Trying to configure a template sensor for summer/winter time

Hi, I need a template sensor that indicates when we are using Daylight Saving Time.
In my country the time changes “the last sunday of march” and “the last sunday of october”
I have been trying generating dates, firing an automation every night at 3:01 (passed the time change), and checking the different conditions…but I’d like to have it calculated in a sensor.

Isn’t there a sensor that tells us automatically if DST is being applied in the current timezone?

Paste this into Home Assistant’s Template Editor:

{{now().timetuple().tm_isdst}}

Currently, the result is 1 for me which is correct because DST is in effect where I live.

I think the result is either -1 or None if DST is not in effect.

1 Like

Thank you! I’ll try to simulate different dates and check this (hope I don’t mess the database meanwhile…)

Just for future reference: in v0.92+ this template won’t render automatically, for doing so the template sensor must include:
entity_id: sensor.time

To clarify, the template I provided would not be suitable for use in a Template Sensor in any recent version of Home Assistant (since 0.87 or thereabouts). That’s because the function now() is not an entity that Home Assistant monitors for changes.

The example I offered was simply to demonstrate how to get DST information from a datetime object. If it were to be used in a Template Sensor, some other entity is needed that can be monitored by Home Assistant. Your suggestion to use sensor.time is perfect because that’s an entity that Home Assistant monitors once every minute (sensor.date is monitored once every day).

1 Like