What I want to achieve:
I have a terrarium full of plants that normally reside in tropical or sub-tropical areas. I thought it would be pretty cool to give them a daylight cycle that is the same as some place close to the equator. So I want the lights to turn on when the sun goes up at some specified place and turn off when the sun sets.
What I have done:
I found an open API that gives me sunrise and sunset times as JSON (for some random spot in Africa), here: https://api.sunrise-sunset.org/json?lat=9.757452&lng=16.415384
I use the RESTful integration to “extract” the variables sunrise and sunset respectively to two entities that I call “sensor.sun_tropic_sunrise” and “sensor.sun_tropic_sunset”.
This is where I am lost. I have tried a couple of different ways I found here on the forum, one was using a template for the “action” that had an if-else-clause checking if the current time is before or after sunset and sunrise, setting switch off or on. That partly worked; I got it to print the right switch state but it never triggered. I can’t remember what I set the trigger to… I believe I even tried setting trigger to template sensor.sun_tropic_sunrise == True and still nothing.
I’ve also tried this:
trigger:
- platform: time
at: "{{ as_datetime(states('sensor.sun_tropic_sunset')[:19]) }}"
It doesn’t set it off either.
Any suggestions as to what I should try next?