Hi,
I have an automation that works for the light in our bedroom.
The light is Tuya based and is turned on and off via a Shelly 2.5.in an automation
The problem we have is that the light turns on when daylight saving is changed, so twice a year in the middle of the night.
So I’m wondering if I can turn off the automation on the days that DST toggles, so the last sunday of March and the last sunday of October.
Add this Template Condition to your automation and it will prevent it from executing its actions on the last sunday of March and the last sunday of October.
condition:
- condition: template
value_template: >
{% set dst_changeover = now().month in [3,10]
and now().isoweekday() == 7
and (now() + timedelta(days=7)).month != now().month %}
{{ not dst_changeover }}
Pretty much if @123 posts it then it’s likely the right answer, so I’m not disputing it. That being said, you might want to create a template sensor so you can use DST in other parts of your automations. For me, I use a DST sensor pretty frequently:
I believe the difference is that my template determines if today is (not) one of the two DST changeover days whereas yours indicates if DST is in effect or not.
If my template is used in a Template Binary Sensor, it will be on for all days of the year except two.
If your template is used for a Template Binary Sensor, it will be on for all the days when DST is in effect.
You are the YAML/Jinja/Python Zen Master (not being snarky, I mean that), I like having a template sensor just because I never have to remember how I calculated it on my other automations
If my template is used in a Template Binary Sensor, it will be on for all days of the year except two
This looks like what I need.
With such a Template sensor I can turn off the automation when the sensor is OFF and it’s 1.55AM and turn it back on at 3.05AM.
Turning off automations as a normal part of their operation is not a recommended practice. An automation should contain all necessary logic to control its operation. What I suggested should be used as a condition in the automation so it can controls its own operation.
If you have just one automation, that shouldn’t run on DST changeover days, then you don’t need to create a Template Binary Sensor. Simply do what I had suggested; add the Template Condition I posted above to that automation. The automation will not execute its actions on the two DST changeover days.
If you have multiple automations then, yes, you can create a Template Binary Sensor with the suggested template and use it in a State Condition in each automation.
It should report on now, not off.
The template reports false on the two DST changeover days, otherwise it reports true. Today is not a DST changeover day so it should be reporting on. A Template Binary Sensor reports false as off and true as on.
That is strange, I copied it from here, and it shows OFF now.
I’m not sure if I understand the code good enough but to me it looks like:
SET (so state is ON) if month is 3 or 10 and day=sunday and it’s the last day of the month
else NOT (so state is OFF)
The template is reporting True today because today is not a DST changeover day. That’s exactly what is needed for the Template Condition I posted above and suggested you add to your existing automation. It will prevent the automation from executing its actions on the two DST changeover days (those are the only two days when the Template Condition will report False).
Found my mistake; I copied the line above too to the helper. Now it behaves as you describe.
(And I will have to look into understanding it properly I guess)
I prefer having it in the helper as I don’t know if I will have other automations using it.
Please consider marking my post above with the Solution tag. It will automatically place a check-mark next to the topic’s title which signals to other users that this topic has been resolved. This helps users find answers to similar questions.
That’s your choice. If used in a Template Condition or in a Template Binary Sensor, the principle of suppressing actions with the suggested template remains the same (and superior to original goal of turning off the automation).
I think that last part is a question of semantics, turning it off as in making it not do any action.
But it’s not 100% clear why the ligth turns on on that moment, this is the first try to solve it.