aboutsummaryrefslogtreecommitdiffstats
path: root/neohub2pgsql.py
blob: 646fa602750a0516eb2e8b5f67163d1cc7c1ace5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#!/usr/bin/python3

import os
import asyncio
import neohubapi.neohub as neohub

from todb import todb

neohub_ip = os.environ['el_neohub_ip']
neohub_port = os.environ['el_neohub_port']

values = []

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}")
        values.append((device.time, device.device_id, device.away, device.heat_mode, device.heat_on, device.current_floor_temperature, device.target_temperature, device.temperature))

asyncio.run(run())

todb("INSERT INTO neohub (time, device_id, away, heat_mode, heat_on, current_floor_temperature, target_temperature, temperature) VALUES(%s,%s,%s,%s,%s,%s,%s,%s)", values)