Turn on lights when I arrive home, but different scenes for different sun elevations. How?

Hello.

I’ve realized that two of my automation’s crash a bit with each other and I have to sort of combine them like a IF ELSE condition. I’m not particularly good of a programmer and am learning HA and YAML by reading documents and the forums here but can’t quite figure this one out. I need some assistance on how to think to improve my automation’s.

https://pastebin.com/rhGnNS6U

Currently my automation’s look as above. The first one (sunset_if_home) is my automation to turn on the lights when I arrive/am home and the sun is below 5 degrees above the horizon. And between some random times so that it doesn’t activate 5 in the morning when I’m sleeping. The second automation (evening_light) is that my lights should dim when I’m home and the sun is 10 degrees below the horizon because bright lights is a bit rough on my eyes then.

The problem I have is that if I’m out for long enough that the sun goes below 10 degrees under the horizon my lights won’t turn on when I arrive home. So I’d like to do an automation that starts my “normalvit” scene that is a normal white light when the sun is below 5 degrees (and above 10) but if I arrive home when the sun is below 10 degrees I’d like the automation to start the “dimmad_vit” scene instead with a dim white light.

I still want to keep the second automation to automatically dim the lights below 10 degrees, as it’s working well as long as I get home in time.

Anyone got any suggestions on how I could adjust my automations to meet my needs or got any tips for documentation I could read to perhaps figure it out on my own? Thanks a bunch!

You could call the scene.turn_on with a data template like this, have three triggers: you arriving home, the sun dropping below 5, and the sun dropping below -10. Keep your “being home” and “odd hours” conditions.

{% if states('sun.sun.attributes.elevation') | float < 5 and states('sun.sun.attributes.elevation') | float > -10 %}scene.normalvit{% else %}scene.dimmad_vit{% endif %}
1 Like

Yeah, I turned to the Discord for help and got some great help from skalavala.

We ended up with this code: https://pastebin.com/ArH0R4Hp

I will try this out for the coming days and see if it works out as intended.