diff options
Diffstat (limited to 'scripts/neohub.py')
-rw-r--r-- | scripts/neohub.py | 25 |
1 files changed, 13 insertions, 12 deletions
diff --git a/scripts/neohub.py b/scripts/neohub.py index 4fd3a16..7ef8b77 100644 --- a/scripts/neohub.py +++ b/scripts/neohub.py @@ -2,6 +2,7 @@ ''' Get stuff from neohub! This is mostly the usage-example from https://gitlab.com/neohubapi/neohubapi/ ''' import os +import time import asyncio from datetime import datetime import neohubapi.neohub as neohub @@ -10,8 +11,9 @@ import common neohub_ip = os.environ['el_neohub_ip'] neohub_port = os.environ['el_neohub_port'] +SLEEP = 120 # Sleep between runs -async def run(): +async def call_neohub(): ''' async runner! w00p ''' # Legacy connection hub = neohub.NeoHub(neohub_ip, int(neohub_port)) @@ -20,7 +22,7 @@ async def run(): 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}") + #print(f"Temperature in zone {device.name}: {device}") values = ( datetime.utcnow(), device.time, @@ -44,21 +46,20 @@ async def run(): temperature) VALUES(%s, %s, %s, %s, %s, %s, %s, %s, %s)""" - common.dbi(sql, values) - + common.dbi(sql, values, verbose=True) sql = """INSERT INTO mqtt_temps - (name, + (sensor_id, temperature, - time, - room) - SELECT 'neohub', %s, %s, sensors.room + time) + SELECT sensors.id, %s, %s FROM sensors WHERE sensors.name = 'neohub'""" values = (device.temperature, datetime.utcnow()) - common.dbi(sql, values) - - + common.dbi(sql, values, verbose=True) -asyncio.run(run()) +# Loop it forever +while True: + asyncio.run(call_neohub()) + time.sleep(SLEEP) |