Beginner in home assistant.
I am trying to understand automations and variables.
I have read this: automation trigger variables
I think this would work as:
First trigger is evaluated 30 minutes before sunset… The variable is always True so the conditions says: “carry on”
Second trigger is evaluated before the first one since the offset is 1 hour before sunset.
I pasted the whole line: is_true: "{{ states('sensor.condition') in ['cloudy', 'rainy'] }}"
in the developer tools template section and it gives: is_true: “True”.
This makes me think that this variable is_true evaluated to True and thus one hour before sunset the condition should be met and the action should be taken.
However. When I look in the traces the path always runs the first trigger and never the second one?
Can someone tell me why the rainy cloudy variable is never evaluated?
trigger:
- platform: sun
event: sunset
offset: "-00:30:00"
variables:
is_true: true
- platform: sun
event: sunset
offset: "-01:00:00"
variables:
is_true: "{{ states('sensor.condition') in ['cloudy', 'rainy'] }}"
condition:
- "{{ is_true }}"
action:
- service: script.sfeerlampen
data: {}
mode: single
But this would run nothing when it is not cloudy or rainy?
The condition is False when not cloudy or rainy. In that case I would like the lights turn on with an offset of -30
Because you’re confusing internal state with presentation. “Rainy” is the localised text based on the internal state rainy; partlycloudy becomes “Partly cloudy” . Not everyone in the world speaks English, which is why it’s done this way.
Thanks for your help
With the filter is works!
So the solution is to use this:
is_true: "{{ states('sensor.condition') | lower in ['cloudy', 'rainy'] }}"
Although I am still not sure why. My code had ‘cloudy’ and ‘rainy’ with lowercase ‘c’ and ‘r’ and did not work.
Now with the filter it DOES work. That suggest that the state delivers Rainy or Cloudy.