question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Improve/fix Home Assistant MQTT integration

See original GitHub issue

Could you please make small addition in your code so Home Assistant (HA) integration via internal HA MQTT Mosquitto broker works properly? The current version of miflora-mqtt-daemon allows only partial integration because of missing information in MQTT data which is sent by miflora-mqtt-daemon resulting in partial plant sensor visibility and HA GUI warnings like “This entity does not have a unique ID, therefore its settings cannot be managed from the UI”…

Goals: The main goal of this request is to have each Miflora Plant sensor visible under Mosquitto broker as a separate HA Device with its Entities/Sensors (temperature, moisture, conductivity, light intensity, battery). Result: ha-miflora02

Another goal is to be able to place miflora sensor into HA “Areas”. This requires the main goal to be implemented (miflora sensor needs to be visible as Device in HA not as separate entities/sensors). Result: ha-miflora01

Explanation: According to HA MQTT Sensor Discovery (https://www.home-assistant.io/integrations/sensor.mqtt/) miflora-mqtt-daemon should also send sensor’s “unique_id” along with it’s “parent device” information (identifiers, connections, firmware, … ) configuration variables. After that, the discovered MQTT sensor is added automatically into HA Device Registry (https://developers.home-assistant.io/docs/device_registry_index/) and visible in HA GUI.

Tested patch which needs to be merged:

diff --git a/miflora-mqtt-daemon.py b/miflora-mqtt-daemon.py
index 1209779..096c5d3 100755
--- a/miflora-mqtt-daemon.py
+++ b/miflora-mqtt-daemon.py
@@ -307,6 +307,15 @@ elif reporting_mode == 'homeassistant-mqtt':
             payload['name'] = "{} {}".format(flora_name, sensor.title())
             if 'device_class' in params:
                 payload['device_class'] = params['device_class']
+            payload['unique_id'] = "%s-%s" % ( flora['mac'].lower().replace(":", ""), sensor, )
+            payload['device'] = {
+                    'identifiers': [ "MiFlora{}".format( flora['mac'].lower().replace(":", "") )],
+                    'connections': [[ "mac", flora['mac'].lower() ]],
+                    'manufacturer': 'Xiaomi',
+                    'name': flora_name,
+                    'model': 'HHCCJCY01',
+                    'sw_version': flora['firmware']
+                    }
             mqtt_client.publish('{}/{}_{}/config'.format(topic_path, flora_name, sensor).lower(), json.dumps(payload), 1, True)
 elif reporting_mode == 'wirenboard-mqtt':
     print_line('Announcing Mi Flora devices to MQTT broker for auto-discovery ...')

Thank you!

PS: In case no new Miflora devices are visible in your HA after patching miflora-mqtt-daemon, try restarting HA.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:10 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
ThomDietrichcommented, Mar 30, 2020

Will HA generate sensor names correctly?

I believe so. Check this out: https://github.com/home-assistant/core/issues/10220

The name field from your PR is used as the entity_id. Why HA installation works with the latest version of this daemon

In feature we can add there

Believe it or not, that is why even though I removed “/state” initially, I left “/sensor/” in. For #35 I envision “miflora/config/…”

1reaction
bangomcommented, Mar 23, 2020

Great, should I create git pull request or attached patch is enough?

I’m running miflora-mqtt-daemon on multiple separate raspberrypi-zero devices which work as btle gateways for nearby miflora sensors. Hass.io is on a separate central device.

I’m also thinking to enhance miflora-mqtt-daemon with passive btle readings by default (each miflora broadcasts everything except battery status multiple times per minute) which will save miflora batteries in long-term use. Active btle pooling only few times per day for battery status. Passive btle Miflora reading, see ESPhome or HA component sensor.mitemp_bt. Miflora-mqtt-daemon would be first to combine passive and active (battery status) reading.

po 23. 3. 2020 v 15:38 odesílatel Thomas Dietrich notifications@github.com napsal:

Hey @bangom https://github.com/bangom, thanks for this. I’ll patch this in the next 1-3 days. Out of personal interest: Where does your miflora-mqtt-daemon run, on a normal Linux machine or inside docker on a raspberry pi with Hass.io?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/ThomDietrich/miflora-mqtt-daemon/issues/101#issuecomment-602635428, or unsubscribe https://github.com/notifications/unsubscribe-auth/AKBL3AEL4EGOP3BBEFIC7RDRI5X4ZANCNFSM4LRODVTQ .

– Moris Bangoura

Read more comments on GitHub >

github_iconTop Results From Across the Web

MQTT - Home Assistant
Instructions on how to setup MQTT within Home Assistant. ... To use the public mosquitto broker, configure the MQTT integration to connect to...
Read more >
MQTT - Home Assistant
It allows extremely lightweight publish/subscribe messaging transport. To integrate MQTT into Home Assistant, you need to setup the MQTT integration.
Read more >
MQTT Integration - Configuration - Home Assistant Community
In the Integrations panel in Configuration, it is showing my MQTT: image and if I click on it it says: 'This Integration has...
Read more >
MQTT Sensor - Home Assistant
Instructions on how to integrate MQTT sensors within Home Assistant. ... This mqtt sensor platform uses the MQTT message payload as the sensor...
Read more >
MQTT - devices can be included in "integration" - Configuration
If you look at the Home Assistant MQTT Docs regarding configuration (for example mqtt cover), you'll see a section about device . It...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found