diff options
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()) + |