From 67e33f1723d11f5ca028a37ddff1c1cd4e935062 Mon Sep 17 00:00:00 2001 From: Julian Tabel Date: Sun, 26 Jul 2026 16:04:23 +0200 Subject: [PATCH] Split wake-up automation around restart-proof awake flag Replace the monolithic Sleep Tracking Stopped automation with an input_boolean.awake flag plus input_datetime.woke_up timestamp. Bedroom light and bathroom music trigger on the flag, music now runs weekdays only, and the 45-minute music stop uses a template trigger against the stored timestamp instead of a delay so it survives Home Assistant restarts. Co-Authored-By: Claude Fable 5 --- automations.yaml | 124 +++++++++++++++++++++++++++++++++---------- packages/wakeup.yaml | 11 ++++ 2 files changed, 108 insertions(+), 27 deletions(-) create mode 100644 packages/wakeup.yaml diff --git a/automations.yaml b/automations.yaml index bc1ac81..b94feb7 100644 --- a/automations.yaml +++ b/automations.yaml @@ -297,8 +297,8 @@ data: {} mode: single - id: '1758383701998' - alias: Sleep Tracking Stopped - description: '' + alias: Sleep Tracking Stopped - Set Awake + description: Marks awake and stores the wake-up time; everything else builds on input_boolean.awake triggers: - trigger: state entity_id: @@ -311,6 +311,43 @@ entity_id: person.julian zone: zone.home actions: + - action: input_datetime.set_datetime + target: + entity_id: input_datetime.woke_up + data: + datetime: '{{ now().strftime(''%Y-%m-%d %H:%M:%S'') }}' + - action: input_boolean.turn_on + target: + entity_id: input_boolean.awake + data: {} + mode: single +- id: '1785225600001' + alias: Sleep Tracking Started - Reset Awake + description: '' + triggers: + - trigger: state + entity_id: + - event.sleep_as_android_sleep_tracking_2 + attribute: event_type + to: + - started + conditions: [] + actions: + - action: input_boolean.turn_off + target: + entity_id: input_boolean.awake + data: {} + mode: single +- id: '1785225600002' + alias: Awake - Bedroom Light + description: '' + triggers: + - trigger: state + entity_id: + - input_boolean.awake + to: 'on' + conditions: [] + actions: - action: light.turn_on metadata: {} data: @@ -319,31 +356,64 @@ brightness_pct: 25 target: area_id: bedroom - - sequence: - - action: media_player.shuffle_set - metadata: {} - data: - shuffle: true - target: - entity_id: media_player.speaker_bad_2 - - action: music_assistant.play_media - metadata: {} - data: - enqueue: replace - media_id: - - library://artist/1 - target: - entity_id: media_player.speaker_bad_2 - - delay: - hours: 0 - minutes: 45 - seconds: 0 - milliseconds: 0 - - action: media_player.media_stop - metadata: {} - data: {} - target: - entity_id: media_player.speaker_bad_2 + mode: single +- id: '1785225600003' + alias: Awake - Bathroom Music + description: Weekdays only + triggers: + - trigger: state + entity_id: + - input_boolean.awake + to: 'on' + conditions: + - condition: time + weekday: + - mon + - tue + - wed + - thu + - fri + actions: + - action: media_player.shuffle_set + metadata: {} + data: + shuffle: true + target: + entity_id: media_player.speaker_bad_2 + - action: music_assistant.play_media + metadata: {} + data: + enqueue: replace + media_id: + - library://artist/1 + target: + entity_id: media_player.speaker_bad_2 + mode: single +- id: '1785225600004' + alias: Awake - Stop Bathroom Music + description: Stops the wake-up music 45 minutes after waking; template trigger survives HA restarts + triggers: + - trigger: template + value_template: '{{ is_state(''input_boolean.awake'', ''on'') and state_attr(''input_datetime.woke_up'', + ''timestamp'') is not none and now().timestamp() - state_attr(''input_datetime.woke_up'', + ''timestamp'') > 45 * 60 }}' + conditions: + - condition: time + weekday: + - mon + - tue + - wed + - thu + - fri + - condition: state + entity_id: media_player.speaker_bad_2 + state: playing + actions: + - action: media_player.media_stop + metadata: {} + data: {} + target: + entity_id: media_player.speaker_bad_2 mode: single - id: '1758737029692' alias: Schreibtisch scan Licht diff --git a/packages/wakeup.yaml b/packages/wakeup.yaml new file mode 100644 index 0000000..561fa71 --- /dev/null +++ b/packages/wakeup.yaml @@ -0,0 +1,11 @@ +input_boolean: + awake: + name: Awake + icon: mdi:weather-sunny + +input_datetime: + woke_up: + name: Woke up + has_date: true + has_time: true + icon: mdi:alarm-check