Last afternoon I got an idea! ![]()
I have been using helpers with tod (time of day), created them many, many years ago.
I wanted the outdoor lights to be on during the night so I set before to sunrise plus some time offset and after to sunset minus some time offset.
This didnât work as I wanted. So I did the inverse, created a new helper where I set after to sunrise plus some time offset and before to sunset minus some time offset.
This was called âoutdoordayâ. Then the old outdoornight became ânot outdoordayâ. Not perfect, but it works most of the time.
The problem here that it is the old style of helpers in the configuration.yaml, they donât have an ID, and therefor can not be edited in the UIâŚ
So now I got some energy to test and learn new thingsâŚ
Custom Templates! TADA!
Started to look at sensor.sun_next_* properies, tried many variants in the template tool.
Got a macro to work and was pretty proud of it, but it failed at som stage.
So I started to think about it, and came to this conslusion:
It is
night when sensor.sun_next_rising < sensor.sun_next_setting
Simple as that basicly!
But could not make it that simple I needed the offsets, and got different offsets for indoor lights, outdoor lights, christnas lights indoor and christnas lights outdoor.
Thatâs why the macro⌠And now I can use number helpers for simple adjustment, even the Mrs can dio it!
{% macro night_on(sunrise_offset, sunset_offset) %}
{{ states(âsensor.sun_next_risingâ) | as_datetime | as_local + timedelta(minutes=sunrise_offset) < states(âsensor.sun_next_settingâ)| as_datetime|as_local + timedelta(minutes=sunset_offset) }}
{% endmacro %}
The call:
{% from âmytod.jinjaâ import night_on %}
{{night_on(30,-20)}}
With off at 30 minutes before sunrise and on at 20 minutes before sunset!
Now I just have to figure out how to put multiple macros in a fileâŚ
I have loads that I need to moveâŚ