Creating a alarm clock

What does the template give as output in the dev-tool? Did you test if it ever gets value “true”?

You can also put them directly beneath each other ( in the dev-tool) to make sure they have the same format (and not a extra 0 for instance):

 {{ states("sensor.alarm_clock_start") }}
 {{ states("sensor.alarm_clock_time_long") }}

And finally you can also try the following format:

'{{ states.sensor.alarm_clock_start.state == states.sensor.alarm_clock_time_long.state }}'

It gets “true”.

Earlier today I changed the value_template in the automation and it started working. I’m still testing it.

- alias: 'alarm clock'
  trigger:
    - platform: time
      minutes: '/1'
      seconds: 0
  condition:
    - condition: state
      entity_id: input_boolean.alarm_clock_status
      state: 'on'
    - condition: state
      entity_id: input_boolean.vacation_mode
      state: 'off'
    - condition: template
      value_template: '{{ ((as_timestamp(now())|int + 300)|timestamp_custom("%H:%M")) == states("sensor.alarm_clock_time_long") }}'
  action:
    service: script.wake_up

It returns “true” once a day. :wink:

It seems to be working fine now.

Thank you all for your help.

1 Like

It seems like an MQTT button would be the way to go for that. Or one of those z-wave remote controls. I don’t know if an automation can control another automation though. :thinking:

Thanks, been a while since I looked at this.

I have some Xiaomi Buttons so I may make them switch on a script that stops the alarm… adds a 10mins delay… then starts the alarm sound again. Should be quite easy actually. I haven’t used my alarm since because I couldn’t find a simple solution at the time. Thanks for reminding me! I’ll add this to the list of things to do.

What I would really love is to continue using my sleep cycle app and integrate it into Emulated Hue. The app can turn on/turn off a Hue bulb when the alarm is set/goes off. But I haven’t found a way of making that work with emulated Hue.

Can anyone help me?

I have this automation:

- alias: 'Ochtend Verwarming'
  trigger:
    platform: state
    entity_id: input_number.morningheatinghour, input_number.morningheating_min, input_number.morningheatingduration
  action:
  - service: homeassistant.turn_on
    data:
      entity_id:
        - automation.morningheating_on
  - service: homeassistant.turn_on
    data:
      entity_id:
        - automation.morningheating_off

- alias: 'morningheating_on'
  initial_state: True
  trigger:
    - platform: time
      minutes: '/5'
      seconds: 14
  condition:
    condition: and
    conditions:
      - condition: template
        value_template: '{{ (now().strftime("%s") | int | timestamp_custom("%H:%M")) == states.sensor.morningheating_time.state }}'
      - condition: state
        entity_id: input_boolean.morningheatingstatus
        state: 'on'
  action:
    service: scene.turn_on
    entity_id: scene.Ochtend_Prog_aan

- alias: 'morningheating_off'
  initial_state: True
  trigger:
    - platform: time
      minutes: '/5'
      seconds: 14
  condition:
    condition: and
    conditions:
      - condition: template
        value_template: '{{ ((now().strftime("%s") | int - (states("input_number.morningheatingduration") | int) * 60) | timestamp_custom("%H:%M")) == states.sensor.morningheating_time.state }}'
      - condition: state
        entity_id: input_boolean.morningheatingstatus
        state: 'on'
  action:
    service: scene.turn_on
    entity_id: scene.Ochtend_Prog_uit

Second automation doesn’t trigger.

How to solve?

I’m not quite sure what you are trying to accomplish here. What is your goal with this automation? Turning on an automation doesn’t mean it gets triggered, you are aware of that?.

Hi Bob,
Yes I know turning on the automation doesn’t trigger it :).
What I’m trying to accomplish is that the first automation turns on the heating.
Then the second automation should trigger after the starting time + duration minutes occurs, and should turn off the heating.

I copied it from this thread (hmmm, maybe I should post my question there then :))

Hi @PuckStar,

Unless I did not understand your request, if you simply want to turn your heating off x minutes after it’s been turned on, why not add a delay to your first automation then turn the heating off?

  action:
    service: scene.turn_on
    entity_id: scene.Ochtend_Prog_uit
    delay: 00:10:00
    service: scene.turn_off
    entity_id: scene.Ochtend_Prog_uit

I want it to be variable and to be set through the UI. So 1 day I may want it to stay on 15minutes, the other day 60minutes.
Can I use input_numbers as the delay variable?

in that case I’d personally stick with 2 automations indeed.
The 2nd should run periodically (e.g. every 1 min) and have a condition to check against.

I’d say make sure you’re on you can use release 0.55 or later and use input_datetime in your condition. I would not use the == operator but the >= operator to make sure your automation still runs in the event where there is a delay.
I’d use something like this:

     - condition: template
        value_template: '{{ (as_timestamp(states.automation.ochtend_verwarming.attributes.last_triggered + input_datetime.time_to_heat) -  as_timestamp(states.automation.ochtend_verwarming.attributes.last_triggered) > 0}}'

I’ve not tested the above code so can’t guarantee it’s error-free but should give you a starting point hopefully.

OR you could use an input_select with a list of times and use this instead of input_datetime.time_to_heat if your list of possible times is not infinite

hello guys i use the alarm clock.
when i restart my pi i lost all values of my Sliders.
how can i do?

Have a look here…

Something goes wrong with the statement half hour before but I’m not sure what I’m doing wrong.
Any thoughts?


- alias: 'Half uur voor de wekker CV aan'
  initial_state: 'on'
  hide_entity: True
  trigger:
    platform: template
    value_template: '{{ ((now().strftime("%s") | int + 1800 ) | timestamp_custom("%H:%M")) == states.sensor.alarm_clock_time_long.state }}'
  condition:
    condition: or
    conditions:
      - condition: and
        conditions:
        - condition: state
          entity_id: input_boolean.alarmstatus
          state: 'on'
        - condition: state
          entity_id: input_boolean.alarmweekday
          state: 'on'
      - condition: and
        conditions:
        - condition: state
          entity_id: input_boolean.alarmstatus
          state: 'on'
        - condition: state
          entity_id: input_boolean.alarmweekday
          state: 'off'
  action:
    -   service: scene.turn_on
        entity_id: scene.toon_comfort

@keithh666 i tried it but not works.
I would like to use mqtt.

I use this:

alias: ‘test’
trigger:
platform: template
value_template: '{{ states.sensor.time.state == states.sensor.alarm_time.state }}
action:
service: notify.notify
data_template:
message: ‘teste’

How can transform that ,on mqtt?
I dont want lost my sliders values when i restart.

@masterkenobi can u help too?

I think if you were to create an MQTT switch that had as payload your slider state and set the state and command topics to the same, then set the retain switch to true, that would force the MQTT broker to resend the slider state back after a reset. You would have to setup an automation to send the state when it’s state changed.

@keithh666 i am using this alarm https://github.com/master-kenobi/ha-alarmclock
Can put here that changes ? I dont have skills to create that you told me. If you can help was great.

An alarm clock that plays a radio station in the morning?

What would be the best code

can you post your code, thanks