Creating a alarm clock

I’m getting a syntax error in the frontend Templates page (and what I mean by that is that the output is blanc instead of “false” or “true”).

I’m new to HA and templating so forgive me if this question is something I should know. But why the – 1200 on the last one and not just -1200

anyone managed to add a “snooze” and “off” function? I’m using mqtt buttons with Wemos D1 and Button Shield and also Amazon Dash buttons for various other automations around the house.

A snooze and off function would be easy with two buttons (one for snooze that stops the script for 5mins and then starts it again using a delay. And off is self explanatory) but really id like one button. Anyone have any thoughts about this?

Cheers!

I’m rather new to HA as well and the double minus is just something I figured should be the syntax since equal also must contain 2 “==” instead of 1.

BTW: single minus isn’t working as well

which media_player?

Chromecast (Google Cast)

In many programming languages, a double equal tests for equality, where a single assigns value - even in an if/then context.

Thanks for the tip :slight_smile:

For those who are interested: this did the trick (triggers my automation 20 minutes before wakeup time)

'{{ ((now().strftime("%s") | int + 1200) | timestamp_custom("%H:%M"))  }} == {{  states.input_select.alarmtime.state  }}'
3 Likes

Nice that you got it to work!
I had a similar problem and solved it a little different:

I created a custom sensor which shows the actual trigger time, i.e. in the example in the link the lights go out x hours after the sunset.
Then I could use the standard compare with this virtual sensor in the automation rule.

If everything seems right then probably your problem is with foreing characters. You should only use the english alphabet in any automation or configuration file. I have ran into this a couple of times, and hass unfortunately does not give any errors just the automation does not trigger. :frowning:
cheers
tom

Thank you all for the examples here, this is great.

Was wondering if someone could post a working trigger that will fire before the alarm time?

I would like to fade in my lights and slowly raise the volume of a radio 15 minutes before what the alarm time is set at in the UI.

I tried last night using the discussion here as a guide but couldn’t get the automation to actually trigger even though double checking my templating in the debug UI appeared like it should have been working.

It works fine using the example code verbatim I just want it to be offset by a few minutes.

Here you go:

- alias: 'Rule 9 - Wakeup Light with Radio'
  trigger:
    platform: time
    minutes: '/5'
    seconds: '0'
  condition:
    condition: and
    conditions:
      - condition: template
        value_template: '{{ ((now().strftime("%s") | int + 900) | 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   

P.S I didn’t post the alarm part because of the long script :slight_smile:

P.S 2: I just asked the same question a couple of days ago and the answer was just 2 posts above your question

Here is mine:

# Wake Monday
  alias: 'WAKE - Monday'
  trigger:
    - platform: template
      value_template: '{{ states.sensor.time.state == states.sensor.sen_at_mon.state }}'

  condition:
  condition: and
  conditions:
    - condition: time
      weekday:
         - mon
    - condition: state
      entity_id: 'sensor.holiday'
      state: '0'
    - condition: state
      entity_id: 'input_boolean.holiday'
      state: 'off'
    - condition: state
      entity_id: 'group.phones'
      state: 'on'
    - condition: template
      value_template: '{{ (states.input_select.ah_mon.state | int) > 0 }}'

  action:
    - service: homeassistant.turn_on
      entity_id: switch.ebredes
   - service: shell_command.ebresztes 

cheers
tom

1 Like

Here is my version… I wanted to set all the days, start and end time.

I didn’t have any coding experience before HA, so I added all my code for my fellow yaml noobs :wink:

ps. just add the times between “02:00” and “22:00”

light:
  platform: hue
  host: 192.168.1.100
  allow_unreachable: true

media_player:
  - platform: sonos

scene:
  - name: Morning
    entities:
      light.bedroom:
        state: on
        brightness: 230
        color_temp: 234
        transition: 30
        rgb_color: [255,231,194]
      light.hall:
        state: on
        brightness: 230
        color_temp: 234
        transition: 30
        rgb_color: [255,231,194]
      light.livingroom:
        state: on
        brightness: 230
        color_temp: 234
        transition: 30
        rgb_color: [255,231,194]
      light.ktichen:
        state: on
        brightness: 230
        color_temp: 234
        transition: 30
        rgb_color: [255,231,194]

### Alarm Clock Input ###

input_boolean:    
  monday:
    name: Monday
    initial: on
  tuesday:
    name: Tuesday
    initial: on
  wednesday:
    name: Wednesday
    initial: on
  thursday:
    name: Thursday
    initial: on
  friday:
    name: Friday
    initial: on
  saturday:
    name: Saturday
    initial: off
  sunday:
    name: Sunday
    initial: off

