Hey everyone, after an hour of testing, I still can’t get it to work. Can you guys help me?
After the alarm clock is turned off and someone is detected by the motion detector within 1 hour, it should perform something. In the following yaml file, a radio will finally turn on. The light is only for testing.
I think you may be misunderstanding how triggers and conditions work.
The way you have set up your trigger, it will fire when the Local Time attribute of the next alarm sensor has been in a stable state for 1 hour. If you have at least one alarm scheduled every day, and there is more than an hour between your alarms, the trigger will fire 1 hour after your alarm sounds.
Be aware that there is no specific state for the alarm being turned off. The sensor’s state simply changes to the next scheduled time, or to “unavailable” if there isn’t another alarm scheduled. Also, the Local Time attribute does not exist when there isn’t another alarm scheduled. These factors need to be planned for in your trigger.
Conditions do not wait. If the motion sensor is not detecting motion at the moment the trigger fires, the condition will fail and the automation will stop. If you want to allow a timespan in which another event can occur, you need to use a Wait action
alias: Morgenroutine
description: ""
trigger:
- platform: state
entity_id:
- sensor.pixel_6_pro_next_alarm
attribute: Local Time
- platform: state
entity_id:
- sensor.pixel_6_pro_next_alarm
to: unavailable
not_from: unknown
condition: []
action:
- wait_for_trigger:
- platform: state
entity_id: binary_sensor.aqara_bewegungsmelder_esszimmer_occupancy
to: 'on'
timeout: "01:00:00"
continue_on_timeout: false
- type: turn_off
device_id: 2885bce8c9962b2b0dd32b9165d44598
entity_id: light.buro_decke
domain: light
mode: single
If the alarm on the phone is used for more than just a once-a-day/morning alarm, keep in mind that this automation will also be triggered whenever a new alarm is added that is sooner than the existing next alarm. This might not be a problem, but you should consider additional conditions for when you do not want this automation to perform its actions. For example, when specific people are or are not home, certain times of the day or days of the week.