Automation and Boolean

I’ve been using HA since the beginning of the year and it;s time to get more into the automations. I had a simple alarm clock that that brighten the lights and turned on a few others. Same time every day.

Looking at the thread about alarm clock I like the move to sliders to set the time. So following the one I liked I added an automation to automation.yaml, sensors to sensor.yaml, but don’t know where to put the input_sliders and input_booleans. Do I need to create new yaml files for them.

I tried different places and the only yaml file that would do anything that would load after restarting HA was in the configuration.yaml. But the alarm doesn’t work and I get the following errors in the log.

    17-03-05 18:42:44 WARNING (MainThread) [homeassistant.components.sensor.template] Could not render template Minutes, the state is unknown. 
    17-03-05 18:42:44 WARNING (MainThread) [homeassistant.components.sensor.template] Could not render template Hour, the state is unknown. 
    17-03-05 18:42:44 WARNING (MainThread) [homeassistant.components.sensor.template] Could not render template Alarm, the state is unknown.

Everything in the HA UI looks good. Can move the sliders and activate the alarm, but the automation will not run.

Any help greatly appreciated.

You can either put it directly in the config.yaml or you can create separate yaml files and include them.

If you can post all of the code related to your automation I’m sure someone here can help you.

Just make sure after you paste your code in the post you highlight and click the preformatted text button in the editor menu. Button that looks like < / >.

Here are my yaml’s.

automation.yaml

- alias: "Alarm"
  trigger:
    platform: time
    minutes: '/1'
    seconds: 0    
    
  condition:
      condition: and
      conditions:
          - condition: template
            value_template: '{{ states.sensor.time.state == states.sensor.alarm_time.state }}'

          - 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: time
                    weekday:
                      - sun
                      - mon
                      - tue
                      - wed
                      - thu
                      - fri
          - condition: and
            conditions:
              - condition: state
                entity_id: input_boolean.alarmstatus
                state: 'on'
              - condition: state
                entity_id: input_boolean.alarmweekday
                state: 'off'    
  action:
      - service: script.turn_on 
        entity_id: script.wakeup

sensor.yaml

  - platform: template
    sensors:
      alarm_hour:
        friendly_name: 'Hour'
        value_template: '{{ states.input_slider.alarmhour.state|round(0)|string }}'
      alarm_minutes:
        friendly_name: 'Minutes'
        value_template: '{{ states.input_slider.alarmminutes.state|round(0)|string }}'
      alarm_time:
        friendly_name: 'Alarm'
        value_template: '{% if states.input_slider.alarmhour.state|round(0)|string|length == 1 %}0{% endif %}{{ states.input_slider.alarmhour.state|round(0)|string }}:{% if states.input_slider.alarmminutes.state|round(0)|string|length == 1 %}0{% endif %}{{ states.input_slider.alarmminutes.state|round(0)|string }}'
      time:
        value_template: '{{ now().strftime("%H:%M")}}'

And the lines in the configuration.yaml for the alarm clock

input_slider:
      alarmhour:
        name: Hour
        icon: mdi:timer
        initial: 5
        min: 0
        max: 23
        step: 1
      alarmminutes:
        name: Minutes
        icon: mdi:timer
        initial: 30
        min: 0
        max: 55
        step: 5

    input_boolean:
      alarmstatus:
        name: Active
        initial: off
        icon: mdi:alarm-check

      alarmweekday:
        name: workdays
        initial: off
        icon: mdi:calendar

Hope those help someone find my problem.

With creating a yaml/s file for the input_boolean and the input_slider can they be in one file or separate yaml files like input_boolean.yaml and input_slider.yaml and then list them in the configuration.yaml?

TIA

I don’t know why you need Hour and Minutes sensor, but for the alarm time, here’s what I use:

sensor:
  - platform: template
    sensors:
      wake_up_alarm_time:
        friendly_name: 'Time'
        value_template: '{{ "%0.02d:%0.02d" | format(states("input_slider.alarmhour") | int, states("input_slider.alarmminutes") | int) }}

I basically did a copy and paste of code put up for use and added my action and default alarm time… At this time, I don’t understand this enough to start from scratch. Everything seems to be working, but the alarm is not going off. See errors in the first post. I’m clueless till I learn more.

I spent a lot of time going through this post here to get my similar alarm/timer situation working: https://github.com/master-kenobi/ha-alarmclock

After I used that github link last week, all I did was change my action in his code and all was well.
Thanks for the reply.