Need help with template - String to date converter

Hi, I have a sensor named ‘sensor.street_cleaning’ that contains day of the street cleaning in String format. I’m looking for creating an automation that will send me notification to move my car the day before street cleaning. For example, if sensor’s state says ‘Tuesday’ then I should receive notification on Monday. Is it possible

This is close to what my needs I found online but not working for me.

  alias: Send notification if tomorrow is Monday
  trigger:
    - platform: time
      at: '12:00:00'
  condition:
    condition: template
    value_template: "{{ (is_state('sensor.accord_street_cleaning_2', 'Monday') and now().weekday() == 0) or (is_state('sensor.accord_street_cleaning_2', 'Tuesday') and now().weekday() == 1) or (is_state('sensor.accord_street_cleaning_2', 'Wednesday') and now().weekday() == 2) or (is_state('sensor.accord_street_cleaning_2', 'Thursday') and now().weekday() == 3) }}"
  action:
    - service: notify.pushbullet
      data:
        message: "Tomorrow is Monday, Tuesday, Wednesday, or Thursday!"```
alias: Send notification if tomorrow is Monday through Thursday
variables:
  tomorrow: "{{ (now() + timedelta(days=1)).strftime('%A') }}"
trigger:
  - platform: time
    at: '12:00:00'
condition:
  - "{{ tomorrow in ['Monday', 'Tuesday', 'Wednesday', 'Thursday'] }}"
  - "{{ is_state('sensor.accord_street_cleaning_2', tomorrow) }}"
action:
  - service: notify.pushbullet
    data:
      message: "Tomorrow is {{ tomorrow }}!"
1 Like

Thank you but I’m getting tomorrow is undefined.

You cant use the template editor to test variables like that.

You have to do this:

1 Like

Where did you learn that you can use the Template Editor to test an automation?

The trigger variable only exists when an automation’s trigger is triggered. Reference: Testing your automation

If not triggered by the automation’s trigger, the trigger variable is undefined so any template containing the trigger variable cannot be tested in the Template Editor.

1 Like

Stupid me! Learning new things everyday. Thank you both of you legends.

Does the automation I posted meet your requirements?

It did. Thank you so much!

1 Like