Daylight Saving Time custom sensor. Using it as condition

Please be patient since I’m using HA just for a week.

I’m trying to create a sensor for Daylight Saving Time which could be used as a condition in automation.

Firstly I’ve created in sensors.yaml loaded by configuration.yaml:

##### Daylight Saving Time #################
- platform: template
  sensors:
    daylight_saving_time:
      friendly_name: "Daylight Saving Time"
      unique_id: "daylight_saving_time_berlin"
      value_template: >
        {% set now_berlin = utcnow().astimezone() %}
        {% set dst_offset = now_berlin.dst() or timedelta(0) %}
        {% if dst_offset != timedelta(0) %}
          Sommerzeit
        {% else %}
          Winterzeit
        {% endif %}
      icon_template: >
        {% set now_berlin = utcnow().astimezone() %}
        {% set dst_offset = now_berlin.dst() or timedelta(0) %}
        {% if dst_offset != timedelta(0) %}
          mdi:weather-sunny
        {% else %}
          mdi:weather-night
        {% endif %}
      availability_template: >
        {{ utcnow().astimezone() is not none }}

Which works properly giving me in development/states Sommerzeit (Summertime) or Winterzeit (Wintertime) based on the timezone in Berlin. BUT I can’t choose neither ‘Sommerzeit’ nor ‘Winterzeit’ when using this as a condition in automation. The states pull-down-menu only offers ‘unknown’ and ‘unavailable’

I’ve tested it also (which would be the preferred way for me) as template for sensor under helpers with:

{% set now_berlin = utcnow().astimezone() %}
{% set dst_offset = now_berlin.dst() or timedelta(0) %}
{% if dst_offset != timedelta(0) %}
Sommerzeit
{% else %}
Winterzeit
{% endif %}

How do I get those two given states in the pull-down-menu?

That’s to be expected because the Automation Editor doesn’t know what are all the possible values of the Template Sensor you created.

First, I want to commend you on your progress after just one week. So I’m kind of reluctant to point you to a solution of one of the forum’s jinja guru’s that is short and simple, as always:

For the record, you also won’t be able to choose those two specific words using the suggested Binary Sensor. It will display On and Off which is sufficient for an entity that indicates if DST is enabled. However, it all depends on how important it is for your application to display Sommerzeit and Winterzeit.

Not at all. I’ll take any states I can get. :slight_smile:

BTW the condition itself works like a charm when inserted directly into yaml.

condition:
  - condition: state
    entity_id: sensor.daylight_saving_time
    state: "Sommerzeit"

But the question is how to get the Automation Editor see ‘some’ states?

If you make it a sensor, it can have any value you want. So

As said, kt also means the dropdown in the automation editor is no longer able to help you out. But it won’t prevent you from typing the values yourself.

You can’t because the Automation Editor isn’t aware of all the possible states your Template Sensor can produce.

Ok I’ll go with the binary_sensor

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

It gives me at least the states on / off under conditions. That’s enough.
I’ll keep my sensor for the dashboard.
Thanx to all of you.

2 Likes