Ok here we go. Perhaps it has gotten way to complicated but this is my result after HOURS and HOURS of trial and error ( with a lot of help from the experts on this forum) and it seems to do the job pretty well
Sensors:
- platform: template
sensors:
alarmtime:
friendly_name: Wakeup Time
entity_id:
- input_slider.alarm_hour
- input_slider.alarm_minutes
value_template: '{{ "%0.02d:%0.02d" | format(states("input_slider.alarm_hour") | int, states("input_slider.alarm_minutes") | int) }}'
nextalarm:
friendly_name: Seconds untill next alarm
entity_id:
- input_slider.alarm_hour
- input_slider.alarm_minutes
value_template: >
{% set relative_time = (states.input_slider.alarm_hour.state|float|multiply(60) + states.input_slider.alarm_minutes.state|float) - (now().hour|float|multiply(60) + now().minute) %}
{%- if relative_time < 0 -%}
{{23*60+relative_time}}
{%- else -%}
{{ relative_time-60}}
{%- endif %}
time_until_alarm:
friendly_name: Time untill next alarm
entity_id:
- sensor.nextalarm
value_template: '{{ (states.sensor.nextalarm.state.split(" ")[0] | int *60 ) | timestamp_custom("%H:%M") }}'
Automation for wakeup light with radio:
- alias: 'Wakeup Light with Radio'
trigger:
platform: time
minutes: '/5'
seconds: '0'
condition:
condition: and
conditions:
- condition: template
value_template: '{{ ((now().strftime("%s") | int + 1200) | timestamp_custom("%H:%M")) == states.sensor.alarmtime.state }}'
- condition: state
entity_id: input_boolean.alarm_clock
state: 'on'
action:
- service: light.turn_on
data:
entity_id: light.bed_room
brightness: 255
rgb_color: [255,255,255]
transition: 1200
- service: media_player.play_media
data_template:
entity_id: media_player.bed_room
media_content_id: >
{% if is_state("input_select.radio_wakeup", "Radio 538") %} http://vip-icecast.538.lw.triple-it.nl:80/RADIO538_MP3
{% elif is_state("input_select.radio_wakeup", "Q-Music") %} http://icecast-qmusic.cdp.triple-it.nl/Qmusic_nl_live_96.mp3
{% elif is_state("input_select.radio_wakeup", "3FM") %} http://icecast.omroep.nl/3fm-bb-mp3
{% elif is_state("input_select.radio_wakeup", "100% NL") %} http://stream.100p.nl/100pctnl.mp3
{% elif is_state("input_select.radio_wakeup", "Veronica") %} http://8543.live.streamtheworld.com/VERONICACMP3
{% elif is_state("input_select.radio_wakeup", "Sky Radio") %} http://8623.live.streamtheworld.com:80/SKYRADIOAAC_SC
{% elif is_state("input_select.radio_wakeup", "Arrow Classic Rock") %} http://91.221.151.155/listen.mp3
{% elif is_state("input_select.radio_wakeup", "Classic FM") %} http://19143.live.streamtheworld.com/CLASSICFM_SC
{% elif is_state("input_select.radio_wakeup", "BNR Nieuwsradio") %} http://icecast-bnr.cdp.triple-it.nl/bnr_mp3_96_03
{% endif %}
media_content_type: 'audio/mp4'
- service: media_player.volume_set
data:
entity_id: media_player.bed_room
volume_level: '0.01'
- delay: '00:02:00'
- service: media_player.volume_set
data:
entity_id: media_player.bed_room
volume_level: '0.05'
- delay: '00:02:00'
- service: media_player.volume_set
data:
entity_id: media_player.bed_room
volume_level: '0.10'
- delay: '00:01:30'
- service: media_player.volume_set
data:
entity_id: media_player.bed_room
volume_level: '0.15'
- delay: '00:01:30'
- service: media_player.volume_set
data:
entity_id: media_player.bed_room
volume_level: '0.20'
- delay: '00:01:30'
- service: media_player.volume_set
data:
entity_id: media_player.bed_room
volume_level: '0.25'
- delay: '00:01:00'
- service: media_player.volume_set
data:
entity_id: media_player.bed_room
volume_level: '0.30'
- delay: '00:01:00'
- service: media_player.volume_set
data:
entity_id: media_player.bed_room
volume_level: '0.35'
- delay: '00:01:00'
- service: media_player.volume_set
data:
entity_id: media_player.bed_room
volume_level: '0.40'
- delay: '00:01:00'
- service: media_player.volume_set
data:
entity_id: media_player.bed_room
volume_level: '0.45'
- delay: '00:01:00'
- service: media_player.volume_set
data:
entity_id: media_player.bed_room
volume_level: '0.50'
- delay: '00:01:00'
- service: media_player.volume_set
data:
entity_id: media_player.bed_room
volume_level: '0.55'
- delay: '00:00:45'
- service: media_player.volume_set
data:
entity_id: media_player.bed_room
volume_level: '0.60'
- delay: '00:00:45'
- service: media_player.volume_set
data:
entity_id: media_player.bed_room
volume_level: '0.65'
- delay: '00:00:45'
- service: media_player.volume_set
data:
entity_id: media_player.bed_room
volume_level: '0.70'
- delay: '00:02:00'
- service: light.turn_on
data:
entity_id: light.hall_way
brightness: 125
- service: light.turn_on
data:
entity_id: light.diner_table
brightness: 125
- service: light.turn_on
data:
entity_id: light.living_room
brightness: 140
- service: media_player.volume_set
data:
entity_id: media_player.ca_bathroom
volume_level: '0.40'
- delay: '00:00:10'
- service: media_player.volume_set
data:
entity_id: media_player.ca_bathroom
volume_level: '0.40'
- service: media_player.play_media
data_template:
entity_id: media_player.ca_bathroom
media_content_id: >
{% if is_state("input_select.radio_wakeup", "Radio 538") %} http://vip-icecast.538.lw.triple-it.nl:80/RADIO538_MP3
{% elif is_state("input_select.radio_wakeup", "Q-Music") %} http://icecast-qmusic.cdp.triple-it.nl/Qmusic_nl_live_96.mp3
{% elif is_state("input_select.radio_wakeup", "3FM") %} http://icecast.omroep.nl/3fm-bb-mp3
{% elif is_state("input_select.radio_wakeup", "100% NL") %} http://stream.100p.nl/100pctnl.mp3
{% elif is_state("input_select.radio_wakeup", "Veronica") %} http://8543.live.streamtheworld.com/VERONICACMP3
{% elif is_state("input_select.radio_wakeup", "Sky Radio") %} http://8623.live.streamtheworld.com:80/SKYRADIOAAC_SC
{% elif is_state("input_select.radio_wakeup", "Arrow Classic Rock") %} http://91.221.151.155/listen.mp3
{% elif is_state("input_select.radio_wakeup", "Classic FM") %} http://19143.live.streamtheworld.com/CLASSICFM_SC
{% elif is_state("input_select.radio_wakeup", "BNR Nieuwsradio") %} http://icecast-bnr.cdp.triple-it.nl/bnr_mp3_96_03
{% endif %}
media_content_type: 'audio/mp4'
- service: homeassistant.turn_off
data:
entity_id: input_boolean.alarm_clock
Automations for changing alarm time triggered through MQTT, sent through Tasker:
- alias: Set alarmtime_hour
trigger:
platform: mqtt
topic: "setHour"
action:
service: input_slider.select_value
data_template:
entity_id: input_slider.alarm_hour
value: '{{ trigger.payload}}'
- alias: Set alarmtime_minutes
trigger:
platform: mqtt
topic: "setMinutes"
action:
service: input_slider.select_value
data_template:
entity_id: input_slider.alarm_minutes
value: '{{ trigger.payload}}'
Script for executing lullaby and gently decreasing volume over 30 mins:
sleep:
alias: Good Night
sequence:
- alias: Set Volume
service: media_player.volume_set
data:
entity_id: media_player.bed_room
volume_level: '1.0'
- alias: Say Sleep Left
service: tts.google_say
entity_id: media_player.bed_room
data_template:
message: 'Next alarm in {{ (states.sensor.nextalarm.state.split(" ")[0] | int *60 ) | timestamp_custom("%H") | int }} hours and {{ (states.sensor.nextalarm.state.split(" ")[0] | int *60 ) | timestamp_custom("%M") }} minutes . Good night.'
cache: false
- delay: '00:00:15'
- alias: Set Volume2
service: media_player.volume_set
data:
entity_id: media_player.bed_room
volume_level: '0.75'
- condition: state
entity_id: input_boolean.lullaby
state: 'on'
- service: media_player.play_media
entity_id: media_player.bed_room
data_template:
entity_id: media_player.bed_room
media_content_id: >
{% if is_state("input_select.lullaby", "Sleep Radio") %} http://37.59.28.208:8722/stream
{% elif is_state("input_select.lullaby", "Ambient Sleeping Pill") %} http://perseus.shoutca.st:8447/h
{% elif is_state("input_select.lullaby", "Radio Art - Sleep") %} http://live.radioart.com/fSleep.mp3
{% elif is_state("input_select.lullaby", "Ambi Nature Radio") %} http://94.23.252.14:8067/stream
{% elif is_state("input_select.lullaby", "Calm Radio - Sleep") %} http://streams.calmradio.com/api/39/128/stream
{% endif %}
media_content_type: 'audio/mp4'
- delay: '00:05:00'
- service: media_player.volume_set
data:
entity_id: media_player.bed_room
volume_level: '0.70'
- delay: '00:02:30'
- service: media_player.volume_set
data:
entity_id: media_player.bed_room
volume_level: '0.65'
- delay: '00:02:30'
- service: media_player.volume_set
data:
entity_id: media_player.bed_room
volume_level: '0.60'
- delay: '00:05:00'
- service: media_player.volume_set
data:
entity_id: media_player.bed_room
volume_level: '0.55'
- delay: '00:02:30'
- service: media_player.volume_set
data:
entity_id: media_player.bed_room
volume_level: '0.50'
- delay: '00:02:30'
- service: media_player.volume_set
data:
entity_id: media_player.bed_room
volume_level: '0.45'
- delay: '00:05:00'
- service: media_player.volume_set
data:
entity_id: media_player.bed_room
volume_level: '0.40'
- delay: '00:02:30'
- service: media_player.volume_set
data:
entity_id: media_player.bed_room
volume_level: '0.35'
- delay: '00:02:30'
- service: media_player.volume_set
data:
entity_id: media_player.bed_room
volume_level: '0.30'
- delay: '00:05:00'
- service: media_player.volume_set
data:
entity_id: media_player.bed_room
volume_level: '0.25'
Input sliders, selectors and booleans:
input_boolean:
alarm_clock:
name: On/Off
initial: off
icon: mdi:alarm
lullaby:
name: Lullaby On/Off
initial: On
icon: mdi:sleep
input_slider:
alarm_hour:
name: Hour
icon: mdi:timer
initial: 6
min: 0
max: 23
step: 1
alarm_minutes:
name: Minutes
icon: mdi:timer
initial: 35
min: 0
max: 55
step: 5
input_select:
radio_wakeup:
name: Wakeup Radio Station
options:
- Radio 538
- Q-Music
- 3FM
- 100% NL
- Veronica
- Sky Radio
- Arrow Classic Rock
- Classic FM
- BNR Nieuwsradio
initial: Radio 538
icon: mdi:radio
lullaby:
name: Lullaby Radio Station
options:
- Sleep Radio
- Ambient Sleeping Pill
- Radio Art - Sleep
- Ambi Nature Radio
- Calm Radio - Sleep
initial: Ambient Sleeping Pill
icon: mdi:music-circle
Frontend view:
group:
Wake-up Alarm:
name: Wakeup Light with Radio
entities:
- input_boolean.alarm_clock
- sensor.alarmtime
- sensor.time_until_alarm
- input_slider.alarm_hour
- input_slider.alarm_minutes
- input_boolean.lullaby
- input_select.lullaby
- input_select.radio_wakeup