Well, I must have had a “senior moment” last night when I went to bed because I completely forgot to set my alarm to get up for work this morning and to put my phone on the charger like I do every night.
So, I got to thinking, since I already have a work calendar set up and I have my phone alarm status all coming in to HA why not automate my Echo to remind me around the time I usually go to bed that I don’t have an alarm set if I have to go to work the next day. Isn’t HA awesome!
I set up a boolean to indicate if my alarm is not actually set if it should be and it’s correctly turned on by the followimg automation:
- alias: Set My Phone Alarm Needed Bool
trigger:
- platform: template
value_template: >
{% if is_state('sensor.my_mobile_app_next_alarm', 'unavailable') and ( is_state_attr('calendar.my_gmail_com', 'message', 'days') or is_state_attr('calendar.my_gmail_com', 'message', 'DD - support') ) %}
true
{% else %}
false
{% endif %}
action:
- service: input_boolean.turn_on
entity_id: input_boolean.my_phone_alarm_needed_but_not_set
But if I set the alarm I want the boolean to also get turned back off.
I tried to use the trigger data to turn it on/off as appropriate like this:
action:
- service: >
{% if trigger.to_state.state == 'true' %}
input_boolean.turn_on
{% else %}
input_boolean.turn_off
{% endif %}
entity_id: input_boolean.my_phone_alarm_needed_but_not_set
But it didn’t work.
I don’t think I’ve ever seen the trigger data from a template trigger used in the service call. According to the docs it implies my trigger data should work. But in thinking about it logically the trigger needs to go from true to false then back to true again for the automation to actually trigger. And if the automation doesn’t trigger then there is no trigger data to check the new “to_state” so of course it wouldn’t do anything at all. It doesn’t even work when the trigger is satisfied (template goes from false to true) and the automation is actually triggered. So it doesn’t look like even then there is an available “to_state” to satisfy the “if” and run the turn_on service…
So I’m not sure if I’m doing something wrong and/or thinking about it wrong or if the docs are misleading.
The black box of the “trigger” object is very hard (if not impossible) to troubleshoot since you can’t see what’s going on behind the scenes. Or at least I don’t know of a way to see it.
I’ve got it working fine using two automations (one to turn it on & another to turn it off) but if nothing more than for an educational opportunity I’d like to know how to correctly set up the service call in this situation if it’s even possible.
TIA.