I am really struggling to get MQTT sensors defined correctly. I have read all the documentation (several times) and most of the discussion on the Community.
I’m using Espresense and I can see the states of the device_trackers created by Espresense.
Using MQTT Explorer on a Windows laptop I can inspect the MQTT messages being received by HA
I’ve used an alias to translate the MAC address to an id so I can see the topic as
espresense/devices/car:merc/gate
for example.
The value of the topic is:
{
"mac":"a4cXXXXXXXXX",
"id":"car:merc",
"name":"Car - Merc",
"idType":250,
"rssi@1m":-71,
"rssi":-84,
"raw":3.15,
"distance":2.76,
"int":2188
}
I have 4 Espresense sensors, one of which is gate
, along my driveway and I want to detect the movement of the cars, so I am trying to extract the distance
attribute for a car from each of the sensors.
I tried to create sensors in my configuration.yaml
file as instructed in the manual.
mqtt:
sensor:
- name: 'Car - Merc - Gate'
state_topic: 'espresense/devices/car:merc/gate/infojson'
value_template: "{{ value_json.distance }}"
unit_of_measurement: "m"
state_attributes_topic: 'espresense/devices/car:merc/gate'
payload_available: "online"
payload_not_available: "offline"
I keep on getting the following error after a reboot.
I cannot see what I have done incorrectly. I saw some people using state_attribute_template
but this does seem to be required, and that is not the error message.
I removed the state_attributes_topic
from each of the sensors and they get created correctly, but the value returned is “unknown”.
HELP!!