Probably. I wasn’t aware of the or option.
I posted the or above that was created by the editor. Is there a way to simulate sunset / sunrise in HA to test automations.
You don’t need two ORs, one OR at the top is enough. Remove the second OR.
You need to create two conditions below the or condition in the editor, you cant have sunrise and sunset in the same condition.
So you are saying the code above is wrong? This was copied from the docs.
condition: or
conditions:
- condition: sun
before: sunrise
after: sunset
after_offset: '03:00:00'
This from your automation is wrong, the example from the docs is fine. You need to create two separate conditions below the or condition. One for the sunset and one for the sunrise.
I believe this is what I have been saying (not sure here or another thread) that the GUI editor is not making the automation correctly. Hopefully the one I now have will work.
It does but you did not use it correctly. When you choose the sun condition in the GUI editor you specify only one, sunrise or sunset. Then you create another condition, choose the sun condition and configure the other part.
Like this?
- entity_id: binary_sensor.pir_back_garden
from: 'off'
platform: state
to: 'on'
condition:
- condition: or
conditions:
- before: sunrise
condition: sun
- after: sunset
condition: sun
action:
- entity_id: switch.back_garden_security_light
service: switch.turn_on
- service: script.1578119325234
Think I have got the hang of this ` now? thought it was only one back tick, not three…
I had to manually change the code in the Automation Yaml to get it to work and not in the GUI in Automations.
Yes exactly like this
if you compare it to the docs it’s the same only the order is a bit different.
That’s exactly the example I gave you above
Just so I understand you correctly are you saying that you can or can’t use the Condition " or" in the GUI editor?
When I used the “or” in the GUI the yaml code generated was incorrect. When I manually entered the code in the automations yaml file the automation ran correctly. I pasted above the code generated by the GUI and the code I entered manually.
I am having issues with the GUI not working correctly and for other users it works great. Not sure what the differences are between the systems that work and the systems that don’t. I can’t even get the first screen on the GUI to work correctly. I get no drop down options.
What version HA are you running?
I am on Home Assistant 0.103.5
The same version as you. Also all components and integrations are at the latest version.
The GUI creates it correctly.
Take a look at the GIF below, I tried to show it, hope the quality is good enough. If you do it exactly like I did in the video, does it not create the YAML I show at the end of the video?

It doesn’t do this on mine, also on the first screen you hit skip rather than using the drop-down. This is also broken for me.
You could have copy/pasted the example I gave you above and had this working already. I gave you a working version to paste in and adjust with your named devices.
Although it is great having and using the automation editor as a beginner, you can not achieve as much as you can editing your automations.yaml file. You end up creating much more involved automations to achieve something that can be done with a template.
If you only want to the light to turn on after sunset AND before sunrise, the example I provided already does that. You don’t need or conditions. Use the sun elevation, it is a far more elegant solution almost every time.
trigger:
platform: state
entity_id: binary_sensor.pir_back_garden
to: 'on'
condition:
condition: template
value_template: "{{ states.sun.sun.attributes.elevation | int < 1 }}"
action:
service: switch.turn_on
entity_id: switch.back_garden_security_light
About the dropdown this might be sometjing with supported devices but I don’t know exactly. But if you create the automation like I did and the YAML created for the sun condition is not correct, then there is a bug with your system.
I now understand what I was doing was wrong in the way the GUI was written. I took the “or” as a logic “or” where you need to set the two conditions. Since the two open up when you choose OR in the drop down I was setting it up there. I did not realize that the two it was showing was only the first condition of the or and you need to pick 1 and then need you need to add a second condition. I still think the way it was implemented is wrong, but now I understand how to use it.
I agree that you should not be able to choose before and after, as well as sunrise and sunset in the same condition. You should only be able to choose before or after and then sunrise or sunset.
