From cae261e163111c209e7ba2821a85d95e6bc14795 Mon Sep 17 00:00:00 2001 From: Trasrik Galdifei <40101443+trasrikgaldifei@users.noreply.github.com> Date: Sun, 28 May 2023 17:25:36 +0200 Subject: [PATCH 1/2] Add files via upload --- miflora-mqtt-daemon.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/miflora-mqtt-daemon.py b/miflora-mqtt-daemon.py index 6837d56..973bc5d 100755 --- a/miflora-mqtt-daemon.py +++ b/miflora-mqtt-daemon.py @@ -119,7 +119,7 @@ def on_publish(client, userdata, mid): miflora_cache_timeout = sleep_period - 1 # Check configuration -if reporting_mode not in ['mqtt-json', 'mqtt-homie', 'json', 'mqtt-smarthome', 'homeassistant-mqtt', 'thingsboard-json', 'wirenboard-mqtt']: +if reporting_mode not in ['mqtt-json', 'mqtt-pure', 'mqtt-homie', 'json', 'mqtt-smarthome', 'homeassistant-mqtt', 'thingsboard-json', 'wirenboard-mqtt']: print_line('Configuration parameter reporting_mode set to an invalid value', error=True, sd_notify=True) sys.exit(1) if not config['Sensors']: @@ -132,7 +132,7 @@ def on_publish(client, userdata, mid): print_line('Configuration accepted', console=False, sd_notify=True) # MQTT connection -if reporting_mode in ['mqtt-json', 'mqtt-smarthome', 'homeassistant-mqtt', 'thingsboard-json', 'wirenboard-mqtt']: +if reporting_mode in ['mqtt-json', 'mqtt-pure', 'mqtt-smarthome', 'homeassistant-mqtt', 'thingsboard-json', 'wirenboard-mqtt']: print_line('Connecting to MQTT broker ...') mqtt_client = mqtt.Client() mqtt_client.on_connect = on_connect @@ -231,6 +231,7 @@ def on_publish(client, userdata, mid): mqtt_client.publish('{}/$announce'.format(base_topic), json.dumps(flores_info), retain=True) sleep(0.5) # some slack for the publish roundtrip and callback function print() + elif reporting_mode == 'mqtt-homie': mqtt_client = OrderedDict() print_line('Announcing Mi Flora devices to MQTT broker for auto-discovery ...') @@ -429,6 +430,11 @@ def on_publish(client, userdata, mid): print_line('Publishing to MQTT topic "{}/{}"'.format(base_topic, flora_name)) mqtt_client.publish('{}/{}'.format(base_topic, flora_name), json.dumps(data)) sleep(0.5) # some slack for the publish roundtrip and callback function + elif reporting_mode == 'mqtt-pure': + print_line('Publishing data to MQTT base topic "{}/{}"'.format(base_topic, flora_name.lower())) + for [param, value] in data.items(): + mqtt_client.publish('{}/{}/{}'.format(base_topic, flora_name.lower(), param), value, 1, True) + sleep(0.5) # some slack for the publish roundtrip and callback function elif reporting_mode == 'thingsboard-json': print_line('Publishing to MQTT topic "{}" username "{}"'.format(base_topic, flora_name)) mqtt_client.username_pw_set(flora_name) From dbfa5e1d2df9b81476def7d03ca41e79954a0f54 Mon Sep 17 00:00:00 2001 From: Trasrik Galdifei <40101443+trasrikgaldifei@users.noreply.github.com> Date: Sun, 28 May 2023 17:30:52 +0200 Subject: [PATCH 2/2] Update config.ini.dist --- config.ini.dist | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/config.ini.dist b/config.ini.dist index b26e255..63ff7f6 100644 --- a/config.ini.dist +++ b/config.ini.dist @@ -11,6 +11,7 @@ # Currently supported: # # mqtt-json - Publish to an MQTT broker in a proprietary json format (Default) +# mqtt-pure - Nothin fancy, just the bare information # mqtt-homie - Publish to an MQTT broker following the Homie MQTT convention # (https://github.com/marvinroger/homie) # mqtt-smarthome - Publish to an MQTT broker following the mqtt-smarthome proposal @@ -53,7 +54,7 @@ # The MQTT base topic to publish all Mi Flora sensor data topics under. # Default depends on the configured reporting_method -#base_topic = miflora # Default for: mqtt-json, mqtt-smarthome, homeassistant-mqtt +#base_topic = miflora # Default for: mqtt-json, mqtt-pure, mqtt-smarthome, homeassistant-mqtt #base_topic = homie # Default for: mqtt-homie #base_topic = gladys/master/device # Default for: gladys-mqtt #base_topic = v1/devices/me/telemetry # Default for: thingsboard-json