Template in automation does not pass, gives true in template editor

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?

The curly braces… though you can just use day instead strftime('%d').

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… :grin:

1 Like

Thanks, this works.
-curly brackets
-template on seperate line
->- at line before.

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.

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.