Trying to figure this out. I have an automation that relies on the condition {{ not is_state('media_player.man_cave_roku_2', 'playing') }} in order words, once the roku goes from ‘playing’ to anything else (idle, paused, etc) then the lights turn off. However, I’d like it to only trip after this has changed for 10 minutes.
Any ideas how I’d do this?
Well the trigger is actually something different - it’s triggered based on the motion sensor and there are multiple conditions which are variations on the condition, so I can’t change it around.
Good call. Here’s what I have so far. Currently it triggers after the motion detector shuts off & the two media players aren’t playing.
I’d like it to wait for the media players to be inactive for at least 10 minutes.
- id: '1508624466805'
alias: Basement Light Off
trigger:
- entity_id: binary_sensor.basement_motion_44
from: 'on'
platform: state
to: 'off'
condition:
- condition: template
value_template: '{{ not is_state(''media_player.man_cave_roku_2'', ''playing'')
}}'
- condition: template
value_template: '{{ not is_state(''media_player.justin_s_ipad'', ''playing'')
}}'
- condition: state
entity_id: binary_sensor.vistacam_700_motion_sensor_18
state: 'off'
action:
- data:
entity_id: light.basement_52
service: light.turn_off
initial_state: true
You triggers wont work as you expect. Say you switch the players off and go upstairs, the motion sensor goes off but the players have not been off for ten minutes. Ten minutes later what is going to trigger the automation?
Maybe this was wishful thinking, but I thought that once the motion detector triggered things off, it would basically “stall” until one of the conditions was met. Is that incorrect?
EDIT: Wow I was way off. ^^ Just tried a simple automation with a couple light switches and, yeah, if the condition isn’t true immediately, it doesn’t wait for it to be true. I have no idea how all my automations work so well, but now I understand why they fail when they do!
Can you explain the nested conditions you have here? Shouldn’t there be something like condition: and in there at some point? Because as I read it now… it says “if any of the 4 following conditions are true”, right? (And in this case a video playing for > 600 seconds would trigger as true even though the state is ‘playing’, right?) I’m still wrapping my head around this stuff, so please don’t interpret this as prying or criticism… just me trying to understand something complex! I appreciate your guidance.
Can you explain the nested conditions you have here? Shouldn’t there be something like condition: and in there at some point? Because as I read it now… it says “if any of the 4 following conditions are true”, right? (And in this case a video playing for > 600 seconds would trigger as true even though the state is ‘playing’, right?) I’m still wrapping my head around this stuff, so please don’t interpret this as prying or criticism… just me trying to understand something complex! I appreciate your guidance.
Conditions are AND by default. All five conditions have to be true for the action to be performed.
Conditions dont trigger automations. Only triggers do. Conditions are applied after the trigger happens. Also there is a condition to check for NOT playing which is ANDed with this time condition.
So only when the motion_44 sensor has been off for 15 minutes will the automation trigger. Then all five conditions are checked and if they are all true the action is performed.
EDIT: Just saw your edit. Yeah automations dont wait for conditions to be true. Trigger → check conditions → if true do actions, else exit.
Another way to do this would be to trigger every minute and check the conditions but that’s pretty wasteful of CPU resources and as it’s not really a time critical automation the 15 minute motion off trigger should do.
Just was thinking about this and I might end up making a separate Automation that is triggered by the media devices which will turn the original automation off (and another for on). It means another automation but would be cleaner looking and less prone to errors, I’d think.