ThomDietrich / miflora-mqtt-daemon

Linux service to collect and transfer Xiaomi Mi Flora plant sensor data via MQTT to your smart home system, with cluster support 🌱🌼🥀🏡🌳
MIT License
610 stars 140 forks source link

Integration with HomeAssistant on different RaspberryPi raises wildcard issue #64

Open SpuriousGer opened 5 years ago

SpuriousGer commented 5 years ago

Hi everyone,

I receive the following issue after running the initial execution:

 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 305, in <module>
    mqtt_client.publish('{}/{}_{}/config'.format(topic_path, flora_name, sensor).lower(), json.dumps(payload), 1, 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.

The MQTT connection is successfully established. I used mainly the standard configuration with the exception of the hostname which I set to the correct IP of my MQTT broker instance which is using the hass.io add-on for the MQTT broker. My hope was to use the auto-discovery to integrate seamlessly.

I haven't found anything by googling, so I am not sure if this is a very unique issue or just my incompetence.

SpuriousGer commented 5 years ago

I didn't remove the spaces at the end, apologies. That's what caused the error.

ThomDietrich commented 5 years ago

We could handle this issue in code. The relevant variables need to be rstrip()'ed.

SpuriousGer commented 5 years ago

To give more feedback/background on this: I had the line for homeassistant uncommented and then it looked like this: base_topic = homeassistant # Default for: homeassistant-mqtt

Which then caused the wildcard error. I don't know if this is due to the fact that I had the # at the end or if it was due to the extra spaces. My initial assumption was due to the extra spaces, as # should be interpreted as comments.