2stimpy
(Arnold Sanders)
May 9, 2022, 7:56pm
1
I had an automation for my sun screens that worked fine for a few years.
However this year it seems to be broken.
I commented out the following
# - condition: template
# value_template: "{{ n.month >= 5 or n.month < 9 }}"
Now the automation does work.
So there must be something wrong with this, but I can’t figure out what has changed over the past months that makes this line to corrupt the automation.
Complet automation below.
- id: Screens achter dicht
alias: Screens achter dicht
trigger:
- entity_id: sun.sun
platform: state
- above: 14000
entity_id: sensor.lichtsterkte_achter_gem
for:
minutes: 5
platform: numeric_state
condition:
- condition: and
conditions:
- above: 14000
condition: numeric_state
entity_id: sensor.lichtsterkte_achter_gem
- above: 22
condition: numeric_state
entity_id: sensor.boven_achter_temperature
- condition: state
entity_id: cover.screen_boven
for:
minutes: 20
state: open
# - condition: template
# value_template: "{{ n.month >= 5 or n.month < 9 }}"
action:
service: cover.close_cover
entity_id:
- cover.screen_boven
- cover.screen_was_klein
initial_state: "on"
Where is the variable n
defined? It looks like it should be now()
…
- condition: template
value_template: "{{ now().month >= 5 or now().month < 9 }}"
123
(Taras)
May 9, 2022, 9:35pm
3
Has anyone noticed that the template allows for any month of the year?
If the template’s goal is to only allow May to August then the logical or
should be a logical and
.
{{ now().month >= 5 and now().month < 9 }}
Alternatively
{{ 5 <= now().month < 9 }}
1 Like
2stimpy
(Arnold Sanders)
May 10, 2022, 7:56am
4
Strange thing is that I had it like this for 2 years. The screens should only be activaded in may, june, juli and august.
I’ll try the suggested sollitions, thanks.
123
(Taras)
May 10, 2022, 1:22pm
5
Using logical OR the template accepts all values from 1 to 12.
Using logical AND it only allows 5 to 8.
Copy-paste the following into the Template Editor and try it.
{%- for i in range(1,13) %}
{{ iif(i >= 5 and i < 9, i, ' ') }}
{%- endfor %}
2stimpy
(Arnold Sanders)
May 10, 2022, 6:52pm
6
Thanks for explaining, ik tried it. It gives your result as expected.
I now have
- condition: template
value_template: "{{ 5 <= now().month < 9 }}"
in the automation. I also tried this in the template editor. and this gives me as a result “true”
If I change 5 in to 6, i get “false” as a result.
So I think this should be working now? Or am I still missing something.
123
(Taras)
May 10, 2022, 7:16pm
7
Then the suggested template condition will do that.
- condition: template
value_template: "{{ 5 <= now().month < 9 }}"
If you wish, you can also write it in shorthand notation.
- "{{ 5 <= now().month < 9 }}"