These appear to be working correctly, however the logs are consistently filled with the following errors:
Template variable error: 'value_json' is undefined when rendering '{{value_json.RfReceived.Data}}' Error parsing value: 'value_json' is undefined (value: E63B42off, template: {{value_json.RfReceived.Data}})
I’m pretty sure this was copied from another post somewhere in the forum and it didn’t generate an eror when I created them Can someone explain what I might be doing wrong here?
Another copy-paste problem. I don’t know where this code originated, but it’s never going to work in the form you’ve posted it — the binary_sensor is expecting to receive structured JSON but your automation is sending it a simple string. Solution in my post in this topic:
I changed the code to reflect your suggestions but it made no difference. I even commented out the references to the element that shows up in the log in both automations.yaml and binary_sensors.yaml, but the error still appears in the log.
Error parsing value: 'value_json' is undefined (value: E63B42off, template: {{value_json.RfReceived.Data}})
11:39:45 – (ERROR) helpers/template.py - message first occurred at 11:39:10 and shows up 90 times
Template variable error: 'value_json' is undefined when rendering '{{value_json.RfReceived.Data}}'
11:39:45 – (ERROR) helpers/template.py - message first occurred at 11:39:10 and shows up 90 times
Is there somewhere else that I should be looking, because it appears the errors are not being generated by statements in either of those files?
You need to restart HA for the changes to take effect. The error message is quite clear: your sensor template is expecting a different structure to what your automation is feeding it.
I restart it after every change I make. I’ve even hard rebooted the NUC to be absolutely sure.
Any reference to E63B42off is commented out in automations.yaml and binary_sensors.yaml, and yet the error still appears. Are these the only two places the template could be in?
Well, if you’ve restarted and haven’t (to your knowledge) used the templates anywhere else, the error should not be occurring still; and your code looks good to run as expected if uncommented. Are you sure these aren’t old errors?
2021-06-03 12:32:09 ERROR (MainThread) [homeassistant.helpers.template] Error parsing value: 'value_json' is undefined (value: E63B42off, template: {{value_json.RfReceived.Data}})
2021-06-03 12:32:09 INFO (MainThread) [homeassistant.components.mqtt.binary_sensor] No matching payload found for entity: Landing Motion with state topic: tele/sonoff/RESULT. Payload: 'E63B42off', template output: 'E63B42off', with value template 'Template("{{value_json.RfReceived.Data}}")'
2021-06-03 12:32:09 ERROR (MainThread) [homeassistant.helpers.template] Template variable error: 'value_json' is undefined when rendering '{{value_json.RfReceived.Data}}'
2021-06-03 12:32:09 ERROR (MainThread) [homeassistant.helpers.template] Error parsing value: 'value_json' is undefined (value: E63B42off, template: {{value_json.RfReceived.Data}})
2021-06-03 12:32:09 INFO (MainThread) [homeassistant.components.mqtt.binary_sensor] No matching payload found for entity: Anna's Bedroom Motion with state topic: tele/sonoff/RESULT. Payload: 'E63B42off', template output: 'E63B42off', with value template 'Template("{{value_json.RfReceived.Data}}")'
2021-06-03 12:32:09 ERROR (MainThread) [homeassistant.helpers.template] Template variable error: 'value_json' is undefined when rendering '{{value_json.RfReceived.Data}}'
2021-06-03 12:32:09 ERROR (MainThread) [homeassistant.helpers.template] Error parsing value: 'value_json' is undefined (value: E63B42off, template: {{value_json.RfReceived.Data}})
2021-06-03 12:32:09 INFO (MainThread) [homeassistant.components.mqtt.binary_sensor] No matching payload found for entity: Xander's Bedroom Motion with state topic: tele/sonoff/RESULT. Payload: 'E63B42off', template output: 'E63B42off', with value template 'Template("{{value_json.RfReceived.Data}}")'
2021-06-03 12:32:09 ERROR (MainThread) [homeassistant.helpers.template] Template variable error: 'value_json' is undefined when rendering '{{value_json.RfReceived.Data}}'
2021-06-03 12:32:09 ERROR (MainThread) [homeassistant.helpers.template] Error parsing value: 'value_json' is undefined (value: E63B42off, template: {{value_json.RfReceived.Data}})
2021-06-03 12:32:09 INFO (MainThread) [homeassistant.components.mqtt.binary_sensor] No matching payload found for entity: Office Motion with state topic: tele/sonoff/RESULT. Payload: 'E63B42off', template output: 'E63B42off', with value template 'Template("{{value_json.RfReceived.Data}}")'
2021-06-03 12:32:09 ERROR (MainThread) [homeassistant.helpers.template] Template variable error: 'value_json' is undefined when rendering '{{value_json.RfReceived.Data}}'
2021-06-03 12:32:09 ERROR (MainThread) [homeassistant.helpers.template] Error parsing value: 'value_json' is undefined (value: E63B42off, template: {{value_json.RfReceived.Data}})
2021-06-03 12:32:09 INFO (MainThread) [homeassistant.components.mqtt.binary_sensor] No matching payload found for entity: Kitchen Motion with state topic: tele/sonoff/RESULT. Payload: 'E63B42off', template output: 'E63B42off', with value template 'Template("{{value_json.RfReceived.Data}}")'
2021-06-03 12:32:09 ERROR (MainThread) [homeassistant.helpers.template] Template variable error: 'value_json' is undefined when rendering '{{value_json.RfReceived.Data}}'
2021-06-03 12:32:09 ERROR (MainThread) [homeassistant.helpers.template] Error parsing value: 'value_json' is undefined (value: E63B42off, template: {{value_json.RfReceived.Data}})
2021-06-03 12:32:09 INFO (MainThread) [homeassistant.components.mqtt.binary_sensor] No matching payload found for entity: Patio Door with state topic: tele/sonoff/RESULT. Payload: 'E63B42off', template output: 'E63B42off', with value template 'Template("{{value_json.RfReceived.Data}}")'
2021-06-03 12:32:09 ERROR (MainThread) [homeassistant.helpers.template] Template variable error: 'value_json' is undefined when rendering '{{value_json.RfReceived.Data}}'
2021-06-03 12:32:09 ERROR (MainThread) [homeassistant.helpers.template] Error parsing value: 'value_json' is undefined (value: E63B42off, template: {{value_json.RfReceived.Data}})
2021-06-03 12:32:09 INFO (MainThread) [homeassistant.components.mqtt.binary_sensor] No matching payload found for entity: Front Door with state topic: tele/sonoff/RESULT. Payload: 'E63B42off', template output: 'E63B42off', with value template 'Template("{{value_json.RfReceived.Data}}")'
2021-06-03 12:32:09 ERROR (MainThread) [homeassistant.helpers.template] Template variable error: 'value_json' is undefined when rendering '{{value_json.RfReceived.Data}}'
2021-06-03 12:32:09 ERROR (MainThread) [homeassistant.helpers.template] Error parsing value: 'value_json' is undefined (value: E63B42off, template: {{value_json.RfReceived.Data}})
2021-06-03 12:32:09 INFO (MainThread) [homeassistant.components.mqtt.binary_sensor] No matching payload found for entity: Kitchen Door with state topic: tele/sonoff/RESULT. Payload: 'E63B42off', template output: 'E63B42off', with value template 'Template("{{value_json.RfReceived.Data}}")'
2021-06-03 12:32:09 ERROR (MainThread) [homeassistant.helpers.template] Template variable error: 'value_json' is undefined when rendering '{{value_json.RfReceived.Data}}'
2021-06-03 12:32:09 ERROR (MainThread) [homeassistant.helpers.template] Error parsing value: 'value_json' is undefined (value: E63B42off, template: {{value_json.RfReceived.Data}})
2021-06-03 12:32:09 INFO (MainThread) [homeassistant.components.mqtt.binary_sensor] No matching payload found for entity: Back Door with state topic: tele/sonoff/RESULT. Payload: 'E63B42off', template output: 'E63B42off', with value template 'Template("{{value_json.RfReceived.Data}}")'
This is from the log file just now. 12:32 was about 20 minutes ago.
Now I look at it, why would it be sending the same payload to all those entities…?
I mean the binary_sensors.yaml contains references to lots of sensors which are now all set up the same way as the one I showed above. I have commented out all references to the device using E63B42 and E63B42off in both automations.yaml and binary_sensors.yaml. I did this as a start point to see if I could identify what could fix it so that I can then apply that same fix to the others.
I’m contemplating commenting out every line in both files to see what affect that has.
It’d be good to see what’s actually being sent over MQTT from the sensors. I assume that E63B42 is your doorbell one, and that the other sensors broadcast different IDs — and that you have put those IDs into the config for each as appropriate.
I don’t know why these messages are persisting if you have deleted references to the template. Have a look under Configuration / Entities and see if they are still appearing there despite being commented out.
Another possibility is that the sensor is sending the structured data some of the time, and the plain string at other times. Perhaps try uncommenting one sensor, adjusted like this:
OK, I’m still baffled by this. I took out everything from automations and from bin_sensors and the errors disappeared.
I added 5 sensors back in, none of which even mentioned E63B42, and there were 25 errors in the log all mentioning it. I took three out, leaving just two, and there were then four errors mentioning it. The number of errors seems to be the square of the number of sensors, so something is obviously not right about the way I’ve set this up.
Somewhere there’s a template that specifically refers to E63B42off, but I have no idea where it could be
…and yet this error still appears in the log on startup:
Error parsing value: 'value_json' is undefined (value: E63B42off, template: {% if value_json.RfReceived is defined %} {{ value_json.RfReceived.Data }} {% else %} {{ value_json }} {% endif %})
11:39:07 – (ERROR) helpers/template.py
Template variable error: 'value_json' is undefined when rendering '{% if value_json.RfReceived is defined %} {{ value_json.RfReceived.Data }} {% else %} {{ value_json }} {% endif %}'
11:39:07 – (ERROR) helpers/template.py
It’s like that trigger value is cached somewhere in the system and gets sent out to every sensor. I’ve restarted the Sonoff Bridge and restarted HA with the Bridge turned off. The error still appears, so I know the problem exists within HA somewhere. But where?
There are a lot running. I disabled the MQTT integration then restarted, and the error disappeared. I stopped Mosquitto and restarted, and the error also disappeared. Probably unsurprisingly.
When I started Mosquitto again, the error immediately appeared in the log.
If I listen to tele/sonoff/RESULT in the MQTT settings page, I get the following:
Message 1 received on tele/sonoff/RESULT at 13:04:
E63B42off
QoS: 0 - Retain: true
Is this message being retained somewhere and if so, how do I reset it?
I’ve published a null value to that topic and it temporarily gets set to 0 with retain false, but as soon as I listen again it’s jumped back to the value above with retain true.