simon1964
(Simon1964)
December 29, 2023, 2:44pm
1
I’m quit new to home assistant and want to automate my vacuum.
I want it to run when I leave home.
However only one time a day.
Because of this I made the following automation"
automation:
- alias: "Vacuum: start when leaving home"
trigger:
- platform: zone
entity_id: person.simon
zone: zone.home
event: leave
condition:
- condition: template
value_template: "as_datetime(states('sensor.roborock_s7_last_clean_end')).strftime('%d') != now().strftime('%d')"
action:
- service: vacuum.start
target:
entity_id: vacuum.roborock_s7
I get true in the template editor when entering this:
{{as_datetime(states('sensor.roborock_s7_last_clean_end')).strftime('%d') !=
now().strftime('%d')}}
However when I check the condition under Settings → automations & scenes I get:
condition did not pass
What am I missing?
simon1964:
What am I missing?
The curly braces… though you can just use day
instead strftime('%d')
.
123
(Taras)
December 29, 2023, 4:37pm
3
Like Didgeridrew said, your template should be wrapped in double braces.
If you are interested, here’s a slightly shorter version:
condition:
- condition: template
value_template: >
{{ as_datetime(states('sensor.roborock_s7_last_clean_end')).day != now().day }}
1 Like
Dang it Taras… Just as I’m editing my post so it’s not so cheeky…
1 Like
simon1964
(Simon1964)
December 29, 2023, 7:02pm
5
Thanks, this works.
-curly brackets
-template on seperate line
->- at line before.
123
(Taras)
December 29, 2023, 8:09pm
6
simon1964:
Thanks, this works.
You’re welcome!
Please consider marking my post above with the Solution tag (or Didgeridrew’s post if you chose to follow its suggestion). 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.
For more information about the Solution tag, refer to guideline 21 in the FAQ .
finity
December 29, 2023, 9:24pm
7
Just to be clear…
you don’t need to put it on the separate line.
it can be on the same line as long as it’s inside quotes as in your first attempt.
if you had just added the brackets to your first attempt it would have worked.