Automation fail when using condition sun

Hello,

I’m trying to create an automation when the door opens the light goes on. But i want it only to happen after sunset and before sunrise. The moment i put the part condition in my automation it stops working and i have an error next to condition. Any ideas?

image

See the examples here: https://www.home-assistant.io/docs/scripts/conditions/#sun-condition

Also, please don’t post screenshots of text. It is impossible for us to edit and correct.

Just wanted to show the error beside the code :wink:
In any case this is the full code no more errors in the file editor but now i get a strange error in the log.

- id: '1608156855532'
  alias: deur licht aan gang
  description: ''
  trigger:
  - type: opened
    platform: device
    device_id: 2bbe457e13d27e811b16afa618d988aa
    entity_id: binary_sensor.deur_naar_gang
    domain: binary_sensor
    condition: or
    conditions:
    - condition: sun
      after: sunset
    - condition: sun
      before: sunrise
  action:
  - service: switch.turn_on
    data: {}
    entity_id: switch.sonoff_voordeur
  mode: single
  • Invalid config for [automation]: required key not provided @ data[‘trigger’][1][‘platform’]. Got None. (See /config/configuration.yaml, line 10).
  • Invalid config for [automation]: [condition] is an invalid option for [automation]. Check: automation->condition. (See /config/configuration.yaml, line 10).

configuration.yaml line 10 is this:

group: !include groups.yaml

You’re trying to include your OR condition in your trigger, that’s not where it goes.

Needs to be in the condition block…

- id: '1608156855532'
  alias: deur licht aan gang
  description: ''
  trigger:
  - type: opened
    platform: device
    device_id: 2bbe457e13d27e811b16afa618d988aa
    entity_id: binary_sensor.deur_naar_gang
    domain: binary_sensor
  condition:
    condition: or
    conditions:
    - condition: sun
      after: sunset
    - condition: sun
      before: sunrise
  action:
  - service: switch.turn_on
    data: {}
    entity_id: switch.sonoff_voordeur
  mode: single

Yep that was it :man_facepalming:
I find it very confusing to put the word condition 4 times in there… I tried several ways but they failed every time.
Thanx for the advice!

1 Like

First one is the condition block of the automation, second one says that you want to use an OR condition, third and fourth are the conditions you’re ORing.

1 Like