Message malformed: required key not provided @ data ['condition'] [0] ['device_id']

This automation is throwing a Message malformed: required key not provided @ data[‘condition’][0][‘device_id’] error that I cannot figure out

alias: Family Room follow the Sun
description: ""
trigger:
  - platform: state
    entity_id: group.family_room_motion
    from: "off"
    to: "on"
condition:
  - type: is_illuminance
    condition: device
    entity_id: sensor.family_room_mantle_illuminance
    domain: sensor
    below: 50
action:
  - service: light.turn_on
    data:
      transition: 2
      brightness_pct: "{{ states('sensor.light_brightness') }}"
      color_temp: "{{ states('sensor.light_colour_temp') }}"
    target:
      entity_id: light.family_room_right
  - wait_for_trigger:
      - platform: state
        entity_id: group.family_room_motion
        from: "on"
        to: "off"
  - service: light.turn_off
    data:
      transition: 12
    target:
      entity_id:
        - light.family_room_right
mode: restart

You’re using a device condition. You need to supply a device id.

Or better, use a numeric state condition instead, so you only have to supply an entity id.

Thanks @tom_l
To use numeric_state, I had to comment out type and domain in order to save it…
This shouldn’t impact anything should it?

condition:
#   - type: is_illuminance
    - condition: numeric_state
      entity_id: sensor.family_room_mantle_illuminance
#     domain: sensor
      below: 50

It appears that you created this manually and not by using the Automation Editor. If you did use the Automation Editor to create it, you must have edited it because, like tom_l said, this is a Numeric Device Condition and is missing its device option.


Rule of thumb:

Don’t create Device Triggers, Device Conditions, or Device Actions manually. They’re meant to be created using the Automation Editor and then the resulting YAML should be left untouched (i.e. don’t attempt to modify their YAML afterwards).

By “commenting out” those specific lines, you effectively converted the Device Condition into a Numeric State Condition (which is what tom_l suggested). You may as well delete those “commented out” lines because they serve no purpose here.

Got it… Thanks Guys!

You’re welcome but can you confirm the malformed Device Condition was not produced by the Automation Editor but is a result of manual intervention? I just want to confirm it’s not due to a software bug.

Hi @123,
Confirming I manually created the automation which led to the error. There is nothing wrong with the Automation Editor.
Thanks