I use this to trun on my coffee machine via a Zigbee fingerbot 5 minutes before my alarm goes off on my Sonos speaker (via a different automation). The on-off switch is a helper and checks to see if coffee had been requested and is reset at the end of the automation. An input_datetime helper called ‘alarm_clock’ that stores the target alarm time
alias: Alarm Coffee
description: Turns on coffee machine 5 minutes before the alarm goes off
trigger:
- platform: template
value_template: |-
{{ states('input_datetime.alarm_clock')[:-3] ==
(now() + timedelta(minutes=5)).strftime('%H:%M') }}
condition:
- condition: state
entity_id: input_boolean.alarm_coffee
state: "on"
action:
- service: notify.persistent_notification
data:
message: >-
"Alarm clock is approaching! Triggering action in 5 minutes. Alarm Time:
{{ states('input_datetime.alarm_clock') | regex_replace('T', ' ') |
regex_replace('\....$', '') }}, Now: {{ now().strftime('%H:%M:%S') }}"
- type: toggle
device_id: b48faec2d4b298702039a7fddef32fb1
entity_id: 56fa9a8aea5a92cbf84940f5f6ba697a
domain: switch
- service: input_boolean.turn_off
target:
entity_id: input_boolean.alarm_coffee
data: {}
mode: single