First of all, this works fine when using a hacked Sonoff (tasmota) switch. Attaching the temp sensor (DHT21) and configuring MQTT the temp works perfectly. So I know my MQTT setup is correct. The issue seems to be syntax in the MQTT message. I've attached the Domoticz log with maximum debugging and you can see two messages. The second is the invalid message from my Python script. The first is the valid message (with an empty temperature) from the Sonoff.
Right off the bat I see three things:
1. The invalid message has a space between the colon and the parameter.
2. The invalid message has the items in a different order.
3. The invalid message does not put the temp reading in quotes.
This is a two part question. The first part is - what is causing Domoticz not to like this MQTT message? For the second part I'm going to post the section of my Python script that generates this message. I'm using the paho_mqtt library to generate the message.
The second part of my question is how do I change the way my message is constructed to make Domoticz happy?
Here is the Python
Code: Select all
temp_data = {'idx':deviceIDX, 'nvalue':0, 'svalue':round(temperature, decim_digits)}
client.publish(topic, json.dumps(temp_data))
Thanks!