Hi, I’m trying to create an automation that will run between 12:30am and 3:30am to turn off the TV if it’s already on or has been turned on during that time and if motion has not been detected for the past 30 mins. It will then send an announcement that the TV will turn off and if motion is detected within 15 mins, action will be canceled. I want it to continue to check for these conditions until the end time in case some turns the TV back on again.
Currently I have the code below. I tried to have it trigger between a certain time but can’t seem to figure it out so I’m having it check every half an hour.
I’m fairly new myself, but I don’t think that will ever work, if it were me, I would trigger of the motion sensor being no movement and then check to see if the time condition. Does the TV need to be checked to be on to turn it off, just turn it off (unless you can only toggle the power state)
I would consider something like this as an idea, please dont take this as face value, just to give you an work flow to get to your solution you need.
description: ""
mode: single
trigger:
- platform: state
entity_id:
- binary_sensor.motion_sensor_motion
from: "on"
to: "off"
for:
hours: 0
minutes: 30
seconds: 0
condition:
- condition: time
after: "00:30:00"
before: "03:30:00"
I think the time matters, so be aware that the order is correct. Hope it starts you off, unless someone might come along with some more to add
@Roxy, you’re close. but i think it’d be better with a few tweaks.
personally i’d remove the from: "on" because if it goes from unavailable to off, i’d still want to trigger. if it goes from anything to off for 30 minutes, i’d want to trigger.
in any automation where you want to restrict the timeframe, you almost certainly also then need to add the start of the timeframe as a trigger. remember that triggers happen right when the event happens… so if motion stopped at 23:59, then at 00:29, it would try to trigger. the condition would block it. then it will not trigger at 00:30. ha does not keep re-trying unless the trigger happens again.
so below i added 00:30 as a trigger. but, that means it will try to trigger every 00:30, so that means i need to add the motion state as a condition.
@Rich37804 take a look at the example i posted.
there are a couple issues with what you have.
it is a touch more complicated, and requires a separate timer helper.
theoretically, yours will turn the tv off if motion detection is “on” for 30 minutes straight. practically speaking, unless you’re dancing in your tv room, this probably won’t happen, but it is a logical bug.
typo: you are starting timer.test_timer_2, but checking timer.test_timer:
please avoid using device_id uuid’s when not needed: