Help with AlarmClock

Hello Everyone,

I am struggling to get my alarm clock to work again. Ever since i updated to 82.1 the automation doesnt work anymore and i cannot figure out why.

Any pointers would be helpful.

input_number:
    alarm_1_hour:
        name: Hours
        icon: mdi:timer
        initial: 7
        min: 0
        max: 23
        step: 1
    alarm_1_minutes:
        name: Minutes
        icon: mdi:timer
        initial: 0
        min: 0
        max: 59
        step: 1
    alarm_1_offset:
        name: Transition
        icon: mdi:blur-linear
        initial: 15
        min: 0
        max: 60
        step: 15

input_boolean:
    alarm_1_weekday:
        name: Weekdays
        initial: on
        icon: mdi:calendar
    alarm_1_weekend:
        name: Weekends
        initial: off
        icon: mdi:calendar

sensor:
    - platform: template
      friendly_name: sensor.alarm_1_time
      sensors:
         alarm_1_time:
              friendly_name: 'Alarm Time'
              value_template: >-
                  {{ "%0.02d:%0.02d" | format(states("input_number.alarm_1_hour") | int, states("input_number.alarm_1_minutes") | int) }}
    - platform: template
      entity_id: sensor.alarm_1_time_minus_offset
      sensors:
         alarm_1_time_minus_offset:
              friendly_name: 'Offset Time'
              value_template: >-
                  {{ '%0.02d:%0.02d' | format( ((((states('input_number.alarm_1_hour') | int)*60 + (states('input_number.alarm_1_minutes') | int) - (states('input_number.alarm_1_offset'))| int)/60)| int),(((((((((states('input_number.alarm_1_hour') | int)*60 + (states('input_number.alarm_1_minutes') | int) - (states('input_number.alarm_1_offset')) | int)/60)) - ((((states('input_number.alarm_1_hour') | int)*60 + (states('input_number.alarm_1_minutes') | int) - (states('input_number.alarm_1_offset')) | int)/60)| int))*100) | int)*60/100) | round) ) }}

group:
    alarm_1:
        name: Wake Me Up
        entities:
            - sensor.time
            - sensor.alarm_1_time
            - sensor.alarm_1_time_minus_offset
            - input_number.alarm_1_hour
            - input_number.alarm_1_minutes
            - input_number.alarm_1_offset
            - input_boolean.alarm_1_weekday
            - input_boolean.alarm_1_weekend


automation:            
- id: alarm_1_weekday
  alias: 'Wake me up (weekday)'
  trigger:
    - platform: time
      minutes: '/1'
      seconds: 00
  condition:
    condition: and
    conditions:
      - condition: state
        entity_id: input_boolean.alarm_1_weekday
        state: 'on'
      - condition: time
        weekday:
          - mon
          - tue
          - wed
          - thu
          - fri  
      - condition: template
        value_template: "{{ states.sensor.time.state == states.sensor.alarm_1_time_minus_offset.state  }}"
  action:
  - data:
      message: Alarm ! Current time is {{ states.sensor.time.state }} and alarm is set to {{ states.sensor.alarm_1_time.state }} with an offset of {{ states.input_number.alarm_1_offset.state }} set to {{ states.sensor.alarm_1_time_minus_offset.state }} Weekdays ({{ states.input_boolean.alarm_1_weekday.state }} ) and Weekends ({{ states.input_boolean.alarm_1_weekend.state }} ) test {{ "%0.02d:%0.02d" | format(states("input_number.alarm_1_hour") | int, states("input_number.alarm_1_minutes") | int) }}
    service: notify.zchat
  - data: {}
    service: script.wakeup_sequence
