Device_id property for automations

Hi all

I was receiving errors in the log about my SmartThings token so I generated a new one and re-added via the GUI. Before I did this I got errors in the UI where I’d added ST devices to Lovelace cards (because HA couldn’t communicate with ST).

After re-adding the Lovelace cards are all working again. Going in to Automations (in the GUI) shows all of my automations, clicking into them, all references to ST devices (sensors, lights, switches) are blank. Any references to other integrations are fine.

I tried creating a new automation in the GUI and looking at the YAML this created the device names are all the same. I’ve written all of the automations manually in YAML. After reviewing the code it seems all my automations have a device_id property:

- id: 'auto-motion-bedmain-on'
  alias: Motion - Bedroom Main Light On
  description: ''
  trigger:
  - device_id: 1dfdcf440a8942e78a5e33aea366048a
    domain: binary_sensor
    entity_id: binary_sensor.bedroom_sensor_motion
    platform: device
    type: motion
  condition:
  - before: '20:00'
    condition: time
  - condition: state
    entity_id: input_select.house_mode
    state: Home-Evening
  action:
  - device_id: a48f378c87264a30969f97975145c024
    domain: light
    entity_id: light.bedroom_main_light
    type: turn_on

If I change to:

- id: 'auto-motion-bedmain-on'
  alias: Motion - Bedroom Main Light On
  description: ''
  trigger:
  - entity_id: binary_sensor.bedroom_sensor_motion
    domain: binary_sensor
    platform: device
    type: motion
  condition:
  - before: '20:00'
    condition: time
  - condition: state
    entity_id: input_select.house_mode
    state: Home-Evening
  action:
  - entity_id: light.bedroom_main_light
    domain: light
    type: turn_on

then I get errors in the log:

Invalid config for [automation]: extra keys not allowed @ data['action'][0]['domain']. Got None
extra keys not allowed @ data['action'][0]['type']. Got None
required key not provided @ data['trigger'][0]['device_id']. Got None. (See /config/configuration.yaml, line 48). Please check the docs at https://home-assistant.io/integrations/automation/

I can’t seem to find the “device_id” for any of my devices and to be honest I’d rather use the “entity_id” anyway.

Does anyone have any ideas?

The device_id is automatically generated when you create an automation with the UI, however it is not needed. Remove the lines with “domain:” from your automations.

Thanks!

I’ve removed domain but still getting errors:

- id: 'auto-motion-bedmain-on'
  alias: Motion - Bedroom Main Light On
  description: ''
  trigger:
  - entity_id: binary_sensor.bedroom_sensor_motion
    platform: device
    type: motion
  condition:
  - before: '20:00'
    condition: time
  - condition: state
    entity_id: input_select.house_mode
    state: Home-Evening
  action:
  - entity_id: light.bedroom_main_light
    type: turn_on

gives the error:

Invalid config for [automation]: extra keys not allowed @ data['action'][0]['type']. Got None
required key not provided @ data['trigger'][0]['device_id']. Got None
required key not provided @ data['trigger'][0]['domain']. Got None. (See /config/configuration.yaml, line 48). Please check the docs at https://home-assistant.io/integrations/automation/

I see, try this:

- id: 'auto-motion-bedmain-on'
  alias: Motion - Bedroom Main Light On
  description: ''
  trigger:
  - entity_id: binary_sensor.bedroom_sensor_motion
    platform: state
    to: "on"
  condition:
  - before: '20:00'
    condition: time
  - condition: state
    entity_id: input_select.house_mode
    state: "Home-Evening"
  action:
  - entity_id: light.bedroom_main_light
    service: light.turn_on
1 Like

Oh awesome! This has worked thank you!

Yeah the thing is that the Automation Editor creates different automations than the ones you do manually.

And it gets even more confusing still since the OP was trying to create an automation with the device automation editor and that one creates even more different types of automations.

I don’t get why the device automation editor adds so much more unnecessary information. Add to that that you can’t just easily edit the automation unless you edit it to completely conform to the standard automation rules and it just makes it that much harder.

3 Likes