Lights on when sunset

Can someone tell me what is wrong with this code?.

#Automation Keukenverlichting aan bij aanwezigheid:
- alias: 'Keukenverlichting Aan'
  trigger:
    platform: sun
    event: sunset
    offset: "-00:20:00"
  condition:
    condition: state
    entity_id: 
    - device_tracker.iphone1
    - device_tracker.iphone2
    state: home
  action:
    service: light.turn_on
    entity_id: light.shelly_shdm_1_db2fb3

I’m getting an error when reloading my automations

Indentation. Should be:

entity_id:
  - device_tracker.iphone1
  - device_tracker.iphone2

Doesn’t work either :frowning:

I’m using this one also as an automation and works great:

    entity_id: 
    - binary_sensor.0x00158d00031cd4ef_contact
    - binary_sensor.0x00158d0003139e42_contact
    to: 'on'

Getting this error:
Invalid config for [automation]: extra keys not allowed @ data[‘condition’][0][‘state’]. Got None
not a valid value for dictionary value @ data[‘condition’][0][‘condition’]. Got None
value should be a string for dictionary value @ data[‘condition’][0][‘entity_id’]. Got None. (See /config/configuration.yaml, line 12). Please check the docs at https://home-assistant.io/integrations/automation/

Try replacing entity_id with entities:

Or bringing them in one line like so

entity_id: device_tracker.iphone1, device_tracker.iphone2

Both not working :frowning:

I don’t believe you can list multiple entities in a condition like that. Make that single condition two separate state conditions (one for each entity). Conditions are AND by default so listing two conditions will limit the automation to executing only if both conditions are true.

@icaman004 Believe it or not, either of those two indentation styles with a list will work. My entire config has indentation like this:

foo:
- bar
- bar

I use this as an automation to turn lights red when a doorsensor triggers:

    entity_id: 
    - binary_sensor.0x00158d00031cd4ef_contact
    - binary_sensor.0x00158d0003139e42_contact
    to: 'on'

They don’t need to be both triggered before the light turns red. One is fine.

Right, but that’s in a trigger, not in a condition. You can list entity IDs in a trigger like that. Also, triggers are always OR, while conditions are always AND (when just you list them without specifying condition: or of course).

Your error says

value should be a string for dictionary value @ data[‘condition’][0][‘entity_id’].

Which means it’s expecting a string, not a list, for entity_id: in your condition.

1 Like

Ah oke :).
So how do i split these two device_trackers?

Try this:

#Automation Keukenverlichting aan bij aanwezigheid:
- alias: 'Keukenverlichting Aan'
  trigger:
    platform: sun
    event: sunset
    offset: "-00:20:00"
  condition:
  - condition:
    entity_id: device_tracker.iphone1
    state: 'home'
  - condition:
    entity_id: device_tracker.iphone2
    state: 'home'
  action:
    service: light.turn_on
    entity_id: light.shelly_shdm_1_db2fb3

Was just about to post that @Markus99 :wink:
Thanks all for helping!

1 Like

I don’t think that’s quite right. Using the dash is basically an indentation. So dash plus indent equals double indentation.

This looks quite functional, or am I wrong?

#Automation Keukenverlichting aan bij aanwezigheid:
- alias: 'Keukenverlichting Aan'
  trigger:
    platform: sun
    event: sunset
    offset: "-00:20:00"
  condition:
    - condition: state
      entity_id: device_tracker.iphonemaurice
      state: 'home'
    - condition: state
      entity_id: device_tracker.iphone_van_yvette_2
      state: 'home'
  action:
    - service: light.turn_on
      entity_id: light.shelly_shdm_1_db2fb3

Both are ok. Most of the docs show

foo:
  - bar

but

foo:
- bar

is fine too.

In fact, if you enter in the second type on YAMLLint, it says valid yaml but displays the first type in the output.