Hello all
This might not seem very advanced, yet quite neat. With inspiration from this post about creating a Sonos alarm with Philips HUE light dimming
I figured out, that more important than the dimming functionality, I really wanted to be able to control the Sonos alarm with a physical button when it was live. I had a bunch og Phillips HUE dimmer switches lying around, so aimed for these. To save you all from figuring out youselves, I am therefore posting my code for
- Turn up the volume
- turn down the volume
- Snooze the alarm (practically pause and continue after a defined amount of time)
- turn of the alarm - and read out the weather forecast.
My dimmer switch is set up as a sensor “sensor.sovevrelse_switch” and basically the 4 below automations perform:
(the “Klik” numbers corresponds to the button numbers on the remote in HA)
“klik 4” : call script to turn off the alarm
“klik 3” : call script to turn down volume
“klik 2” : call script to turn up volume
“klik 1” : Call script to snooze for X minutes
Automations.yaml
- id: Soveværelse remote klik 4
alias: Soveværelse remote klik 4
trigger:
- platform: state
entity_id: sensor.sovevrelse_switch
to: ‘4_click’
action:
- service: script.sovevrelse_sluk_alarm
entity_id: media_player.sovevrelse_2
#-----------------------------------------------------------------------------------------------------------------
- id: Soveværelse remote klik 2
alias: Soveværelse remote klik 2
trigger:
- platform: state
entity_id: sensor.sovevrelse_switch
to: '2_click'
action:
- service: script.sovevrelse_skru_op
entity_id: media_player.sovevrelse_2
#-----------------------------------------------------------------------------------------------------------------
- id: Soveværelse remote klik 3
alias: Soveværelse remote klik 3
trigger:
- platform: state
entity_id: sensor.sovevrelse_switch
to: '3_click'
action:
- service: script.sovevrelse_skru_ned
entity_id: media_player.sovevrelse_2
#-----------------------------------------------------------------------------------------------------------------
- id: Soveværelse remote klik 1
alias: Soveværelse remote klik 1
trigger:
- platform: state
entity_id: sensor.sovevrelse_switch
to: '1_click'
action:
- service: script.sovevrelse_snooze
entity_id: media_player.sovevrelse_2
#-----------------------------------------------------------------------------------------------------------------
Scripts.yaml
#-----------------------------------------------------------------------------------------------------------------
sovevrelse_snooze:
alias: "sovevrelse_snooze"
sequence:
- service: media_player.media_play_pause
data:
entity_id: "media_player.sovevrelse_2"
- delay: '00:10:00'
- service: media_player.media_play_pause
data_template:
entity_id: "media_player.sovevrelse_2"
#-----------------------------------------------------------------------------------------------------------------
sovevrelse_skru_op:
alias: "sovevrelse_skru_op"
sequence:
- service: media_player.volume_set
entity_id: media_player.sovevrelse_2
data_template:
volume_level: '{{ states.media_player.sovevrelse_2.attributes.volume_level + 0.05 }}'
#-----------------------------------------------------------------------------------------------------------------
sovevrelse_skru_ned:
alias: "sovevrelse_skru_ned"
sequence:
- service: media_player.volume_set
entity_id: media_player.sovevrelse_2
data_template:
volume_level: '{{ states.media_player.sovevrelse_2.attributes.volume_level - 0.05 }}'
#-----------------------------------------------------------------------------------------------------------------
sovevrelse_sluk_alarm:
alias: "sovevrelse_sluk_alarm"
sequence:
- service: media_player.sonos_snapshot
data_template:
entity_id: "media_player.sovevrelse_2"
- service: tts.google_say
data_template:
entity_id: "media_player.sovevrelse_2"
message: Goodmorning Michael, the alarm has been turned off for today. The weatherforecast for today is - {{states ('sensor.dark_sky_hourly_summary')}}. Hight temperature {{states ('sensor.dark_sky_daily_high_temperature_0') | int}} degrees, low temperature {{states ('sensor.dark_sky_daily_low_temperature_0') | int}} degrees
- delay: '00:00:16'
- service: media_player.sonos_restore
data_template:
entity_id: "media_player.sovevrelse_2"
- delay: '00:00:02'
- service: media_player.media_play_pause
data_template:
entity_id: "media_player.sovevrelse_2"
#-----------------------------------------------------------------------------------------------------------------
Maybe you can use it.
/Michael.