I have an ESP8266-01 with two DS18b20 temperature sensors. The ESP publishes the temperatures every few minutes with the topic: “temperature01/temperature”, and a payload of ‘{“ds1”:{“Temperature”:77.00}}’ or ‘{“ds0”:{“Temperature”:63.00}}’.
My sensors.yaml file is below:
- platform: mqtt
name: "Temp In"
state_topic: "temperature01/temperature"
value_template: "{{ value_json['ds0'].Temperature }}"
force_update: true
unit_of_measurement: "°F"
- platform: mqtt
name: "Temp Out"
state_topic: "temperature01/temperature"
value_template: "{{ value_json['ds1'].Temperature }}"
force_update: true
unit_of_measurement: "°F"
This works fine and I see the inside and outside temeratures on Home Assistant.
But, I am getting errors logged:
Error parsing value: 'dict object' has no attribute 'ds0' (value: {"ds1":{"Temperature":80.00}}, template: {{ value_json['ds0'].Temperature }})
Error parsing value: 'dict object' has no attribute 'ds1' (value: {"ds0":{"Temperature":63.00}}, template: {{ value_json['ds1'].Temperature }})
I suspect the errors are because the template for ds0 doesn’t know what to do with the data from ds1. (For the record, this is my first template).
While the errors don’t interfere with Home Assistant, I would like to fix this for two reasons. 1) To learn how to better handle data from a sensor with two values, and 2) to reduce the write cycles on my SD card in the Raspberry Pi.
So, I am looking for tips on fixing either my templates or the data format sent by the ESP (or both).
Thanks