Changing input_number to fixed values

Hey Guys,

i found this thread Alarm Clock with Sonos & Philips Hue - Share your Projects! - Home Assistant Community (home-assistant.io) to combine hue und sonos alarm which works great. The only thing i want to change is that i don’t need to use the sliders (input_numbers). I want fixed values so one alarm + hue wake up routine should turn on at 6:00, another one at 6:30 one at 7:00 and so one.

Each alarm should have an button to turn on.

So i changed the existing code from the thread:

- alias: Set Sonos Alarm
  trigger:
    - platform: state
      entity_id: input_boolean.alarm_clock_status
      to: 'on'
  action:
    service: media_player.sonos_update_alarm
    data_template:
      entity_id: media_player.bedroom
      alarm_id: 4
      time: '{{ states.sensor.alarm_clock_time.state }}'
      enabled: true
- alias: Disable Sonos Alarm
  trigger:
    - platform: state
      entity_id: input_boolean.alarm_clock_status
      to: 'off'
  action:
    service: media_player.sonos_update_alarm
    data_template:
      entity_id: media_player.bedroom
      alarm_id: 4
      enabled: false
- alias: Fade in Lights in Bedroom
  trigger:
    platform: time
    seconds: 00
  condition:
    condition: and
    conditions:
      - condition: state
        entity_id: input_boolean.alarm_clock_status
        state: 'on'
      - condition: template
        value_template: '{{ (utcnow().strftime("%s") | int + states.sensor.alarm_clock_fade_in_minutes.state | int * 60) | timestamp_custom("%H:%M") == states.sensor.alarm_clock_time.state }}'
  action:
    service: script.bedroom_light_fade_in

to:

- alias: Alarm 7:00
  trigger:
  - platform: state
    entity_id: input_boolean.alarm_clock_status_seven
    to: 'on'
  action:
    service: sonos.update_alarm
    data_template:
      entity_id: media_player.bedroom_sonos
      alarm_id: 1
      time: '7:00'
      enabled: true    

- alias: Disable Sonos Alarm 7:00
  trigger:
  - platform: state
    entity_id: input_boolean.alarm_clock_status_seven
    to: 'off'
  action:
    service: sonos.update_alarm
    data_template:
      entity_id: media_player.bedroom_sonos
      alarm_id: 1217
      enabled: false
      
- alias: Fade in Lights in Bedroom 7:00
  trigger:
    platform: time_pattern
    seconds: 0
  condition:
    condition: and
    conditions:
    - condition: state
      entity_id: input_boolean.alarm_clock_status_seven
      state: 'on'
    - condition: time
      weekday:
        - mon
        - tue
        - wed
        - thu
        - fri
    - condition: template
      value_template: '{{ (utcnow().strftime("%s") | int + "10"
        | int * 60) | timestamp_custom("%H:%M") == "7:00"
        }}'
  action:
    service: script.bedroom_light_fade_in_test

I created a new entitiy for the alarm button so there is trigger to set the alarm.
Sonos Alarm works great and will be enabled and disabled.

heres the script which should run after every fade in automation:
The lights turn on when i run this script directly form HA.

bedroom_light_fade_in_test:
  sequence:
  - service: light.turn_on
    data_template:
      entity_id:
      - light.licht_schlafzimmer
      - light.licht_bett
      profile: relax
      transition: '{{ "10" | int * 60 }}'
  - delay: '{{ "00:10:15" }}'
  - delay: 00:10:00
  - service: light.turn_off
    data_template:
      entity_id:
      - light.licht_schlafzimmer
      - light.licht_bett
  mode: single

I think the condition for “Fade in Lights in Bedroom 7:00” is not working ok. I think it is the value template for the time. Anyone can help me to fix that?

Hi,

try “07:00” instead of “7:00” in condition template.

Because I assume your local time is not utc format.

Yeah i probably think this will do the trick.

I tried it wuith “12:15” which worked very well. While testing the automation and the script the lights will go on too.

So i think the lights will work tomorrow too. I will tell you if this worked.

Why not simply:

    trigger:
      - platform: time
        at: "06:50:00"

which is, I think, what you’re trying to do.

Yes i didn’t know this would also work. Seems a little bit easier.
But can i set the same conditions?

so it should look like this:

- alias: Fade in Lights in Bedroom 7:00
    trigger:
      - platform: time
        at: "06:50:00"
  condition:
    condition: and
    conditions:
    - condition: state
      entity_id: input_boolean.alarm_clock_status_seven
      state: 'on'
    - condition: time
      weekday:
        - mon
        - tue
        - wed
        - thu
        - fri
  action:
    service: script.bedroom_light_fade_in_test

will this work? lights should not go on on every day and not when the alarm button is not set to “on”

Yes, I just stripped out your additional conditions where I put [...] for brevity.

You don’t need the condition: and or the following line, as conditions are AND by default. You might also want to look at the workday sensor if you don’t want your lights to come on on a weekday Christmas Day. Once that’s installed, you could reduce this to:

- alias: Fade in Lights in Bedroom 7:00
  trigger:
    - platform: time
      at: "06:50:00"
  condition:
    - condition: state
      entity_id:
        - binary_sensor.workday_sensor
        - input_boolean.alarm_clock_status_seven
      state: 'on'
  action:
    - service: script.bedroom_light_fade_in_test

The condition block makes use of the multiple-entities test in the docs.

Thank you so much. This is definitly easier and works for me. I will see if it also works in the morning because of the 07:00 instead of 7:00.

But i thin my problem ist solved.