There is no error in the automatic check and the execution is normal, but the log reports an error

I have a sonoff rf bridge. I use it to receive signals from the 433 remote control. There is no error in the written automatic check. It is normal to use, but the error will be reported in the homeassistant’s log. I do n’t know what the reason is, and everyone can help me? Home Assistant 0.103.4

sensor:
  - platform: mqtt
    name: "sonoff_rf_bridge_received"
    state_topic: "sonoff_rf_bridge/tele/RESULT"
    expire_after: 10
    value_template: "{{ value_json.RfReceived.Data }}"
automation:
  - alias: sonoff_rf_bridge_receive_bedroom
    hide_entity: true
    trigger:
    - platform: state
      entity_id: sensor.sonoff_rf_bridge_received
    condition: []
    action:
      service_template: >
        {% if (trigger.to_state.state == "20610F") or (trigger.to_state.state == "20610B") or (trigger.to_state.state == "20610D") or (trigger.to_state.state == "20610E") %}
          light.turn_on
        {% elif (trigger.to_state.state == "206107") or (trigger.to_state.state == "206103") or (trigger.to_state.state == "206105") or (trigger.to_state.state == "206106") %}
          light.turn_off
        {% elif trigger.to_state.state == "206104" %}
          script.trun_on_bedroom_all_light
        {% elif trigger.to_state.state == "206108" %}
          script.trun_off_bedroom_all_light
        {% endif %}
      data_template:
        entity_id: >
          {% if (trigger.to_state.state == "20610F") or (trigger.to_state.state == "206107") %}
            light.livingroom_headlights
          {% elif (trigger.to_state.state == "20610B") or (trigger.to_state.state == "206103") %}
            light.restaurant_headlights
          {% elif (trigger.to_state.state == "20610D") or (trigger.to_state.state == "206105") %}
            light.kitchen_lights
          {% elif (trigger.to_state.state == "20610E") or (trigger.to_state.state == "206106") %}
            light.bedroom_lights
          {% endif %}
2019-12-26 19:21:19 ERROR (MainThread) [homeassistant.components.automation] Error while executing automation automation.yao_kong_kai_guan_kong_zhi_deng_guang. Invalid data for call_service at pos 1: not a valid value for dictionary value @ data['entity_id']

2019-12-26 19:21:20 ERROR (MainThread) [homeassistant.components.automation] Error while executing automation automation.yao_kong_kai_guan_kong_zhi_deng_guang. Invalid data for call_service at pos 1: not a valid value for dictionary value @ data['entity_id']

2019-12-26 19:21:21 ERROR (MainThread) [homeassistant.components.automation] Error while executing automation automation.yao_kong_kai_guan_kong_zhi_deng_guang. Invalid data for call_service at pos 1: not a valid value for dictionary value @ data['entity_id']

2019-12-26 19:21:21 ERROR (MainThread) [homeassistant.components.automation] Error while executing automation automation.yao_kong_kai_guan_kong_zhi_deng_guang. Invalid data for call_service at pos 1: not a valid value for dictionary value @ data['entity_id']

2019-12-26 19:21:32 ERROR (MainThread) [homeassistant.components.automation] Error while executing automation automation.yao_kong_kai_guan_kong_zhi_deng_guang. Invalid data for call_service at pos 1: not a valid value for dictionary value @ data['entity_id']

You have different variables dictating your service templates and your data templates. You also don’t have any ‘else’ clause. Therefore, very regularly by the looks, your service template will resolve to something, but your data template will not, leaving you with something like

service: script.trun_off_bedroom_all_light
data:
  entity_id:

Which is invalid. (not to mention the spelling mistake in the word turn).

Thank you, but how do I write different RF 433 codes to execute different devices, scenarios, or scripts?

You need to look at how the output will be when your template resolves. So in your case you want to switch on a light or a script depending on the code. This is fine, but you cannot leave any blanks like my example above.

I would use the homeassistant.turn_on and homeassistant.turn_off services in your service template, and then in your data template resolve the entity_id to either the light or the script as appropriate, carefully working through all the potential outcomes of each template and making sure that it always resolves to the right thing.

If I get a bit of time later and you’re still struggling I can probably go through your original code and fix it for you, but I’m a bit stretched for time right now :slightly_smiling_face:

I don’t have an rf bridge but believe this post has helped many people:

Thank you for your answer. If there is a remote control that can remotely control various devices, scenes and scripts in homeassistant, I hope it can be realized in an automated configuration. The physical remote control is really very useful.

Thank you, but I don’t feel like this is what I want

I’m not sure you understand it. It solves your problem with the unresolved template and it is far more efficient than the method you are currently using.

If you have ten sensors, then every payload published by the RF Bridge will be evaluated by all ten sensors. In other words, each payload is processed ten times.

However with the demultiplexer method:

Unlike the previous strategy where, for ten sensors, each payload is processed ten times, this strategy processes each payload only twice. The payload is initially processed by the automation and then by the sensor.

Why is this not what you want?

Which you can still do with the solution provided. Even better it will ignore your unknown payloads.

I have a couple of Sonoff RF Bridges that I use in my home (more than one to ensure reliable coverage.) I built a couple of Node Red flows that subscribe to each of the MQTT topics, and deduplicate the messages. It also parses out the transmitted code from the message published by the Tasmota software and the re-publishes a message (with an “ON” string as the payload) to a unique topic per “RF Code”.

Then I can create, e.g., binary sensors like this:

binary_sensor:
  - state_topic: 19916/rfcode/E92FD1
    name: fob_e92fd1
    platform: mqtt
    off_delay: 2
    device_class: vibration

This create a binary sensor for, e.g., a PIR that only sends a code when motion is detected. Or, in this case, a button being pressed on a wireless keyfob.

The binary_sensor changes state to “on” for 2 seconds, and then back off again. I do this rather than just having an automation with an MQTT trigger because I like to have the state recorded so I can see how often the sensor fires.

I use a different approach for other door/window sensors that send a unique code for “Opening” and “Closing” events.

It’s probably overkill to install and run Node Red just for this one function, but I already had it around and it was an easy way to solve the deduplication problem from having more than one RF Bridge that might receive and report a transmitted code.