input_select:
  alarmclock_on:
    name: Alarm Clock On
    icon: mdi:alarm
    initial: "07:00"
    options:
      - "00:00"
      - "00:15"
      - "00:30"
      - "00:45"
      - "01:00"
      - "01:15"
      - "01:30"
      - "01:45"
      - "02:00"
      ....
      - "22:00"
      - "22:15"
      - "22:30"
      - "22:45"
      - "23:00"
      - "23:15"
      - "23:30"
      - "23:45"

  alarmclock_off:
    name: Alarm Clock Off
    icon: mdi:alarm
    initial: "08:30"
    options:
      - "00:00"
      - "00:15"
      - "00:30"
      - "00:45"
      - "01:00"
      - "01:15"
      - "01:30"
      - "01:45"
      - "02:00"
      ....
      - "22:00"
      - "22:15"
      - "22:30"
      - "22:45"
      - "23:00"
      - "23:15"
      - "23:30"
      - "23:45"


### Alarm Clock Automation ###

automation alarmclock:
  - alias: "Automation Alarm Clock On"
    trigger:
      platform: time
      minutes: '/15'
      seconds: 00
    condition:
      condition: and
      conditions:
      - condition: template
        value_template: '{{ now().strftime("%H:%M") == states.input_select.alarmclock_on.state }}'
      - condition: or
        conditions:
        # Monday
        - condition: and
          conditions:
          - condition: time
            weekday:
              - mon
          - condition: state
            entity_id: input_boolean.monday
            state: 'on'
        # Tuesday
        - condition: and
          conditions:
          - condition: time
            weekday:
              - tue
          - condition: state
            entity_id: input_boolean.tuesday
            state: 'on'
        # Wednesday
        - condition: and
          conditions:
          - condition: time
            weekday:
              - wed
          - condition: state
            entity_id: input_boolean.wednesday
            state: 'on'           
        # Thursday
        - condition: and
          conditions:
          - condition: time
            weekday:
              - thu
          - condition: state
            entity_id: input_boolean.thursday
            state: 'on'                 
        # Friday
        - condition: and
          conditions:
          - condition: time
            weekday:
              - fri
          - condition: state
            entity_id: input_boolean.friday
            state: 'on'              
        # Saturday
        - condition: and
          conditions:
          - condition: time
            weekday:
              - sat
          - condition: state
            entity_id: input_boolean.saturday
            state: 'on'             
        # Sunday
        - condition: and
          conditions:
          - condition: time
            weekday:
              - sun
          - condition: state
            entity_id: input_boolean.sunday
            state: 'on' 
    action:
      - service: scene.turn_on
        entity_id: scene.morning
      - service: media_player.volume_set
        data_template:
          entity_id: group.sonos
          volume_level: 0.08     
      - service: media_player.play_media
        data_template:
          entity_id: group.sonos
          media_content_id: x-rincon-mp3radio://vip-icecast.538.lw.triple-it.nl/RADIO538_MP3
          media_content_type: music
       

    
  - alias: "Automation Alarm Clock Off"
    trigger:
      platform: time
      minutes: '/15'
      seconds: 00
    condition:
      condition: and
      conditions:
      - condition: template
        value_template: '{{ now().strftime("%H:%M") == states.input_select.alarmclock_off.state }}'
      - condition: or
        conditions:
        # Monday
        - condition: and
          conditions:
          - condition: time
            weekday:
              - mon
          - condition: state
            entity_id: input_boolean.monday
            state: 'on'
        # Tuesday
        - condition: and
          conditions:
          - condition: time
            weekday:
              - tue
          - condition: state
            entity_id: input_boolean.tuesday
            state: 'on'
        # Wednesday
        - condition: and
          conditions:
          - condition: time
            weekday:
              - wed
          - condition: state
            entity_id: input_boolean.wednesday
            state: 'on'           
        # Thursday
        - condition: and
          conditions:
          - condition: time
            weekday:
              - thu
          - condition: state
            entity_id: input_boolean.thursday
            state: 'on'                 
        # Friday
        - condition: and
          conditions:
          - condition: time
            weekday:
              - fri
          - condition: state
            entity_id: input_boolean.friday
            state: 'on'              
        # Saturday
        - condition: and
          conditions:
          - condition: time
            weekday:
              - sat
          - condition: state
            entity_id: input_boolean.saturday
            state: 'on'             
        # Sunday
        - condition: and
          conditions:
          - condition: time
            weekday:
              - sun
          - condition: state
            entity_id: input_boolean.sunday
            state: 'on' 
    action:
      - service: light.turn_off
        entity_id: group.all_lights
      - service: media_player.media_pause
        data_template:
          entity_id: group.sonos  

1 Like

Many thanks to this thread, I have been using my alarm clock for several weeks and love it. Mine slowly fades in lights and music (selection made by calling a MPD playlist of radio streams) and starts a pot of coffee (the recent WeMo coffee maker addition).

very nice. very nice. add it to the projects section so others can learn from it.

Mine is similar to the others here except that I use sliders to set the start and finish times…

If anyone wants to see the code I’ll post it here :slight_smile:

mine reads the google calendar, looks for a meeting called “wakeup” and goes off at that time.

Can you share your config for that?