Automation problems - extra keys not allowed

Hey guys,

i’m getting some problems with my automation. I’m fairly new to this and i cant figure out the error.
I just want to turn on the light when i power on my tv after sunset.

2018-01-22 16:37:17 ERROR (MainThread) [homeassistant.config] Invalid config for [automation]: extra keys not allowed @ data['condition'][0]['after']. Got None
extra keys not allowed @ data['condition'][0]['offset']. Got None
not a valid value for dictionary value @ data['condition'][0]['condition']. Got None
required key not provided @ data['condition'][0]['entity_id']. Got None. (See /config/configuration.yaml, line 106). Please check the docs at https://home-assistant.io/components/automation/

So this is the error i see in the log. And here is my automation

#Turn on the light after sunset when tv is started 
- alias: 'Turn on Light with TV'
  trigger:
    platform: state
    entity_id: media_player.living_room_tv
    to: 'playing'
  condition:
    condition: sun
    after: sunset
    offset: '+00:30:00'
  action:
    service: light.turn_on
    entity_id: light.yeelight_living_room

I hope you can help me

there is no “offset” option for sun
it is called after_offset

- alias: 'Turn on Light with TV'
  trigger:
    platform: state
    entity_id: media_player.living_room_tv
    to: 'playing'
  condition:
    condition: sun
    after: sunset
    after_offset: "+00:30:00"
  action:
    service: light.turn_on
    entity_id: light.yeelight_living_room

Here’s the documentation:

1 Like

That can’t be right.

From my autos.yaml

- alias: Sunrise Lt
  id: '24'
  trigger:
  - platform: sun
    event: sunrise
    offset: "+01:00:00"
  action:
  - service: light.turn_off
    entity_id: light.sonoff_lamp, light.sonoff_spare, light.led_strip

That’s been working every day for the past nine months or so.

Also, offset: is still mentioned in the sun component :

Try adding this as a condition:

- condition: state
    entity_id: sun.sun
    state: 'below_horizon'
1 Like

Sorry I was unclear.

Sun triggers have an offset value, as you have clearly identified.
But CONDITIONS use before_offset and after_offset for sun.
You can find that documentation for sun condition at the link I previously supplied:

2 Likes

wow, thanks for the fast reply to both of you :star_struck:

so this is what works now.

#Turn on the light after sunset when tv is started 
- alias: 'Turn on Light with TV'
  trigger:
    platform: state
    entity_id: media_player.living_room_tv
    to: 'playing'
  condition:
    #condition: sun
    #after: sunset
    #after_offset: '+00:30:00'
    - condition: state
      entity_id: sun.sun
      state: 'below_horizon'
  action:
    service: light.turn_on
    entity_id: light.yeelight_living_room

is it also possible to set an offset here?

You can try the “for” clause in the state condition if you wanted an offset for after sunset.
You can’t do a before offset on state conditions.

I found this quite confusing also. It’s not clear to me why the syntax you used isn’t accepted, for consistency with the trigger syntax.