- id: alarm_1_weekend
  alias: 'Wake me up (weekend)'
  trigger:
    - platform: time
      minutes: '/1'
      seconds: 00
  condition:
    condition: and
    conditions:
      - condition: state
        entity_id: input_boolean.alarm_1_weekend
        state: 'on'
      - condition: time
        weekday:
          - sat
          - sun
      - condition: template
        value_template: "{{ states.sensor.time.state == states.sensor.alarm_1_time_minus_offset.state  }}"
  action:
  - data:
      message: Alarm ! Current time is {{ states.sensor.time.state }} and alarm is set to {{ states.sensor.alarm_1_time.state }} with an offset of {{ states.input_number.alarm_1_offset.state }} set to {{ states.sensor.alarm_1_time_minus_offset.state }} Weekdays ({{ states.input_boolean.alarm_1_weekday.state }} ) and Weekends ({{ states.input_boolean.alarm_1_weekend.state }} ) test {{ "%0.02d:%0.02d" | format(states("input_number.alarm_1_hour") | int, states("input_number.alarm_1_minutes") | int) }}
    service: notify.zchat
  - data: {}
    service: script.wakeup_sequence

“Does not work” is not an error report.

The Bug is: It does not trigger the automation.

There is no log that I could post, not really sure what to say.

image

Take the “and” out of your conditions. They are not necessary, and they seem to be creating problems in recent versions of HA.

I changed the automation to this. The automation is still not triggered, i tried to just take the and away but then i’ll get a config error.

automation:            
- id: alarm_1_weekday
  alias: 'Wake me up (weekday)'
  trigger:
    - platform: time
      minutes: '/1'
      seconds: 00
  condition:
    - condition: state
      entity_id: input_boolean.alarm_1_weekday
      state: 'on'
    - condition: time
      weekday:
        - mon
        - tue
        - wed
        - thu
        - fri  
    - condition: template
      value_template: "{{ states.sensor.time.state == states.sensor.alarm_1_time_minus_offset.state  }}"
  action:
  - data:
      message: Alarm ! Current time is {{ states.sensor.time.state }} and alarm is set to {{ states.sensor.alarm_1_time.state }} with an offset of {{ states.input_number.alarm_1_offset.state }} set to {{ states.sensor.alarm_1_time_minus_offset.state }} Weekdays ({{ states.input_boolean.alarm_1_weekday.state }} ) and Weekends ({{ states.input_boolean.alarm_1_weekend.state }} ) test {{ "%0.02d:%0.02d" | format(states("input_number.alarm_1_hour") | int, states("input_number.alarm_1_minutes") | int) }}
    service: notify.zchat
  - data: {}
    service: script.wakeup_sequence

I shortened it to and its still not working, I tested the states and sensors they are working properly, in the interface, and the condition seems easy enough to write.

automation:            
- id: alarm_1_weekday
  alias: 'Wake me up (weekday)'
  trigger:
    - platform: time
      minutes: '/1'
      seconds: 00
  condition:
    - condition: template
      value_template: "{{ states.sensor.time.state == states.sensor.alarm_1_time_minus_offset.state  }}"
  action:
  - data:
      message: Alarm ! 
    service: notify.zchat

Put quotes around the message.

Does it trigger manually?

Any errors?

Thanks for the hint, I tried triggering the automation by hand and the message delivers without a problem
image

i even put all the states in to check if everything is captured properly :slight_smile:
message: Alarm ! Current time is {{ states.sensor.time.state }} and alarm is set to {{ states.sensor.alarm_1_time.state }} with an offset of {{ states.input_number.alarm_1_offset.state }} set to {{ states.sensor.alarm_1_time_minus_offset.state }} Weekdays ({{ states.input_boolean.alarm_1_weekday.state }} ) and Weekends ({{ states.input_boolean.alarm_1_weekend.state }} ) test {{ "%0.02d:%0.02d" | format(states("input_number.alarm_1_hour") | int, states("input_number.alarm_1_minutes") | int) }}

I guess it must be condition or trigger issue, is there another way to go about the time trigger?

I guess I found the error. Automations cannot be included into packages but must be contained in the automation.yml

cheers thanks for the help

1 Like

Thats kind of a bummer; I like being able to load everything related to a package (scripts, groups, automations, etc) from that package file. Makes it a little more organized IMO and easier to share.

