So I’ve implemented @3vasi0n code, as illustrated above, but made a few changes along the way…
I’ve added an additional input_number for alarm clock snooze duration, as well as one for fade in duration. So now I can adjust the snooze duration, and the amount of time it takes for the lights to fade-in.
instead of posting only the changes I’ve made, I found it easier to post the configuration, in it’s entirety
Here’s what it looks like (please note, I’m using a theme, so your colors may be different)
The code:
configuration.yaml:
config: sun: map: ios: push: categories: - name: alarm clock identifier: 'alarmclock' actions: - identifier: 'AWAKE' title: 'Awake' destructive: no - identifier: 'SNOOZE' title: 'Snooze' destructive: yes
input_boolean.yaml:
alarm_clock_status: name: Alarm Clock Status initial: on icon: mdi:alarm
input_number.yaml:
alarm_clock_hour: name: "Hour" icon: mdi:timer min: 0 max: 23 step: 1 mode: slider alarm_clock_minute: name: "Minutes" icon: mdi:timer min: 0 max: 55 step: 5 mode: slider alarm_clock_snooze: name: "Snooze" icon: mdi:alarm-snooze min: 0 max: 30 step: 1 mode: slider morning_lights_fadein: name: "Fade-in Minutes" icon: mdi:lightbulb-on-outline min: 5 max: 30 step: 1 mode: slider initial: 10
sensors.yaml:
- platform: template sensors: alarm_clock_hour: friendly_name: "Alarm Clock Hour" value_template: '{{ states.input_number.alarm_clock_hour.state | int }}' alarm_clock_minute: friendly_name: "Alarm Clock Minute" value_template: '{{ states.input_number.alarm_clock_minute.state | int }}' alarm_clock_snooze: friendly_name: "Alarm Clock Snooze" value_template: '{{ states.input_number.alarm_clock_snooze.state | int }}' alarm_clock_time: friendly_name: "Alarm Clock Time" value_template: >- {{ states.sensor.alarm_clock_hour.state }}: {%- if states.sensor.alarm_clock_minute.state|length == 1 -%} 0 {%- endif -%} {{ states.sensor.alarm_clock_minute.state }} alarm_clock_time_long: friendly_name: "Alarm Clock Time" value_template: >- {%- if states.sensor.alarm_clock_hour.state|length == 1 -%} 0 {%- endif -%} {{ states.sensor.alarm_clock_hour.state }}: {%- if states.sensor.alarm_clock_minute.state|length == 1 -%} 0 {%- endif -%} {{ states.sensor.alarm_clock_minute.state }}
groups.yaml:
alarm_clock: name: Alarm Clock icon: mdi:alarm entities: - input_boolean.alarm_clock_status - sensor.alarm_clock_time - input_number.alarm_clock_hour - input_number.alarm_clock_minute - sensor.alarm_clock_snooze - input_number.alarm_clock_snooze - sensor.morning_lights_fadein - input_number.morning_lights_fadein
automations.yaml:
# Alarm Clock - id: alarm_clock_activated alias: Alarm Clock Activated hide_entity: False trigger: - platform: template value_template: '{{ states.sensor.time.state == states.sensor.alarm_clock_time_long.state }}' condition: condition: and conditions: - condition: state entity_id: input_boolean.alarm_clock_status state: 'on' - condition: state entity_id: group.presence state: 'home' action: - service: script.turn_on # iOS Push Notification entity_id: script.alarm_clock_awake_pushed # I entirely removed the "Alarm Clock Awake Pushed" automation, because if I clicked "Awake", it just dismissed the notification, and I didn't need to perform an action based on this (I was awake, the lights were already on). # Alarm Clock Snooze Pushed - id: alarm_clock_snooze_action alias: alarm clock snooze action initial_state: true hide_entity: true trigger: - platform: event event_type: ios.notification_action_fired event_data: actionName: SNOOZE action: service: script.turn_on entity_id: script.alarm_clock_snooze_button
scripts.yaml:
(Please keep in mind, I’ve done a lot of customization here, specific to my setup, your data_template will, and should be very different; I always try and account for every possible situation, weekdays, weekends, holidays, etc.)
#Awake alarm_clock_awake_pushed: alias: 'Alarm Clock Awake' sequence: - service: script.turn_on data_template: entity_id: >- {%- if states.binary_sensor.workday_sensor.state == 'on' and states.input_boolean.vacation.state == 'off' and states.input_boolean.company.state == 'off' and states.calendar.holidays_in_united_states.state == 'off' and states.calendar.work.state == 'off' -%} script.morning_lights_weekday {%- elif states.binary_sensor.workday_sensor.state == 'on' and states.input_boolean.vacation.state == 'off' and states.input_boolean.company.state == 'off' and states.calendar.holidays_in_united_states.state == 'on' and states.calendar.work.state == 'off' -%} script.morning_lights_weekend {%- elif states.binary_sensor.workday_sensor.state == 'on' and states.input_boolean.vacation.state == 'off' and states.input_boolean.company.state == 'off' and states.calendar.holidays_in_united_states.state == 'off' and states.calendar.work.state == 'on' -%} script.morning_lights_weekend {%- elif states.binary_sensor.workday_sensor.state == 'off' and states.input_boolean.vacation.state == 'off' and states.input_boolean.company.state == 'off' and states.calendar.holidays_in_united_states.state == 'off' and states.calendar.work.state == 'off' -%} script.morning_lights_weekend {%- else -%} script.morning_lights_weekend {%- endif -%} - service: notify.ios_jon_iphone data: title: "Alarm Clock" message: "Time To Wake Up!" data: push: sound: "US-EN-Alexa-Good-Morning.wav" badge: 0 category: alarmclock # Alarm Clock Snooze Button -> Timer alarm_clock_snooze_button: alias: 'Alarm Clock Snooze Button' sequence: - service: light.turn_off data: entity_id: group.bedroom_lights - service: switch.turn_off entity_id: switch.n7x1_screen - service: switch.turn_off entity_id: switch.n7x2_screen - service: light.turn_off data: entity_id: light.hall_light - service: light.turn_off data: entity_id: light.bathroom_light - service: light.turn_off data: entity_id: group.kitchen_lights - service: script.turn_off data_template: entity_id: >- {%- if states.binary_sensor.workday_sensor.state == 'on' and states.input_boolean.vacation.state == 'off' and states.input_boolean.company.state == 'off' and states.calendar.holidays_in_united_states.state == 'off' and states.calendar.work.state == 'off' -%} script.morning_lights_weekday {%- elif states.binary_sensor.workday_sensor.state == 'on' and states.input_boolean.vacation.state == 'off' and states.input_boolean.company.state == 'off' and states.calendar.holidays_in_united_states.state == 'on' and states.calendar.work.state == 'off' -%} script.morning_lights_weekend {%- elif states.binary_sensor.workday_sensor.state == 'on' and states.input_boolean.vacation.state == 'off' and states.input_boolean.company.state == 'off' and states.calendar.holidays_in_united_states.state == 'off' and states.calendar.work.state == 'on' -%} script.morning_lights_weekend {%- elif states.binary_sensor.workday_sensor.state == 'off' and states.input_boolean.vacation.state == 'off' and states.input_boolean.company.state == 'off' and states.calendar.holidays_in_united_states.state == 'off' and states.calendar.work.state == 'off' -%} script.morning_lights_weekend {%- else -%} script.morning_lights_weekend {%- endif -%} - service: script.turn_on data: entity_id: script.alarm_clock_snooze_timer # Alarm Clock Snooze Timer alarm_clock_snooze_timer: alias: 'Alarm Clock Snooze Timer' sequence: - delay: '{{ (states.sensor.alarm_clock_snooze.state | int * 60 ) }}' - service: automation.trigger data: entity_id: automation.alarm_clock_activated # Morning Lights Weekday morning_lights_weekday: alias: 'Morning Lights Weekday' sequence: - service: light.turn_on data: entity_id: group.bedroom_lights brightness: 1 color_temp: 358 - delay: seconds: 1 - service: light.turn_on data_template: entity_id: group.bedroom_lights brightness: 100 transition: > {{ states.input_number.morning_lights_fadein.state | int * 60 }} - service: switch.turn_on entity_id: switch.n7x1_screen - service: switch.turn_on entity_id: switch.n7x2_screen ... # Morning Lights Weekend morning_lights_weekend: alias: 'Morning Lights Weekend' sequence: - service: light.turn_on data: entity_id: group.bedroom_lights brightness: 1 color_temp: 358 - delay: seconds: 1 - service: light.turn_on data_template: entity_id: group.bedroom_lights brightness: 100 transition: > {{ states.input_number.morning_lights_fadein.state | int * 60 }} - service: switch.turn_on entity_id: switch.n7x1_screen - service: switch.turn_on entity_id: switch.n7x2_screen ...
Logic:
(fairly complicated, but works wonderfully)
If the alarm clock is ON, when the current time matches that of the alarm clock time, the following happens:
- Push notification to phone, with Alexa voice saying “Good Morning”
- Lights begin to fade in (for fade-in duration)
a. Depending on the day
b. Fire the following script (one or the other, not both):- morning_lights_weekend
- morning_lights_weekday
- Awake button - Simply dismisses the notification
- Snooze button - Perform the following:
- Snoozes for the alarm_clock_snooze duration
a. Turns off any and all lights, or screens that were turned on previously
b. Sleep for additional alarm_clock_snooze duration! - Cycle starts over…
Please let me know if anything doesn’t make sense, I accidentally left something out, or you’d like some more details, or clarification. Credit for the alarm clock should go to @3vasi0n, all I did was tweak it a little for my setup.
If anyone’s interested in how I’m controlling the tablet screens, please check out my other post