Creating a alarm clock

Yeah, these two lines do show the correct time:
{{ now().strftime("%H:%M") }}
{{ now().strftime("%s") | int | timestamp_utc }}

Edit:
Summing it up again:

1.    '{{ (now().strftime("%s") | int | timestamp_custom("%H:%M %z%Z")) }}'
2.    '{{ (now().strftime("%s") | int | timestamp_local()) }}'
3.    '{{ (now().strftime("%Z") ) }}'
4.    {{ now().strftime("%s") | int | timestamp_utc }}
5.    {{now().strftime("%H:%M")}}
6.    $ TZ='Europe/Stockholm' date //SSH terminal
7.    $ date //SSH terminal

1.    '13:38 +0100CET'
2.    '2017-01-11 13:38:45'
3.    'CET'
4.    2017-01-11 12:38:46
5.    12:38
6.    Wed 11 Jan 12:38:49 CET 2017
7.    Wed 11 Jan 11:38:51 UTC 2017

At least it’s consistent. Apparently, for some reason your homeassistant’s UTC time is off by one hour. This explains the issues you were having. And it’s worthwhile to fix it, since otherwise, as soon as you switch to summer time, your timers will not work anymore at the suspected times but one hour off… But I have no clue what it causing the time shift…

Have you sat the correct time_zone in the config?

Yes:
time_zone: Europe/Stockholm

This did it for me, thanks a lot!

- alias: 'Rule 9 - Wakeup Light'
  trigger:
    platform: time
    minutes: '/5'
    seconds: '0'
  condition:
    - condition: template
      value_template: '{{ (now().strftime("%s") | int | timestamp_custom("%H:%M")) == states.input_select.alarmtime.state  }}'
  action:
    service: light.turn_on
    data:
      entity_id: light.bed_room
      brightness: 255
      rgb_color: [255,255,255]
      transition: 1200          

And now with radio (slowly increasing volume every minute):

- 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 | timestamp_custom("%H:%M")) == states.input_select.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:
        entity_id: media_player.bed_room
        media_content_id: http://vip-icecast.538.lw.triple-it.nl:80/RADIO538_MP3
        media_content_type: 'audio/mp4' 
    - service: media_player.volume_set
      data:
        entity_id: media_player.bed_room
        volume_level: '0.05'
    - delay: '00:01:00'
    - service: media_player.volume_set
      data:
        entity_id: media_player.bed_room
        volume_level: '0.10'
    - delay: '00:01:00'
    - service: media_player.volume_set
      data:
        entity_id: media_player.bed_room
        volume_level: '0.15'
    - delay: '00:01:00'
    - service: media_player.volume_set
      data:
        entity_id: media_player.bed_room
        volume_level: '0.20'
    - delay: '00:01:00'
    - 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:01:00'
    - service: media_player.volume_set
      data:
        entity_id: media_player.bed_room
        volume_level: '0.60'
    - delay: '00:01:00'
    - service: media_player.volume_set
      data:
        entity_id: media_player.bed_room
        volume_level: '0.65'
    - delay: '00:01:00'
    - service: media_player.volume_set
      data:
        entity_id: media_player.bed_room
        volume_level: '0.70'
    - delay: '00:01:00'
    - service: media_player.volume_set
      data:
        entity_id: media_player.bed_room
        volume_level: '0.75'
    - delay: '00:01:00'
    - service: media_player.volume_set
      data:
        entity_id: media_player.bed_room
        volume_level: '0.80'
    - delay: '00:01:00' 
    - service: media_player.volume_set
      data:
        entity_id: media_player.bed_room
        volume_level: '0.85'
    - delay: '00:01:00'
    - service: media_player.volume_set
      data:
        entity_id: media_player.bed_room
        volume_level: '0.90'
    - delay: '00:01:00'
    - service: media_player.volume_set
      data:
        entity_id: media_player.bed_room
        volume_level: '0.95'
    - delay: '00:01:00'     
    - service: media_player.volume_set
      data:
        entity_id: media_player.bed_room
        volume_level: '1.0'
    - delay: '00:01:00'     
1 Like

I’m trying to trigger my alarm clock 20 minutes before wakeup time but don’t succeed with the code. Can someone help me out?

Original code (which triggers perfectly fine at the time I set with the input boolean):

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

Tried several options but none of them are correct:

{{ (now(--'00:20:00').strftime("%s") | int | timestamp_custom("%H:%M")) == states.input_select.alarmtime.state   }}
{{ (now(-1200).strftime("%s") | int | timestamp_custom("%H:%M")) == states.input_select.alarmtime.state   }}
{{ (now().strftime("%s") | int | timestamp_custom("%H:%M")) == states.input_select.alarmtime.state  -- "00:20:00" }}
{{ (now().strftime("%s") | int | timestamp_custom("%H:%M")) == states.input_select.alarmtime.state  -- 1200 }}

Using “00:20” instead of “00:20:00” also doesn’t work.

syntax error or is the alarm going off at the wrong time? Because the calculations on the left side should add 20 minutes to the current time to compare against the time on your input boolean not subtract it.

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.