I’m trying to make HA alert me about having to take out the trash. I did this by integrating a Google calendar and sending notifications to Google Hangout, which, all by itself, works fine.
Only problem is, the trigger sends me notifications no matter what the value_template is.
This is the automation:
- alias: Gelber Sack
trigger:
- platform: template
value_template: '{{states.sensor.date.state == strptime(states.calendar.gelbersack.attributes.start_time, "%Y-%m-%d %H:%M:%S").strftime("%Y-%m-%d")}}'
- platform: time
at: '06:00:00'
action:
- service: notify.me
data:
message: "Gelben Sack rausstellen!"
I checked the different parts in the template editor:
{{states.sensor.date.state}}
{{states.calendar.gelbersack.attributes.start_time}}
{{states.sensor.date.state == strptime(states.calendar.gelbersack.attributes.start_time, "%Y-%m-%d %H:%M:%S").strftime("%Y-%m-%d")}}
Those are the results:
2018-09-17
2018-10-08 00:00:00
False
As you can see, the dates differ and the value_template is evaluated to “False”, which is correct.
I even have a second calendar:
- alias: Restmüll
trigger:
- platform: template
value_template: '{{states.sensor.date.state == strptime(states.calendar.restmuell.attributes.start_time, "%Y-%m-%d %H:%M:%S").strftime("%Y-%m-%d")}}'
- platform: time
at: '06:00:00'
action:
- service: notify.me
data:
message: "Restmüll rausstellen!"
Same debugging tests:
{{states.sensor.date.state}}
{{states.calendar.restmuell.attributes.start_time}}
{{states.sensor.date.state == strptime(states.calendar.restmuell.attributes.start_time, "%Y-%m-%d %H:%M:%S").strftime("%Y-%m-%d")}}
Results:
2018-09-17
2018-09-17 00:00:00
True
As you can see, in case 1 the dates differ, 2018-09-17 != 2018-10-08, and the result is “False”.
In case 2 the dates match, 2018-09-17 == 2018-09-17, and the result is “True”.
Still I get sent notifications for both triggers every time.
Did I make a mistake somewhere? I can’t wrap my head around this. Is it the use of platform: template AND platform: time which makes the trigger fire every time? Do I need to add logical AND/OR conditions?