I’m trying to trigger an action if a motion sensor is tripped. But, because I don’t want it to happen more than once, I also want a condition to only trigger it if the same motion sensor previously was off for at least 2h30min.
The problem is when I add that last condition, it never triggers. For testing I have lowered the time in condition: state and increased before: in condition time. If I remove the last condition it works… but is then triggered again if I pass by that motion detector again.
Can I change my condition: state somehow to do this?
- alias: Turn on the radio in the morning
initial_state: True
hide_entity: False
trigger:
platform: state
entity_id: binary_sensor.motion_hall
from: 'off'
to: 'on'
action:
service: media_player.play_media
data:
entity_id: media_player.sony_x77
media_content_id: http://sverigesradio.se/topsy/direkt/207-hi.mp3
media_content_type: 'audio/mp3'
condition:
condition: and
conditions:
- condition: time
after: '06:30:00'
before: '09:00:00'
- condition: template
value_template: '{{ states.media_player.sony_x77 != "playing" }}'
- condition: state
entity_id: binary_sensor.motion_hall
state: 'off'
for:
hours: 2
minutes: 30
I would create a separate input boolean, and control the behavior of that boolean with two other automations. The first one would set the boolean to true after the motion sensor has been off for two and a half hours. The second one would turn it low ten seconds after motion is detected. Then, the condition on your main automation would check this input boolean. There may be more elegant ways to do this, but that’s the best I can think of.
I think it’s actually a little worse than redundant. The boolean won’t go on till 2.5 hours of inactivity, and your condition won’t pass till 2.5 hours after that.
BTW, thank you for posting your full automation- it lets one know that their idea actually worked, and helps anyone who stumbles upon this thread in the future!
Of course, now I understand. It only triggers if input_boolean.motion_hall has been on for 2,5 hours. So it has to be idle for 5 hours. It worked fine because I sleep longer than that
Fixed now. Will edit the post with the automation.