"Required key not provided" (binary_sensor automation created using Lovelace UI)

I’m getting this error when I try to run an automation which I’ve created using the Lovelace UI in HA Core:

Invalid config for [automation]: required key not provided @ data['device_id']. Got None.

The idea is to respond to the “on” payload for my binary sensor by arming my home alarm system. I can’t work out which key I need to enter. The definition is below.
Could anyone advise?
The screenshot seems to be a little small, so here’s what I’ve entered (any field not listed I have left blank):

  • Name: Turn on alarm using Sonoff 433MHz remote
  • Mode: Single
    Trigger:
  • Trigger Type: State
  • Trigger ID: alarm_on
  • Entity: binary_sensor.sonoff_433MHz_remote
  • To: on
    Action:
  • Action type: Call service
  • Service: alarm_control_panel.alarm_arm_away
  • Targets: home_alarm

Don’t post screenshots of an automation, post its YAML text.

Click the overflow menu (three vertical dots) in the upper right hand corner of the Automation Editor and select “Edit in YAML”. Copy-paste the displayed YAML text.

The error message is referring to device_id but the automation you posted doesn’t appear to reference device_id. Are you certain the error message is complaining about this particular automation? The answer to that question might be revealed in the YAML text you post.

Sorry here is the yaml:

alias: Turn on alarm using Sonoff 433MHz remote
description: ''
trigger:
  - platform: state
    entity_id: binary_sensor.sonoff_433mhz_remote
    to: 'on'
condition: []
action:
  - service: alarm_control_panel.alarm_arm_away
    target:
      entity_id: alarm_control_panel.home_alarm
mode: single

I get the error message every time I save the automation (not every time I run it, as I originally thought - sorry to mislead)

Here is the binary sensor definition from configuration.yaml:

binary_sensor:
#Sonoff 433MHz remote button 1 (top left)
  - platform: mqtt
    name: "Sonoff 433MHz Remote"
    state_topic: "tele/rf-bridge/RESULT"
    value_template: '{{value_json.RfReceived.Data}}'
    payload_on: "773B78"
    payload_off: "773B7C"
    qos: 1

When you save an automation (via the Automation Editor) it checks the validity of all of your automations (not just the one you’re editing). As suspected, that automation contains no reference to device_id so the error is elsewhere.

You can also execute Configuration > Server Controls > Check Configuration and it’s likely to report the same error.

Examine the other automations you have and find the ones that refer to device_id. One of them appears to be missing required information.

Oh in that case I have 2 problems:

  1. The automation is not firing when I press the button which triggers “payload_on”
  2. My Server Controls options don’t include a “Check Configuration” option (only Restart or Stop server)
    Apart from removing my automations one at a time, is there any way of working out which one is causing the error?

It will after you enable Advanced Mode.

In the main menu, click your Profile (last icon at the bottom of the list) and enable Advanced Mode.

Screenshot from 2021-09-06 13-05-18

If binary_sensor.sonoff_433mhz_remote changes from off to on but the automation fails to trigger, it implies the error message you saw has prevented Home Assistant from loading automations (i.e. it’s not just this automation that won’t work). You should run Check Configuration and then inspect Configuration > Logs.

That’s brilliant - thanks. I’ve now identified and removed the offending automation, and no longer get that error message. The automation now seems to be firing, but one of the actions is not working correctly (TTS using Google Home) - I’ve opened a separate question for that.

Glad to hear it.

Please consider marking my post above with the Solution tag. It will automatically place a check-mark next to the topic’s title which signals to other users that this topic is resolved. This helps other users find answers to similar questions. For more information, refer to guideline 21 in the FAQ.