I was thinking I would only use the second trigger ( I left it for comparison). I do realize though that what Iām trying to do with that trigger is more of a conditon.
So, when my automation completes (If I was still in the room, but still enough for this to happen)
I then move while the automation is probably still in progress turning off the lights. The binary_sensor.motion_sensor_kitchen_motion changes to on. But since the automation is not quite finished, it does not trigger. When the automation finishes, the motion is still on, not changing TO: on. So it does not trigger until it goes off and then back on.
I was thinking (incorrectly), that that the trigger template would be on. and would trigger if it had recently triggered.
I dont like the on/off for X minute automations (probably just being picky), I like it when the lights turn off quickly after leaving a room. Well most the time anyway. Iām going to rethink this a bit. Iāll share anything i come up with.
I havenāt completely followed how your binary_sensor reacts to motion, and exactly what youāre ultimately trying to achieve, but, yes, it is problematic if an automationās trigger fires while the actions of the automation are still running from a previous trigger. I definitely try to avoid that. So one thing I can suggest (in general, and especially if there are any waits or delays in an automationās actions) is to move the actions to a script, and start the script from the automation. In fact, the automation should first cancel the script, then call it. So, like this:
Thanks for your help. I feel like Iām starting to wrap my head around the value template more and more. Does this look like it will work. I have two possible work locations, and I used to always work at each location on specific days, so my automation was hard coded for which day of the week, but lately Itās been more fluid, so I wanted to make a single automation and have it trigger based on an input select of work locations. The sensor changes to true when I should be ready to head out the door. That works well.
- alias: "Notify Me when its time to leave for work"
trigger:
- platform: template
value_template: >
{{ is_state('sensor.time_to_leave_for_work1', 'True') and
is_state('input_select.work_location', 'Work1') }}
- platform: template
value_template: >
{{ is_state('sensor.time_to_leave_for_work2', 'True') and
is_state('input_select.work_location', 'Work2') }}
condition:
- condition: numeric_state
entity_id: sensor.ha_runtime_in_minutes
above: 1
- condition: state
entity_id: binary_sensor.workday_sensor
state: 'on'
action:
- service: script.audio_notify
data_template: >-
{% if states.input_select.work_location == 'Work1' %}
tts_msg: "Work1d on current traffic, you have 10 minutes to leave if you want to get to the work1 by 8:30am. Traffic is {{ states('sensor.me_traffic_density_to_work1') }} today."
{% elif states.input_select.work_location == 'Work2' %}
tts_msg: "Work1d on current traffic, you have 10 minutes to leave if you want to get to khaki by 8:30am. Traffic is {{ states('sensor.me_traffic_density_to_work2') }} today."
{% else %}
tts_msg: "I'm not sure where you're going today"
{% endif %}
mplayer: "main"
Awesome, much cleaner. Yes, basically at midnight they turn false, and then at some point in the morning, based on traffic and time, they turn to true. Iām glad to see Iām getting it ārightā the first time more often.
EDIT: One quick thought/question. When I get home from work, the value is still true. If I change my work location/input select, to where Iām working the next day, it would trigger wouldnt it. Might need to adjust my sensor to turn back to false earlier.
Edit2: Added this condition, which puts the time past midnight, where the sensor would be false. Basically an easy way to ensure it only runs once a day.
A template trigger will only āfireā when it goes from False to True. It wonāt trigger, even if a referenced entity changes, if it goes from True to True. So, when you change the input_select, if the overall expression is still True, it wonāt trigger. And if it goes to False, then obviously it wonāt trigger either. It has to go to False and then back to True to trigger again.
Wouldnāt changing the input select change it from FALSE to TRUE? The sensor would be true, but the input select would be false for one for the other trigger. At any given time only one of the conditions can be true, but both the sensors would be true.
Edit: Nevermind I get it. There is only One Trigger. Itās true if either one is true, and only false when both are false.
What am I doing wrong here. Error Invalid config for [automation]: expected a dictionary for dictionary value
action:
- service: script.audio_notify
data_template: >-
{% if states.input_select.work_location == 'Work1' %}
tts_msg: "Work1d on current traffic, you have 10 minutes to leave if you want to get to the work1 by 8:30am. Traffic is {{ states('sensor.me_traffic_density_to_work1') }} today."
{% elif states.input_select.work_location == 'Work2' %}
tts_msg: "Work1d on current traffic, you have 10 minutes to leave if you want to get to khaki by 8:30am. Traffic is {{ states('sensor.me_traffic_density_to_work2') }} today."
{% else %}
tts_msg: "I'm not sure where you're going today"
{% endif %}
mplayer: "main"
here is an example if a working action
- service: script.audio_notify
data_template:
tts_msg: "Based on current traffic, you have 10 minutes to leave if you want to get to work by 8:30am. Traffic is {{ states('sensor.me_traffic_density_to_work') }} today."
mplayer: "main"
Still getting this, Iām sure its a typo, but cannot see it
Invalid config for [automation]: expected a dictionary for dictionary value @ data[āactionā][0][ādata_templateā]. Got None.
it passes as a valid template in the template section of the UI
- service: script.audio_notify
data_template: >-
{% if states.input_select.work_location == 'work' %}
tts_msg: "Based on current traffic, you have 10 minutes to leave if you want to get to the work by 8:30am. Traffic is {{ states('sensor.pauls_traffic_density_to_work') }} today."
{% elif states.input_select.work_location == 'Work2' %}
tts_msg: "Based on current traffic, you have 10 minutes to leave if you want to get to Work2by 8:30am. Traffic is {{ states('sensor.pauls_traffic_density_to_work2') }} today."
{% else %}
tts_msg: "I'm not sure where you're going today"
{% endif %}
mplayer: "main"
Oh, sorry, I missed another problem. You canāt define YAML parameters conditionally using templates. Templates can only be inside yaml parameters. So:
- service: script.audio_notify
data_template:
tts_msg: >-
{% if states.input_select.work_location == 'Base' %}
Based on current traffic, you have 10 minutes to leave if you want to get to the Navy Base by 8:30am. Traffic is {{ states('sensor.pauls_traffic_density_to_base') }} today.
{% elif states.input_select.work_location == 'CACI' %}
Based on current traffic, you have 10 minutes to leave if you want to get to khaki by 8:30am. Traffic is {{ states('sensor.pauls_traffic_density_to_caci') }} today.
{% else %}
I'm not sure where you're going today
{% endif %}
mplayer: "main"
Well that helped the automation to be valid. This morning it triggered, but it said āIām not sure where youāre going todayā. Iām 100% sure that the input select is correct, is my if else logic wrong??
Um, ok, thatās another problem I didnāt notice. Try this:
- service: script.audio_notify
data_template:
tts_msg: >-
{% if states('input_select.work_location') == 'Base' %}
Based on current traffic, you have 10 minutes to leave if you want to get to the Navy Base by 8:30am. Traffic is {{ states('sensor.pauls_traffic_density_to_base') }} today.
{% elif states('input_select.work_location') == 'CACI' %}
Based on current traffic, you have 10 minutes to leave if you want to get to khaki by 8:30am. Traffic is {{ states('sensor.pauls_traffic_density_to_caci') }} today.
{% else %}
I'm not sure where you're going today
{% endif %}
mplayer: "main"