I am trying to have the lights turn on, when I get home and it is dark, but it doesn’t work when I add both conditions (sunset, sunrise). It does work with a single condition, atm this is “before sunrise”.
trigger:
- entity_id: device_tracker.huawei_mate_20_pro
from: not_home
platform: state
to: home
condition:
- after: sunset
after_offset: -01:00:00
before: sunrise
before_offset: +01:00:00
condition: sun
action:
- service: light.turn_on
I tried reversing conditions, sunrise before sunset but it doesn’t work either.
What am I doing wrong?
It cannot be both after sunset and before sunrise in the same day, you need two conditions, one for after sunset and one for before sunrise, nested under an OR condition.
I tried , but I get an error “Unsupported condition: or”
condition:
condition: or # 'when dark' condition: either after sunset or before sunrise - equivalent to a state condition on `sun.sun` of `below_horizon`
conditions:
- condition: sun
after: sunset
after_offset: "-01:00:00"
- condition: sun
before: sunrise
before_offset: "+01:00:00"
You’re trying to use the automation editor, aren’t you?
The OR condition works fine, it is just not supported by the automation editor because it was introduced as a ‘work in progress’ a long long time ago and then forgotten about.
You should see the automation editor as a way to try out some basic automations, and then move to coding your own as soon as you can.
I thought I needed to check what I code with the editor.
I am a beginner, obviously, so I start with the editor to create an automation, then edit/code it further.
I’ll see if it works in the evening, thanks for the help.
Config check found an error, but I don’t understand what it means. Invalid config for automation:
Got None
extra keys not allowed @ data['condition'][0]['conditions'][0]['offset'].
Got None
not a valid value for dictionary value @ data['condition'][0]['conditions'][0]['condition'].
Got None
required key not provided @ data['condition'][0]['conditions'][0]['entity_id'].
Got None. (See /config/configuration.yaml, line 104).
Please check the docs at https://home-assistant.io/components/automation/ ```
- id: '1547866606884'
alias: Ugasni luči ko odidem ali vzide sonce.
trigger:
- entity_id: device_tracker.huawei_mate_20_pro
from: home
platform: state
to: not_home
- event: sunrise
platform: sun
condition: []
action:
- data: {}
service: light.turn_off
- id: '1547865918090'
alias: Prižgi luči, kot pridem domov.
trigger:
- entity_id: device_tracker.huawei_mate_20_pro
from: not_home
platform: state
to: home
condition:
condition: or # 'when dark' condition: either after sunset or before sunrise - equivalent to a state condition on `sun.sun` of `below_horizon`
conditions:
- condition: sun
after: sunset
offset: "-02:00:00"
- condition: sun
before: sunrise
offset: "+01:00:00"
action:
- service: light.turn_on
- id: '1547865918090'
alias: Prižgi luči, kot pridem domov.
trigger:
- entity_id: device_tracker.huawei_mate_20_pro
from: not_home
platform: state
to: home
condition:
condition: or
conditions:
- condition: sun
after: sunset
after_offset: "-02:00:00"
- condition: sun
before: sunrise
before_offset: "+01:00:00"
action:
- service: light.turn_on
entity_id: ID OF LIGHT
Don’t forget to add the entity id to the bottom, and also to the one above it.
Ok, added entity in both automation rules. Didn’t change anything regarding functionality or error. Light do turn off as per rule, but they don’t turn on with the 2 conditions.