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"
I have not seen after_offset or before_offset anywhere… should be just offset I believe? Also it won’t span across midnight as mf_social said…
I used this for a reference:
Never used that… only used offset… the sign sorts out if it’s before or after…
Sounds logical and apparently works too, but doesn’t help with the error I get - “Unsupported condition: or”
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.
Still doesn’t work… Does HA have a troubleshooting and testing for automation rules? Logs or something so I could see what’s wrong.
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/ ```
Please post the entire automation with formatting preserved.
- 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.
Both have an id, the top one wasn’t showing due to my copy&paste error; should be showing correctly now.
No, the entity id of the light(s) you want to turn on.
Ah, sorry, I didn’t enter any entities, because for the moment I just want all the lights to turn on and off.
That facility has been removed because it causes too many problems, if you want all your lights to come on you need
entity_id: group.all_lights
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.
Found this thread:
Looks like a bug?
Anyway, I am testing a workaround, instead of before sunrise or after sunset I am using:
condition: state
entity_id: sun.sun
state: 'below_horizon'
Seems to be working, light do turn on
I am still getting an error, though:
Configuration invalidCHECK CONFIG
Invalid config for [automation]: expected a dictionary @ data['condition'][0]. Got None extra keys not allowed @ data['entity_id']. Got None extra keys not allowed @ data['state']. 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.
trigger:
- entity_id: device_tracker.huawei_mate_20_pro
from: home
platform: state
to: not_home
- event: sunrise
platform: sun
condition: []
action:
- data: {}
entity_id: group.all_lights
service: light.turn_off
- id: '1547865918090'
alias: Prižgi luči.
trigger:
- entity_id: device_tracker.huawei_mate_20_pro
from: not_home
platform: state
to: home
- event: sunset
platform: sun
condition: state
entity_id: sun.sun
state: 'below_horizon'
action:
- entity_id: group.all_lights
service: light.turn_on