Creating a alarm clock

Shouldn’t “%minutes” be quoted as well?

So:

{"topic":"setMinutes","payload":"%minutes"}

Instead of:

{"topic":"setMinutes","payload":%minutes}

So much work for an alarm clock?

@anon35356645 uhh yeahh well that’s kind of the whole point of Home Automation: spending lots of time configuring to make it easier for yourself at the end…

So, I tried setting up this trigger with MQTT Publisher and I couldn’t get it to work. Every time my task fired I got a message saying that MQTT Publisher crashed and then my server wouldn’t update. So I think I’ll stick with the HTTP Post for now because it’s working pretty well.

No, I don’t think %minutes should be quoted. To me, when you put something in quotes it means to send the string "%minutes" rather than the variable %minutes. In this case, I want to send whatever the value of %minutes is, so I don’t want to put it in quotes. Having it without quotes in my post requests has worked so far.

I personally think that it’s fun to mess with things like this to create something cool in the end, even if it does take a lot of time at first. Also, mine works right now, and I think it’s pretty cool.

1 Like

For iOS users who would like an easier way to set their alarm, I have made a Workflow sequence using the REST API.

https://workflow.is/workflows/23ed6322b7634bd78009849c5e946942

You need to edit it to add your URL and password, and probably change the variable names (this sets values for 2 input sliders - one for the hour, one for the minute).

3 Likes

I’ve made an alarm clock that increases brightness of your lights automatically based on a chosen fade-in time (like phillips wakeup lights):

I’ve been messing around with this clock.
It worked at one point. But now out of nothing it doesn’t anymore.

Problem seems to be that the trigger never gets to be true.

I use the following code as part of the trigger.
value_template: ‘{{ states.sensor.time.state == states.sensor.alarm_time.state}}’

When tested in templates while I now the times should match it still gives out a false result.
Looked at the single parts they both give the same value in that time frame.

What to do?


Found out what was wrong. Alarm Time Hours need to be in 2 digits format.

1 Like

Not sure if anybody here has already published this neat way of zero padding the input_slider values. If not, here you go…

{{ "{:02d}".format(states.input_slider.slider_name.state|int) }}

Applied as a sensor that displays the set hours and minutes on the front end:

sensor:
  set_timer:
          value_template: '{{ "{:02d}".format(states.input_slider.timer_hours_1.state|int) }}:{{ "{:02d}".format(states.input_slider.timer_minutes_1.state|int) }}'
          friendly_name: "Timer"
1 Like

I used this config

But how can i let the alarm go off on my iphone? i cant find it anywhere…

1 Like

I use the alarm clock, but want to use several alarm clocks (one for me and one for each of the kids). How do I get it? Do I have to duplicate the entire code and rename the switches, script, input slider, input bolean … or can I use any of it as it is?
Programming is quite new to me so i need some help …:confused:

Yes, I believe renaming the entities is mandatory, but the good news is: you could automate it !
The template devtool is your friend in your exploratory operations, invaluable in code generation and substitution, every session is bountyful and likely to end with a quick copy and paste.

I need help on identifying why my automation is not running even when the template in the trigger returns true (tested in the Developer Tools).

Sensors:

- platform: template
  sensors:
    alarm_clock_hour:
      value_template: '{{ states.input_slider.alarm_clock_hour.state|int }}'
    alarm_clock_minute:
      value_template: '{{ states.input_slider.alarm_clock_minute.state|int }}'
    alarm_clock_time:
      value_template: >-
        {{ states.sensor.alarm_clock_hour.state }}:
        {%- if states.sensor.alarm_clock_minute.state|length == 1 -%}
          0
        {%- endif -%}
          {{ states.sensor.alarm_clock_minute.state }}
    alarm_clock_time_long:
      value_template: >-
        {% if states.sensor.alarm_clock_hour.state|length == 1 -%}
          0
        {%- endif -%}
          {{ states.sensor.alarm_clock_hour.state }}:
        {%- if states.sensor.alarm_clock_minute.state|length == 1 -%}
          0
        {%- endif -%}
          {{ states.sensor.alarm_clock_minute.state }}
    alarm_clock_start:
      value_template: '{{ ((as_timestamp(now())|int + 300)|timestamp_custom("%H:%M")) }}'

