-
Notifications
You must be signed in to change notification settings - Fork 12
/
aidon_forward.py
46 lines (35 loc) · 1.48 KB
/
aidon_forward.py
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/usr/bin/python
import serial, time, sys, argparse
from hass_influx import *
from aidon_obis import *
parser = argparse.ArgumentParser(description='Forward Aidon data to Home Assistant and InfluxDB')
parser.add_argument('serial_port')
parser.add_argument('--influx_host')
parser.add_argument('--influx_db')
parser.add_argument('--hass_host')
parser.add_argument('--hass_token')
args = parser.parse_args()
# Class used to forward data to Home Assistant and InfluxDB
hi = hass_influx(
inf_host=args.influx_host,
inf_db=args.influx_db,
hass_host=args.hass_host,
hass_token=args.hass_token)
ser = serial.Serial(args.serial_port, 2400, timeout=0.05, parity=serial.PARITY_NONE)
def aidon_callback(fields):
ts = time.time()
if 'p_act_in' in fields:
hi.post("aidon", "power", "%.03f" % (fields['p_act_in']/1000.0), hass_name="Effekt", hass_unit="kW", ts=ts)
if ('il1' in fields) and args.influx_host:
hi.post_influx("voltage", "aidon_p1", "%.01f" % fields['ul1'], ts=ts)
hi.post_influx("voltage", "aidon_p2", "%.01f" % fields['ul2'], ts=ts)
hi.post_influx("voltage", "aidon_p3", "%.01f" % fields['ul3'], ts=ts)
hi.post_influx("current", "aidon_p1", "%.01f" % fields['il1'], ts=ts)
hi.post_influx("current", "aidon_p2", "%.01f" % fields['il2'], ts=ts)
if 'energy_act_in' in fields:
hi.post("aidon", "energy", "%.02f" % fields['energy_act_in'], hass_name="Energi", hass_unit="kWh", ts=ts)
a = aidon(aidon_callback)
while(1):
while ser.inWaiting():
a.decode(ser.read(1))
time.sleep(0.01)