ESP MQTT Temp + Motion Sensor

Hopefully this is really simple for someone, but my searching isnt bringing up the answer and after a few days of testing different ‘solutions’ none seems to have worked for me.

I am followins Dr Zzzs guide for a Tasmota/Sonoff. I am using a NodeMCU and can setup the Temp sensor which works fine, but when I setup the PIR sensor that works, but it then stops the Temp sensor working.

I have narrowed this down to the Value_Template.

Without the PIR sensor the output direct from the Tasmota get:

00:00:14 MQT: tele/hallway/SENSOR = {"Time":"1970-01-01T00:00:14","DHT11":{"Temperature":23.6,"Humidity":67.0},"TempUnit":"C"}

but with the PIR switch I get:

00:15:14 RSL: tele/hallway/SENSOR = {"Time":"1970-01-01T00:15:14","Switch2":"OFF","DHT11":{"Temperature":23.6,"Humidity":67.0},"TempUnit":"C"}

My Value_Template is:

value_template: "{{ value_json.DHT11.Temperature }}"

I assume I need to point it to the now moved Temp reading as this has shifted possition, but cant seem to figure it out.

Any help would be appriciated.

Both outputs should return the same value with your value_template.
You can test this in Developer Tools/Templates.

Without PIR

{% set SENSOR = {"Time":"1970-01-01T00:00:14","DHT11":{"Temperature":23.6,"Humidity":67.0},"TempUnit":"C"} %}
{{ SENSOR.DHT11.Temperature }}

Returns: 23.6

With PIR

{% set SENSOR = {"Time":"1970-01-01T00:15:14","Switch2":"OFF","DHT11":{"Temperature":23.6,"Humidity":67.0},"TempUnit":"C"} %}
{{ SENSOR.DHT11.Temperature }}

Also returns: 23.6

What do you mean with “but it then stops the Temp sensor working”?

HI VDRainer, Thanks for the reply.

I have was not aware of this feature and have been using HA for nearly a year now, so thanks for point it out to me. I will run some tests using this tool and see if I can find out what the cause is.

Just to clarify what I meant, I can have the Temp sensor working, or I can have the PIR working separately, but when I have both configured on the Tasmota software, the PIR works but the Temp doesn’t read or display in HA at all. I can see the temp is being sent out in the console of the Tasmota. I will reply back with any advancement I get.

Once again, thanks.

For anyone googling this as an issue they have - turns out it was my Max packet size in the PubSubClient!! I know this is meant to be changed, but due to using another PC to flash the NodeMCU it was missed. Its been driving me crazy!
Cheers for the replies VDRainer.

1 Like

I think this emphasises the importance of having a client display the data being sent by the broker, rather than relying solely on the tasmota log files.

Hi gpbenton, do you recommend a program for this?

I use mosquitto_sub. If you prefer gui based programs, MQTT.FX is very popular.

Thanks - I will give both a try, always good to learn these things!