jacoscar
(Jacopo)
April 27, 2021, 8:00am
1
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}})
Troon
(Troon)
April 27, 2021, 8:18am
2
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
laca75tn
(My Home)
March 8, 2022, 3:40pm
4
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'