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
- condition: sun
before: sunrise
but the automation editor writes this out to the yaml file which does not allow my automation to work.
condition:
- after: sunset
before: sunrise
condition: sun
But the second code block is the result of clicking the radio buttons for before sunrise and after sunset and then saving. I would expect that to mean night time.
If it can’t produce the expected in code it should warn you or prevent you from saving or something.
I assume if I reversed my selection it would work during the day because a boolean ‘and’ would be valid and non complex?
I understand that.
However, if you choose the ‘Sun’ feature as a ‘State’ in the conditions, you get radio buttons for ‘before’ & ‘after’ sunset/sunrise as well as a input area to enter an offset amount if you would like.
All I am doing is clicking two radio buttons that are available via the front-end and clicking save.
I never posted about this issue previously as I thought I was being stupid and doing something wrong with the editor (I don’t know what it would be because as I said, you only need to click two radio buttons and click save).
As someone starting out with using automations and the ease of using a frontend editor, this is really not helpful to a newbie.
I understand your frustration. If you have an automation with or conditions like you made manually, if you open it in the editor, You will see an error that it’s not supported.
I’m not saying it’s right I’m just saying it is what it is. These types of conditions you can’t edit that way.
The crux of the confusion for the user here is not really that you can’t edit or create ‘or’ conditions it’s that a built in UI element creates a condition that can never evaluate as true and lets you save it. The resulting code effectively silently disables the automation.
If it’s impossible for it to be before sunrise and after sunset at the same time I should not be able to select that as a choice in the UI.
There are a couple of other ways to achieve the same/similar desired result using the automation editor but delving in with a text editor is definitely advised (make sure you use something like Atom, Visual Studio Code or the configurator add-on for hass.io).
Use the STATE condition and the entity sun.sun with the state set to below_horizon
Use the TIME condition and set your before and after times to when sunset/sunrise happens where you are (this may need manual adjustment throughout the year)
So I’m looking for it to come on when the sun is at 25° degrees and after 4PM as long as I haven’t switched off the input_boolean (when I am away). The tim condition of after 4 and before 6 is so that if I turn the automation on again after 6 it won’t trigger… actually, now I think of it, I used to have an automation that disabled automations when I was away but I switched to using an input_boolean instead so the automation is always on and I don’t need this condition anymore… just after 4 so I will take out the before 6 part.
Note that either after 4 or sun angle below 25° will trigger it but then the conditions also get checked before the action will be performed.
Know this is an old topic but in case it helps some one else heres another take on it: This can be done through the front end but you need an input_boolean and couple of automations to toggle the value,
Eg Put this in configuration
input_boolean:
isdark:
name: Is it dark outside?
initial: off
icon: mdi:moon-waning-crescent
Then some thing like the following, in automations (can be configured via the gui)