The thing is, timezone information is part of glibc, which pretty well every distro uses, although HAOS uses a buildroot, and I do not know which C library that uses. Nevertheless timezone data should be available on any system. Time zone data includes DST info - it has to in order to switch your device’s timezone when DST comes and goes.
So the info is available on the system.
EDIT: the zone information is compiled, and in most systems is in (for my zone) /usr/share/zoneinfo/Pacific/Aukland
After much googling there is an obscure program on linux systems (found in coreutils) that dumps some zoneinfo information in a semi digestible format, It can show your DST transitions. For example
nick@hass:~$ zdump -V -c 2021,2023 Pacific/Auckland
Pacific/Auckland Sat Apr 3 13:59:59 2021 UT = Sun Apr 4 02:59:59 2021 NZDT isdst=1 gmtoff=46800
Pacific/Auckland Sat Apr 3 14:00:00 2021 UT = Sun Apr 4 02:00:00 2021 NZST isdst=0 gmtoff=43200
Pacific/Auckland Sat Sep 25 13:59:59 2021 UT = Sun Sep 26 01:59:59 2021 NZST isdst=0 gmtoff=43200
Pacific/Auckland Sat Sep 25 14:00:00 2021 UT = Sun Sep 26 03:00:00 2021 NZDT isdst=1 gmtoff=46800
Pacific/Auckland Sat Apr 2 13:59:59 2022 UT = Sun Apr 3 02:59:59 2022 NZDT isdst=1 gmtoff=46800
Pacific/Auckland Sat Apr 2 14:00:00 2022 UT = Sun Apr 3 02:00:00 2022 NZST isdst=0 gmtoff=43200
Pacific/Auckland Sat Sep 24 13:59:59 2022 UT = Sun Sep 25 01:59:59 2022 NZST isdst=0 gmtoff=43200
Pacific/Auckland Sat Sep 24 14:00:00 2022 UT = Sun Sep 25 03:00:00 2022 NZDT isdst=1 gmtoff=46800
This shows transitions on April 3, 2021, Sept 25, 2021, April 2 , 2022 and Sept 24 2022. A bit of parsing required though, and there is no json output that I can see.
Yes, this is ultimately the problem with all languages too. This is why you have to loop until you find the datetime because the APIs do not offer it. They only tell you when it’s applied or not. I can get all of that information directly from the datetime library, and you have access to them in templates.
This is why I was saying the code I provided can be optimized. It’s currently using the time zone because originally dst() wasn’t exposed to templates. It always returned null. After switching to pytz, it now is populated in the template engine.
I updated it, it’s now 3 separate sensors. Try it out and let me know if it works. The automation changed too. It should properly tell you the gain/lose
OK the first 2 work in template editor, but the last one won’t render for me:
ValueError: not enough values to unpack (expected 3, got 1)
I set
{% set daylight_savings_next = "2022-03-27T02:00:00+00:00" %}
Which was returned from the first template, and then replace states('sensor.daylight_savings_next') with just daylight_savings_next which for the second template correctly renders and returns 146 days.
Yup adding | int after seconds has done the job. lose 1 hour
That’s correct.
EDIT:
Thank you for your efforts, it’s very much appreciated. I have now copied the code in to daylight_savings.yaml in my template directory and will shortly have shiny new sensors!