miflora-mqtt-daemon icon indicating copy to clipboard operation
miflora-mqtt-daemon copied to clipboard

Exception when running miflora-mqtt-daemon.py

Open NicoFilips opened this issue 5 years ago • 6 comments

[21:02:34] root@smarthome:/opt/miflora-mqtt-daemon# python3 /opt/miflora-mqtt-daemon/miflora-mqtt-daemon.py

Xiaomi Mi Flora Plant Sensor MQTT Client/Daemon
Source: https://github.com/ThomDietrich/miflora-mqtt-daemon

[2019-01-15 21:02:47] Connecting to MQTT broker ...
Adding sensor to device list and testing connection ...
Name:          "Flowercare"
Internal name: "Flowercare"
Device name:   "Flower care"
MAC address:   C4:7C:XX:XX:XX:XX
Firmware:      2.7.0
[2019-01-15 21:02:52] Initial connection to Mi Flora sensor "Flowercare" (C4:7C:8D:67:58:3B) successful

[2019-01-15 21:02:52] Announcing Mi Flora devices to MQTT broker for auto-discovery ...
Traceback (most recent call last):
  File "/opt/miflora-mqtt-daemon/miflora-mqtt-daemon.py", line 251, in <module>
    mqtt_client.publish('{}/$announce'.format(base_topic), json.dumps(flores_info), retain=True)
  File "/usr/local/lib/python3.5/dist-packages/paho/mqtt/client.py", line 1057, in publish
    raise ValueError('Publish topic cannot contain wildcards.')
ValueError: Publish topic cannot contain wildcards.

I've commented in base_topic = mqttjson to get it into OpenHAB items. running the script with this line commented out it works perfect, but the OpenHAB items never get updated. Can someone help?

NicoFilips avatar Jan 15 '19 20:01 NicoFilips

Hey there. I believe your issue is related to #64. Please check your config file for trailing spaces.

ThomDietrich avatar Jan 16 '19 08:01 ThomDietrich

Hmm weird, yes I got rid of this exception, very kind, thank you Thomas! But I still encounter no retrieved events or values: image Its even publishing the data: image but my items stay empty: image Items definition is okay, double checked it with the built in:

python3 /opt/miflora-mqtt-daemon/miflora-mqtt-daemon.py --gen-openhab

I've rebooted and restarted/loaded the daemon .. I need a little help here, this can't be so hard, it was running perfectly and has been an very easy setup before my Pi crashed some weeks ago ..

NicoFilips avatar Jan 16 '19 17:01 NicoFilips

Results are published to the MQTT broker but not retrieved by openHAB. Should be simple to debug. My best guess is that with openHAB 2.4 you are now using the new MQTT binding and need to adapt your configuration. The one generated with --gen-openhab is for the old binding and won't help you much. Either install the old binding or modify your configuration. Both should be easy. If you need help, please contact the openHAB community.

I've moved into a new apartment and did not yet implement the needed changes for this daemon. The solution will be #57 - to update the Homie reporting_method and have plants automatically discovered by openHAB 💪

ThomDietrich avatar Jan 16 '19 19:01 ThomDietrich

Maybe that'll help you. I'm using the new MQTT plugin from Openhab 2.4 with the internal broker.

Thing file:

Bridge mqtt:systemBroker:MqttBroker "MQTT Broker" [ brokerid="embedded-mqtt-broker" ]
{
    Thing topic FicusBenjamin "Ficus Benjamin"
    {
        Channels:
            Type number : light         "Lichtstärke"           [ stateTopic="miflora/FicusBenjamin", transformationPattern="JSONPATH:$.light" ]
            Type number : battery       "Batterieladung"        [ stateTopic="miflora/FicusBenjamin", transformationPattern="JSONPATH:$.battery" ]
            Type number : temperature   "Lufttemperatur"        [ stateTopic="miflora/FicusBenjamin", transformationPattern="JSONPATH:$.temperature" ]
            Type number : conductivity  "Bodenfruchtbarkeit"    [ stateTopic="miflora/FicusBenjamin", transformationPattern="JSONPATH:$.conductivity" ]
            Type number : moisture      "Bodenfeuchtigkeit"     [ stateTopic="miflora/FicusBenjamin", transformationPattern="JSONPATH:$.moisture" ]
    }
}

Item File:

Number:Illuminance      Miflora_Ficus_Light         "Lichtstärke Ficus [%d lx]"             <light>         { channel="mqtt:topic:MqttBroker:FicusBenjamin:light" }
Number:Dimensionless    Miflora_Ficus_Battery       "Batterieladung Ficus [%d %%]"          <battery>       { channel="mqtt:topic:MqttBroker:FicusBenjamin:battery" }
Number:Temperature      Miflora_Ficus_Temperature   "Lufttemperatur Ficus [%.1f °C]"        <temperature>   { channel="mqtt:topic:MqttBroker:FicusBenjamin:temperature" }
Number                  Miflora_Ficus_Conductivity  "Bodenfruchtbarkeit Ficus [%d µS/cm]"   <lawnmower>     { channel="mqtt:topic:MqttBroker:FicusBenjamin:conductivity" }
Number:Dimensionless    Miflora_Ficus_Moisture      "Bodenfeuchtigkeit Ficus [%d %%]"       <humidity>      { channel="mqtt:topic:MqttBroker:FicusBenjamin:moisture" }

Markkuuss avatar Jan 17 '19 10:01 Markkuuss

Thanks @Markkuuss !

Even though this is not the future of what this daemon will encourage, would you like to add your example to the end of the README as a PR? That would for sure be helpful

ThomDietrich avatar Jan 17 '19 10:01 ThomDietrich

@ThomDietrich Oh allright, didn't noticed that the mqtt config changed! Thanks for helping. Would be a good thing to update the Readme file expecially for other members, who are like me, not unbelievable familiar with the mqtt configuration :) besides that, great repo! @Markkuuss Thank you ! I will try it when I'm at home. Really helped me out :)

NicoFilips avatar Jan 17 '19 10:01 NicoFilips