Automation:

- alias: 'almclk_wake_up script triggered by alarm clock'
  trigger:
    platform: template
    value_template: '{{ states.sensor.alarm_clock_start.state == states.sensor.alarm_clock_time_long.state }}'
  condition:
    condition: state
    entity_id: input_boolean.alarm_clock_status
    state: 'on'
  action:
    service: script.wake_up

I found post#73 to be very informative at the time: a very nice rewording of the actual documentation on automation template and time triggers. tldr:

  • leverage the time_date platform in value_template just like yours:
    '{{ states("sensor.time") == states("sensor.alarmclock_lights_time") }}'
  • the other option is to trigger evaluation every ‘/n’ time unit with a time platform trigger since at: won’t take a template.

Relative time calculations can horribly complexify the template expression. I, for myself, try to stick to kiss approach, favoring decoupling in general and ultimately thinking packaging when it comes to my configuration.

@patkap thank you for your answer. I tried your suggestions, but unfortunately they did not work either.

This is so sad, I can’t understand why this is the only automation that’s not working.

Hi @mbonani,

for me it works with that :

    trigger:
      - platform: time
        minutes: '/1'
        seconds: 0
    condition:
      - condition: state
        entity_id: input_boolean.automa
        state: 'on'
      - condition: state
        entity_id: calendar.jours_feries_en_france
        state: 'off'
      - condition: template
        value_template: '{{ ((now().strftime("%s") | int + 300) | timestamp_custom("%H:%M") == states.sensor.alarm_time.state) }}'
    action:
      - service: light.turn_on
        entity_id: light.chambre
        data:
          transition: 600
          brightness: 255

you could test with the trigger /1 minutes …

Just tested with the copied and pasted code you provided plus some missing bits …

input_slider:
  alarm_clock_hour:
    initial: 6
    min: 0
    max: 23
    step: 1
  alarm_clock_minute:
    initial: 45
    min: 0
    max: 59
    step: 1

input_boolean:
  alarm_clock_status:
    initial: on

sensor:
  - platform: time_date
    display_options:
      - 'time'
  - platform: template
    sensors:
      alarm_clock_hour:
        value_template: '{{ states.input_slider.alarm_clock_hour.state|int }}'
      alarm_clock_minute:
        value_template: '{{ states.input_slider.alarm_clock_minute.state|int }}'
      alarm_clock_time:
        value_template: >-
          {{ states.sensor.alarm_clock_hour.state }}:
          {%- if states.sensor.alarm_clock_minute.state|length == 1 -%}
            0
          {%- endif -%}
            {{ states.sensor.alarm_clock_minute.state }}
      alarm_clock_time_long:
        value_template: >-
          {% if states.sensor.alarm_clock_hour.state|length == 1 -%}
            0
          {%- endif -%}
            {{ states.sensor.alarm_clock_hour.state }}:
          {%- if states.sensor.alarm_clock_minute.state|length == 1 -%}
            0
          {%- endif -%}
            {{ states.sensor.alarm_clock_minute.state }}
      alarm_clock_start:
        value_template: '{{ ((as_timestamp(now())|int + 300)|timestamp_custom("%H:%M")) }}'

automation:
  - alias: 'almclk_wake_up script triggered by alarm clock'
    trigger:
      platform: template
      value_template: '{{ states.sensor.time.state == states.sensor.alarm_clock_time_long.state }}'
    condition:
      condition: state
      entity_id: input_boolean.alarm_clock_status
      state: 'on'
    action:
      service: persistent_notification.create
      data_template:
        title: 'Alarm!'
        message: '{{ trigger.to_state.state }}

Options !

@Vantskruv

I had the same problem with the time and changed the script from (now().strftime("%s") | int | timestamp_custom("%H:%M")) to as_timestamp (now()) | timestamp_custom("%H:%M") and now everything works fine.

I forgot to post I had the same problem. For some reason now().strftime("%s") returns weird values here, as_timestamp(now()) solved it.

((now().strftime("%s")|int)|timestamp_custom("%H:%M")) == 13:23

((as_timestamp(now())|int)|timestamp_custom("%H:%M")) == 17:23

@Vantskruv and @j.assuncao, are you guys using Hassio?

@mbonani Yes, i am using hass.io