Whats wrong in this alarmclock automation

HI,

something must be wrong cause the alarm will never ring…

Ive check in the template section dev tools, and if the time is set, it won’t go to true. Cant see the error though, please have a look?

automation:
  - alias: Alarm Clock
    id: '1511601479002'
    initial_state: 'off'
    trigger:
      - platform: time
        minutes: '/5'
        seconds: 00
    condition:
      condition: or
      conditions:
        - condition: and
          conditions:
          - condition: template
            value_template: '{{ now().time().strftime("%H:%M") == states.sensor.alarmclock_wd_time_template.state }}'
          - condition: state
            entity_id: input_boolean.alarmclock_wd_enabled
            state: 'on'
          - condition: state
            entity_id: binary_sensor.workday_sensor
            state: 'on'
        - condition: and
          conditions:
          - condition: template
            value_template: '{{ now().time().strftime("%H:%M") == states.sensor.alarmclock_we_time_template.state }}'
          - condition: state
            entity_id: input_boolean.alarmclock_we_enabled
            state: 'on'
          - condition: state
            entity_id: binary_sensor.workday_sensor
            state: 'off'
    action:
      - service: script.alarmclock_ring


Cheers,
Marius

states.sensor.alarmclock_wd_time_template.state

Whats the state of that look like normally?

Do this in the templates section:

{{ states.sensor.alarmclock_wd_time_template.state }}

Also, Can you verify that you are actually firing the event on the minute that you have programmed?

Example. You set the alarm for 1:01. Home assistant fires the even at 1:00, 1:05, 1:10, etc. You’ll never get an alarm because the minutes never match up.

Initial_state off?

this gives the correct time i set with the input_sliders.

I think this sounds like the issue… Unfortunately i wouldn’t know how to check, or change it.

I am positive that the script that is called in the action is actually valid and working. I can call it and it sets a enables a greater set of action even resulting in the espresso machine being turned on :wink:

with the : in between?

If that’s the case, just fire it every minute.

like this you mean? i had already tried that…

automation:
  - alias: Alarm Clock
    id: '1511601479002'
    initial_state: 'off'
    trigger:
      - platform: time
        **minutes: '/1'**
        seconds: 00
    condition:
      condition: or
      conditions:
        - condition: and
          conditions:
          - condition: template
            value_template: '{{ now().time().strftime("%H:%M") == states.sensor.alarmclock_wd_time_template.state }}'
          - condition: state
            entity_id: input_boolean.alarmclock_wd_enabled
            state: 'on'
          - condition: state
            entity_id: binary_sensor.workday_sensor
            state: 'on'
        - condition: and
          conditions:
          - condition: template
            value_template: '{{ now().time().strftime("%H:%M") == states.sensor.alarmclock_we_time_template.state }}'
          - condition: state
            entity_id: input_boolean.alarmclock_we_enabled
            state: 'on'
          - condition: state
            entity_id: binary_sensor.workday_sensor
            state: 'off'
    action:
      - service: script.alarmclock_ring

thought of that, but i do think it is set to on because of this:

35

the sensors:

sensor:
  - platform: template
    sensors:
      alarmclock_wd_time_template:
        friendly_name: 'Time'
        icon_template: "{{ 'mdi:alarm' if is_state('input_boolean.alarmclock_wd_enabled', 'on') else 'mdi:close-circle' }}"
        value_template: '{{ "%0.02d:%0.02d" | format(states("input_number.alarmclock_wd_hour") | int, states("input_number.alarmclock_wd_minute") | int) }}'
      alarmclock_we_time_template:
        friendly_name: 'Time'
        icon_template: "{{ 'mdi:alarm' if is_state('input_boolean.alarmclock_we_enabled', 'on') else 'mdi:close-circle' }}"
        value_template: '{{ "%0.02d:%0.02d" | format(states("input_number.alarmclock_we_hour") | int, states("input_number.alarmclock_we_minute") | int) }}'

give a positive result also:

47

maybe splitting the automation into 2, one for weekdays (wd), and one for weekend (we) could work?

I wonder @mviezzer, does this alarm clock work in your setup at all?

I know you spent alot of time on those sliders, but did you do know about input_datetime?

Anyways,

For shits and giggles, transform your condition to this:

condition:
  condition: template
  value_template: >
    {% set state1 = now().strftime("%H:%M") == states.sensor.alarmclock_wd_time_template.state and is_state('input_boolean.alarmclock_wd_enabled', 'on') and is_state('binary_sensor.workday_sensor','on') %}
    {% set state2 = now().strftime("%H:%M") == states.sensor.alarmclock_we_time_template.state and is_state('input_boolean.alarmclock_we_enabled', 'on') and is_state('binary_sensor.workday_sensor','off') %}
    {{ state1 or state2 }}

Also, plop that into the template editor and check out the values of state1 and state2

wd gives nothing, which is wrong
we give false, which is correct …

— wait a minute my feedback was incorrect: the full above template returns False.—

what value is_state for:

{{ is_state('input_boolean.alarmclock_wd_enabled', 'on') }}

{{ is_state('binary_sensor.workday_sensor','on') }}

true

True

no errors there it seems

It’s gotta be that time check then.

Only thing i noticed was:

now().time().strftime("%H:%M")

can be simplified to

now().strftime("%H:%M")

other than that, not sure.

you could try:

{{ now().hour == 12 and now().minute == 00 }}

with integers. just spit balling.

not exactly sure what yo want me to try here? should i copy past this instead of the strftime?

still, the time check works fine i think, its more the script that isn’tcalled after the condition value_template is met?

Or maybe the fact i have this all except the scripts grouped into an alarm_clock package…
Had strange Package behavior before (groups not reloading, scripts not loading)

see:

I am stumped. Believe it or not, but i have entered an empty line between the trigger and the conditions like below. For the first time this alarm clock has fired.
How is this even possible??

Now have it play a sound on my iPhone…That must be something inconceivable ?

automation:
  - alias: Alarm Clock
    id: '1511601479002'
    initial_state: 'on'
    trigger:
      - platform: time
        minutes: '/1'
        seconds: 00

    condition:
      condition: or
      conditions:
        - condition: and
          conditions:
          - condition: template
            value_template: '{{ now().time().strftime("%H:%M") == states.sensor.alarmclock_wd_time_template.state }}'
          - condition: state
            entity_id: input_boolean.alarmclock_wd_enabled
            state: 'on'
          - condition: state
            entity_id: binary_sensor.workday_sensor
            state: 'on'
        - condition: and
          conditions:
          - condition: template
            value_template: '{{ now().time().strftime("%H:%M") == states.sensor.alarmclock_we_time_template.state }}'
          - condition: state
            entity_id: input_boolean.alarmclock_we_enabled
            state: 'on'
          - condition: state
            entity_id: binary_sensor.workday_sensor
            state: 'off'
    action:
      - service: script.alarmclock_ring

Hi, yes, working here. Could be that initial_state: ‘off’ (the automation wasn’t running, that is not related with Enabled check.

This is relatively new. Most alarm clocks snippets are way back.

The iOS is very restrictive in this way, you may need a workarround… Or use something like Google Home/Chromecast or Kodi or IR blaster to turn on tv…