Rockyca
December 16, 2021, 8:49pm
1
Just trying to get rid of the following two error.s…
Logger: homeassistant.helpers.template
Source: helpers/template.py:574
First occurred: 3:05:09 PM (8 occurrences)
Last logged: 3:38:54 PM
Error parsing value: ‘value_json’ is undefined (value: on, template: {{value_json.state}})
Logger: homeassistant.helpers.template
Source: helpers/template.py:1791
First occurred: 3:05:09 PM (5 occurrences)
Last logged: 3:18:43 PM
Template variable error: ‘value_json’ is undefined when rendering ‘{{value_json.state}}’
I think it has something to do with this block of code which comes from blue iris to notify of AI motion detected on the cameras. I am new to the whole home assistant thing, and coding in general. Any help would be greatly appreciated.
#BlueIris Motion MQTT
#Left Driveway Motion
binary_sensor:
- platform: mqtt
name: "Driveway Left Motion"
device_class: motion
state_topic: "driveway_left_motion"
payload_on: "on"
payload_off: "off"
value_template: "{{value_json.state}}"
off_delay: 30
#Right Driveway Motion
- platform: mqtt
name: "Driveway Right Motion"
device_class: motion
state_topic: "driveway_right_motion"
payload_on: "on"
payload_off: "off"
value_template: "{{value_json.state}}"
off_delay: 30
#Front Door Motion
- platform: mqtt
name: "Front Door Motion"
device_class: motion
state_topic: "front_door_motion"
payload_on: "on"
payload_off: "off"
value_template: "{{value_json.state}}"
off_delay: 30
#Right House Motion
- platform: mqtt
name: "House Right Motion"
device_class: motion
state_topic: "house_right_motion"
payload_on: "on"
payload_off: "off"
value_template: "{{value_json.state}}"
off_delay: 30
TCr82
(Thomas)
December 16, 2021, 8:59pm
2
have your seen this:
maybe also the missing spaces in {{ }} ?
And can you post the value from driveway_right_motion
?
Because it looks like you also miss json_attributes_topic
… or when the topic has no json, just use value
?
tom_l
December 16, 2021, 10:02pm
3
Spacing is nice for legibility but is not required.
This is not required either as only the state is being used.
This would help in diagnosis. Most likely a message is being posted to the driveway topics that does not contain a state
value.
Rockyca
December 17, 2021, 3:28pm
4
where would I find the value? In the states page?
tom_l
December 17, 2021, 9:31pm
5
IMO the easiest way is to subscribe to the topic with MQTT Explorer (free) and come back and look at the message history after a while.
Rockyca
December 18, 2021, 12:09am
6
the value that I have setup and the value that I see on MQTT explorer is “on”
tom_l
December 18, 2021, 12:15am
7
Let it run for a bit. There may be some other message that is sent. You can check the message History section later.
EDIT: Oh. Actually… what is the exact published message? I’m guessing it may not be json.
Is it just:
"on"
Or does it contain:
{"state":"on"}
Rockyca
December 18, 2021, 12:25am
8
what I am receiving from blue iris is just “on” as per the attached
also the payload I am sending from blue iris is just “on”
tom_l
December 18, 2021, 12:42am
9
That ain’t json.
Delete the value template line. You don’t need it. e.g.
#Left Driveway Motion
binary_sensor:
- platform: mqtt
name: "Driveway Left Motion"
device_class: motion
state_topic: "driveway_left_motion"
payload_on: "on"
payload_off: "off"
off_delay: 30
1 Like
Rockyca
December 18, 2021, 12:53am
10
Works!!
what also worked is if I send a payload of : {“state”:“on”} but I like keeping things simple rather than over complicating them.
THanks for your help!
tom_l
December 18, 2021, 1:00am
11
Yep That is because your template was looking for a state in a json formatted message.
This template would also work for your ‘on’ payload:
value_template: "{{ value }}"
Note the lack of value_json
and just value
instead. However it is completely unnecessary.