Control Sonos alarm with Philips HUE Dimmer

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 :slight_smile:

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

  1. Turn up the volume
  2. turn down the volume
  3. Snooze the alarm (practically pause and continue after a defined amount of time)
  4. 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.

2 Likes

Hi Michael,
This is a brilliant idea, I would love to do the same. But for some reason my Hue Dimmer Switches are not showing up in HA. Did you do anything special to get them visible? I just used the Hue Component from the Integration Page, to expose my Hue devices.

You need to add Robin Cole’s custom component to get the sensors. It works by repeatedly polling the Hue bridge (several times a second), which seems untidy, but it’s the only real option and, surprisingly, doesn’t seem to impact the Hue system or HA too much.

Thanks quentinsf. Found it and installed it. It works.
Now I will try to make the above in Node-Red

Hello Brian

I have actually not done anything to make them visible, other than ofcourse have the discovery feature enabled.
The only thing I have in my configuration.yaml is

  - platform: hue
    ip_address: 192.168.0.99 #- My HUE Bridge address
    token: very-long-number-found-via-the-api

Robin Coles componet sounds promising, and I’ll have a look at that (thanks quentinsf !).

Oh, and ignore the bit in that component’s README about 0.8 being the only stable version. I think everybody is just using the most recent version.