ERROR (MainThread) [homeassistant.helpers.template] Error parsing value: 'value_json' is undefined (value: 529CB4off, template: {{value_json.RfReceived.Data}})

I have a Sonoff RF bridge that I use to capture some RF signals to trigger automations.

example configuration

binary_sensor:
  - platform: mqtt
    state_topic: "tele/RF_Bridge/RESULT"
    name: 'Button1'
    value_template: '{{value_json.RfReceived.Data}}'
    payload_on: '529CB2'
    payload_off: '529CB2off'
    device_class: motion
    #optimistic: false
    qos: 1
    #retain: false

example automation to reset the state of the button

- id: '156787833428'
  alias: Reset Button1
  trigger:
  - entity_id: binary_sensor.button1
    from: 'off'
    platform: state
    to: 'on'
    for: 0:00:01
  action:
  - data:
      payload: 529CB2off
      topic: tele/RF_Bridge/RESULT
    service: mqtt.publish
  initial_state: 'on'
  mode: single

The automation works fine (the state of the sensor gets reset to “motion not detected”), but I always get this error in the log (multiple times per press)

ERROR (MainThread) [homeassistant.helpers.template] Error parsing value: ‘value_json’ is undefined (value: 529CB4off, template: {{value_json.RfReceived.Data}})

The automation is not publishing what the binary sensor is expecting. The way you’ve written the sensor suggests you’d be getting messages in this format:

tele/RF_Bridge/RESULT: {"RfReceived": {"Data": "529CB2"}}

to indicate that it is turned on, but your automation is sending:

tele/RF_Bridge/RESULT: "529CB2off"

which isn’t JSON and thus your call to value_json in the sensor is wrong. Try changing the automation to include:

payload: "{\"RfReceived\": {\"Data\": \"529CB2off\"}}"
1 Like

Thanks, that works

1 Like

Would you please be so kind to check my syntax?

I am getting the following error when calling the script below the error.

Logger: homeassistant.helpers.template
Source: helpers/template.py:575
First occurred: 10:26:31 AM
Last logged: 10:26:34 AM

  • Error parsing value: ‘str object’ has no attribute ‘RfReceived’ (value: “{“RfReceived”: {“Data”: “671CCBoff”}}”, template: {{value_json.RfReceived.Data}})
##############################################################
reset_mqtt_binary_sensor:
  description: 'Resets mqtt binary sensor '
  fields:
    code:
      description: 'Code to publish'
      example: 'XXXXXXoff'
  sequence:
    - service: mqtt.publish
      data:
        topic: Home/RF_Bridge/RESULT
        payload: >-
          "{\"RfReceived\": {\"Data\": \"{{ code }}\"}}"


##############################################################
reset_all_mqtt_binary_sensors_with_one_code:
  description: 'Resets all mqtt binary sensors that only have one code'
  sequence:

 
    - service: script.reset_188_mqtt_binary_sensor
      data:
        code: 'D95999off'
    
    - service: script.reset_188_mqtt_binary_sensor
      data:
        code: '4E7511off'
    
    - service: script.reset_188_mqtt_binary_sensor
      data:
        code: '901321off'