diff options
author | Dennis Eriksen <d@ennis.no> | 2023-02-01 20:32:11 +0100 |
---|---|---|
committer | Dennis Eriksen <d@ennis.no> | 2023-02-01 20:32:11 +0100 |
commit | 8d186d39483beff64a1c11f80c6ca5e56dd7bbc5 (patch) | |
tree | 2c5a64ace4bd8eabd4d65014c5313bd7edd76191 /scripts/neohub.py | |
parent | run queue in batches (diff) | |
download | energyscripts-8d186d39483beff64a1c11f80c6ca5e56dd7bbc5.tar.gz |
moving and renaming/breaking everything
Diffstat (limited to 'scripts/neohub.py')
-rw-r--r-- | scripts/neohub.py | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/scripts/neohub.py b/scripts/neohub.py new file mode 100644 index 0000000..5c62606 --- /dev/null +++ b/scripts/neohub.py @@ -0,0 +1,27 @@ +#!/usr/bin/python3 + +import os +import asyncio +from datetime import datetime +import neohubapi.neohub as neohub + +from common import dbi + +neohub_ip = os.environ['el_neohub_ip'] +neohub_port = os.environ['el_neohub_port'] + +async def run(): + # Legacy connection + hub = neohub.NeoHub(neohub_ip, int(neohub_port)) + # Or, for a websocket connection: + # hub = neohub.Neohub(port=4243, token='xxx-xxxxxxx') + system = await hub.get_system() + hub_data, devices = await hub.get_live_data() + for device in devices['thermostats']: + print(f"Temperature in zone {device.name}: {device}") + sql = "INSERT INTO neohub (timestamp, time, device_id, away, heat_mode, heat_on, current_floor_temperature, target_temperature, temperature) VALUES(%s,%s,%s,%s,%s,%s,%s,%s,%s)" + values = (datetime.utcnow(), device.time, device.device_id, device.away, device.heat_mode, device.heat_on, device.current_floor_temperature, device.target_temperature, device.temperature) + dbi(sql, values) + +asyncio.run(run()) + |