Hello,
I have been using homeassistant for many years and haven’t upgraded my installation for quite a while. I am still using the MQTT definitions in the configuration file. I recently reset an outdoor switch unit on accident and rather than re-programming it I have found the MQTT data from the monitor and have utilized that to restate my switch in the config file. The switch can be tuned on and off, but the switch status doesn’t updated.
The problem that I am having is figuring out how to get the status from the status message properly. It has a very old version of Espurna on it and the status message is:
{“button/0”:“2”,“relay/0”:“0”,“time”:“2023-05-22 21:09:57”,“host”:“ESPURNA_054547”,“ip”:“192.168.1.248”}
I am trying to get the relay status with the following MQTT config, this is under a “Switch” heading as if have many switches defined.
- platform: mqtt
name: “Outdoor_2”
state_topic: “ESPURNA_054547/data”
value_template: “{{value_json.relay\/0}}”
command_topic: “ESPURNA_054547/relay/0/set”
qos: 1
payload_on: “1”
payload_off: “0”
state_on: “1”
state_off: “0”
optimistic: false
It seems that home assistant isn’t picking up the /0 as part of the variable it is looking for in the message even though is shows it as the string it is looking for. Below is the error message that I get when it evaluates the status message.
- Error parsing value: ‘dict object’ has no attribute ‘relay’ (value: {“button/0”:“2”,“relay/0”:“0”,“time”:“2023-05-22 21:09:57”,“host”:“ESPURNA_054547”,“ip”:“192.168.1.248”}, template: {{value_json.relay/0}})
How do I format the Json statement so it looks for the proper “relay/0” variable. I finally figured out that the preceeding “\” was required but the system is still only looking for “relay” instead of “relay/0”
Any help would be greatly appreciated.
TM Harris