diff options
author | Dennis Eriksen <d@ennis.no> | 2023-04-03 16:07:08 +0200 |
---|---|---|
committer | Dennis Eriksen <d@ennis.no> | 2023-04-03 16:07:08 +0200 |
commit | cd5a78bc94e7b338bff5f19f96add3dea4483856 (patch) | |
tree | 89f9f1df94cc375816b06229a8d3918e13ce516b /scripts/mqtt_listener.py | |
parent | Use Friendly name here (diff) | |
download | energyscripts-cd5a78bc94e7b338bff5f19f96add3dea4483856.tar.gz |
send mqtt and neohub to new states-table
Diffstat (limited to 'scripts/mqtt_listener.py')
-rw-r--r-- | scripts/mqtt_listener.py | 32 |
1 files changed, 7 insertions, 25 deletions
diff --git a/scripts/mqtt_listener.py b/scripts/mqtt_listener.py index 6c617a5..48dfc6f 100644 --- a/scripts/mqtt_listener.py +++ b/scripts/mqtt_listener.py @@ -57,33 +57,15 @@ def on_message(client, userdata, msg): data['voltage'], data['linkquality'], datetime.utcnow()) + common.dbi(sql, values, verbose=True) - elif name in tempsensors and 'temperature' in data: - data['humidity'] = data['humidity'] if 'humidity' in data else None - data['voltage'] = data['voltage'] if 'voltage' in data else None - sql = """INSERT INTO mqtt_temps - (sensor_id, - temperature, - humidity, - battery, - linkquality, - voltage, - time) - SELECT sensors.id, %s, %s, %s, %s, %s, %s - FROM sensors - WHERE sensors.name = %s""" - values = (data['temperature'], - data['humidity'], - data['battery'], - data['linkquality'], - data['voltage'], - datetime.utcnow(), - name) - - else: - return + if name in tempsensors: + if 'temperature' in data: + common.statein(name, data['temperature'], 'temperature', '°C', verbose=True) + if 'humidity' in data: + common.statein(name, data['humidity'], 'humidity', '%', verbose=True) + - common.dbi(sql, values, verbose=True) # mqtt |