I went back and looked at the packages documentation here: https://www.home-assistant.io/docs/configuration/packages/ and it says

“The package configuration can include: switch , light , automation , groups , or most other Home Assistant components including hardware platforms. It can be specified inline or in a separate YAML file using !include .”

So is that out of date or I was correct to include my automation within my package and there’s something else causing the problem.

I will give it a try, when I come home again maybe it was bugged for a version or two.

Automations work fine in packages, and always have.

Good to know.

Works now for me in packages:

input_number:
    alarm_1_hour:
        name: Hours
        icon: mdi:timer
        initial: 7
        min: 0
        max: 23
        step: 1
    alarm_1_minutes:
        name: Minutes
        icon: mdi:timer
        initial: 0
        min: 0
        max: 59
        step: 1
    alarm_1_offset:
        name: Transition
        icon: mdi:blur-linear
        initial: 15
        min: 0
        max: 60
        step: 15

input_boolean:
    alarm_1_weekday:
        name: Weekdays
        initial: on
        icon: mdi:calendar
    alarm_1_weekend:
        name: Weekends
        initial: off
        icon: mdi:calendar

sensor:
    - platform: template
      friendly_name: sensor.alarm_1_time
      sensors:
         alarm_1_time:
              friendly_name: 'Alarm Time'
              value_template: >-
                  {{ "%0.02d:%0.02d" | format(states("input_number.alarm_1_hour") | int, states("input_number.alarm_1_minutes") | int) }}
    - platform: template
      entity_id: sensor.alarm_1_time_minus_offset
      sensors:
         alarm_1_time_minus_offset:
              friendly_name: 'Offset Time'
              value_template: >-
                  {{ '%0.02d:%0.02d' | format( ((((states('input_number.alarm_1_hour') | int)*60 + (states('input_number.alarm_1_minutes') | int) - (states('input_number.alarm_1_offset'))| int)/60)| int),(((((((((states('input_number.alarm_1_hour') | int)*60 + (states('input_number.alarm_1_minutes') | int) - (states('input_number.alarm_1_offset')) | int)/60)) - ((((states('input_number.alarm_1_hour') | int)*60 + (states('input_number.alarm_1_minutes') | int) - (states('input_number.alarm_1_offset')) | int)/60)| int))*100) | int)*60/100) | round) ) }}

group:
    alarm_1:
        name: Wake Me Up
        entities:
            - sensor.time
            - sensor.alarm_1_time
            - sensor.alarm_1_time_minus_offset
            - input_number.alarm_1_hour
            - input_number.alarm_1_minutes
            - input_number.alarm_1_offset
            - input_boolean.alarm_1_weekday
            - input_boolean.alarm_1_weekend





automation:
  - id: 'alarm_1_weekday'
    alias: Wake me up (weekday)
    trigger:
    - platform: time_pattern
      minutes: /1
      seconds: 0
    condition:
    - condition: state
      entity_id: input_boolean.alarm_1_weekday
      state: 'on'
    - condition: time
      weekday:
      - mon
      - tue
      - wed
      - thu
      - fri
    - condition: template
      value_template: '{{ states.sensor.time.state == states.sensor.alarm_1_time_minus_offset.state  }}'
    action:
    #- data:
    #    message: Alarm ! Current time is {{ states.sensor.time.state }} and alarm is set to {{ states.sensor.alarm_1_time.state }} with an offset of {{ states.input_number.alarm_1_offset.state }} set to {{ states.sensor.alarm_1_time_minus_offset.state }} Weekdays ({{ states.input_boolean.alarm_1_weekday.state }} ) and Weekends ({{ states.input_boolean.alarm_1_weekend.state }} ) test {{ "%0.02d:%0.02d" | format(states("input_number.alarm_1_hour") | int, states("input_number.alarm_1_minutes") | int) }}
    #  service: notify.zchat
    - data: {}
      service: script.wakeup_sequence
  - id: 'alarm_1_weekend'
    alias: Wake me up (weekend)
    trigger:
    - platform: time_pattern
      minutes: /1
      seconds: 0
    condition:
    - condition: state
      entity_id: input_boolean.alarm_1_weekend
      state: 'on'
    - condition: time
      weekday:
      - sat
      - sun
    - condition: template
      value_template: '{{ states.sensor.time.state == states.sensor.alarm_1_time_minus_offset.state  }}'
    action:
    #- data:
    #    message: Alarm ! Current time is {{ states.sensor.time.state }} and alarm is set to {{ states.sensor.alarm_1_time.state }} with an offset of {{ states.input_number.alarm_1_offset.state }} set to {{ states.sensor.alarm_1_time_minus_offset.state }} Weekdays ({{ states.input_boolean.alarm_1_weekday.state }} ) and Weekends ({{ states.input_boolean.alarm_1_weekend.state }} ) test {{ "%0.02d:%0.02d" | format(states("input_number.alarm_1_hour") | int, states("input_number.alarm_1_minutes") | int) }}
    #  service: notify.zchat
    - data: {}
      service: script.wakeup_sequence 
      
      
