Is a device_id needed for an automation?

I used to use AppDaemon for my automations, I am now moving to the HA automations.yaml file and pyscript for more complicated ones.

I created a simple automation via the GUI that works:

- id: '1606735537497'
  alias: volets parents - soir
  description: ''
  trigger:
  - platform: sun
    event: sunset
  condition: []
  action:
  - device_id: 2123c7d6fb4b11ea8642fdb20834c692
    domain: cover
    entity_id: cover.parents_volets
    type: set_position
    position: 10
  mode: single

Since I have a few similar ones, I copied/pasted the above in automations.yaml and I changed

  • the id
  • the description

and removed device_id as I thought it was redundant with the entity_id:

- id: '1606735537498'
  alias: volets michael - soir
  description: ''
  trigger:
  - platform: sun
    event: sunset
  condition: []
  action:
  - entity_id: cover.parents_volets
    type: set_position
    position: 10
  mode: single

Apparently, I was wrong as I now get an error message in my automations:

2020-11-30 12:34:34 ERROR (MainThread) [homeassistant.config] Invalid config for [automation]: [type] is an invalid option for [automation]. Check: automation->action->0->type. (See /config/configuration.yaml, line 27).

The message suggests that there is a problem with type but when i just removed device_id the problem was with domain (see the working version). So it looks like it is actually the lack of device_id that triggers the issue.

Do I really need device_id? If so I am not sure where to find it?

Otherwise, I will go for the GUI, even if it means clicking the same thing a few times.

Device_id is used by the GUI editor, same goes for type and domain. These are used for so called device automations. You can’t mix them together.

This example from you:

- device_id: 2123c7d6fb4b11ea8642fdb20834c692
    domain: cover
    entity_id: cover.parents_volets
    type: set_position
    position: 10

Is equivalent to:

- service: cover.set_position
  entity_id: cover.parents_volets
  data:
    position: 10

Thank you very much for your answer.

I did not realize that I called a device (the shutter automation device, a shelly 2.5) instead of the service (which makes more sense).

It is very clear now, thank you.