script:
  'wakeup_dim':
    alias: wakeup_dim
    sequence:
    - data:
        brightness: '0'
        entity_id:
        - light.lamp_kitchen1
        - light.lamp_kitchen2
        - light.lamp_kitchen3
        - light.lamp_dinning1
        - light.lamp_dinning2
        - light.lamp_dinning3
        - light.office_lamp_new
        - light.lamp_couch
        - light.bedroom_lamp1
        - light.bedroom_lamp2
        - light.hallway_lamp_new
        kelvin: '2200'
        transition: '0'
      service: light.turn_on
    - data:
        brightness: '0'
        entity_id:
        - light.gateway_light_286c07fa2642
        - light.yeelight_rgb_34ce008d0d2f
        rgb_color:
        - 255
        - 169
        - 92
      service: light.turn_on
    - data:
        brightness_pct: '0'
        entity_id:
        - light.colour_bulb
        rgb_color:
        - 255
        - 169
        - 92
        transition: '0'
      service: light.turn_on
  'wakeup_bright':
    alias: wakeup_bright
    sequence:
    - data_template:
        brightness: '255'
        kelvin: '2700'
        transition: '{{(states(''input_number.alarm_1_offset'') | int ) *60}}'
        entity_id:
        - light.lamp_kitchen1
        - light.lamp_kitchen2
        - light.lamp_kitchen3
        - light.lamp_dinning1
        - light.lamp_dinning2
        - light.lamp_dinning3
        - light.office_lamp_new
        - light.lamp_couch
        - light.bedroom_lamp1
        - light.bedroom_lamp2
        - light.hallway_lamp_new
      service: light.turn_on
    - data_template:
        brightness: '255'
        transition: '{{(states(''input_number.alarm_1_offset'') | int ) *60}}'
        entity_id:
        - light.colour_bulb
        rgb_color:
        - 255
        - 169
        - 92
      service: light.turn_on
  'wakeup_sequence':
    alias: wakeup_sequence
    sequence:
    - data:
        message: Alarm ! Current time is {{ states.sensor.time.state }} and alarm is set to {{ states.sensor.alarm_1_time.state }} with an offset of {{ states.input_number.alarm_1_offset.state }} set to {{ states.sensor.alarm_1_time_minus_offset.state }} Weekdays ({{ states.input_boolean.alarm_1_weekday.state }} ) and Weekends ({{ states.input_boolean.alarm_1_weekend.state }} ) 00:{{ states.input_number.alarm_1_offset.state | int }}:00
      service: notify.zchat
    - data: {}
      service: script.wakeup_dim
    - delay: 00:00:02
    - service: script.wakeup_bright
    - delay: '00:{{ states.input_number.alarm_1_offset.state | int }}:00'
    - data: {}
      service: script.play_wakeup_music