Automation w/ Boolean switch

Hello, I hope somebody could help me figure this out.

Im sure there is a better way or atleast see what im missing.

i would love to have a switch so the automation doesn’t turn on during Weekends, snow days, holidays etc.

thanks in advance!

- id: work_school_alarm
  trigger:
    platform: time
    # When 'at' is used, you cannot also match on hour, minute, seconds.
    # Military time format.
    at: '05:55:00'
  action:
    - service: script.turn_on
      entity_id: script.corey_work_alarm
    - service: homeassistant.turn_on
      data:
        entity_id: light.bed_lamp_1
        brightness: 10
    - delay:
        minutes: 5
    - service: homeassistant.turn_off
      entity_id: light.bed_lamp_1
    - delay:
    # supports milliseconds, seconds, minutes, hours, days
        minutes: 40

    - service: script.turn_on
      entity_id: script.time_for_school
    - service: homeassistant.turn_on
      entity_id:
        - light.morgan_lamp
        - light.morgans_room
        - light.camerons_room
    - delay:
    # supports milliseconds, seconds, minutes, hours, days
        minutes: 1
    - service: script.turn_on
      entity_id: script.time_for_school
    - delay:
    # supports milliseconds, seconds, minutes, hours, days
        minutes: 24
    - service: script.turn_on
      entity_id: script.leave_for_school
    - delay:
    # supports milliseconds, seconds, minutes, hours, days
        minutes: 3
    - service: homeassistant.turn_off
      entity_id:
        - light.morgan_lamp
        - light.morgans_room
        - light.camerons_room
    - delay:
    # supports milliseconds, seconds, minutes, hours, days
        minutes: 67
    - service: homeassistant.turn.on
      entity_id:
        - light.cj_bed_lamp
        - light.cj_floor_lamp
    - delay:
        minutes: 35
    - service: script.turn_on
      entity_id: script.alexa_tts_test_execute
    - service: homeassistant.turn_on
      data:
        entity_id: group.livingroom
        color_name: green
        brightness: 255
    - service: homeassistant.turn_on
      data:
        entity_id: group.kitchen
        color_name: green
        brightness: 255
    - delay:
        minutes: 2
    - service: homeassistant.turn_on
      data:
        entity_id: group.livingroom
        color_name: yellow
        brightness: 255
    - service: homeassistant.turn_on
      data:
        entity_id: group.kitchen
        color_name: yellow
        brightness: 255
    - delay:
        minutes: 2
    - service: script.turn_on
      entity_id: script.courtney_bus
    - service: homeassistant.turn_on
      data:
        entity_id: group.livingroom
        color_name: red
        brightness: 255
        flash: long
    - service: homeassistant.turn_on
      data:
        entity_id: group.kitchen
        color_name: red
        brightness: 255
        flash: long
    - service: homeassistant.turn_off
      entity_id:
        - light.cj_bed_lamp
        - light.cj_floor_lamp
    - delay:
        minutes: 3
    - service: homeassistant.turn_on
      data:
        entity_id: group.livingroom
        color_name: relax
    - service: homeassistant.turn_on
      data:
        entity_id: group.kitchen
        color_name: relax

There is a component that can show if ‘today’ is a workday or not:

You would check in a condition by using binary_sensor.workday_sensor and see if it’s ‘on’ before you execute the whole routine.

1 Like

This is a good solution but sometimes the kids don’t have school and I still work or vise versa. I’ll have to look into this for a normal pattern. Thanks for the information!

As I work early and late shifts I am using a google Calendar, it doesn’t take too long to setup as you can repeats things in the calendar. This then triggers different input_booleans depending on what shift I work and if it’s a weekend or I am hosting a dinner part etc.

RESOLVED - Google Calendar based lights

1 Like

In this case I’d just add an input boolean to the setup and check against it in a second condition - the input-boolean could then be changed manually.

Or, maybe an even better idea:
Set up an automation with notification every evening at 9pm with an actionable notification e.g. like this one:

The 2nd part of the automation would be to turn the next day to a workday anyway (in case it wasn’t one today).

So, if you do not respond to the message, the next day is a normal day, if you do, the input boolean will be changed to indicate a ‘free day’.

1 Like

OK this might seem like a lot, but I.m trying here.

I have tried to set 3 different automatons.

  1. My alarm
  2. My Boys Alarm
  3. My Daughters Alarm

I also am trying to create input booleans so I can turn each one off if I don’t need them to run.
Heres my automations:

- id: work_alarm
  alias: Work Alarm
  trigger:
    - platform: time
    # When 'at' is used, you cannot also match on hour, minute, seconds.
    # Military time format.
      at: '05:55:00'
  action:
    - service: script.turn_on
      entity_id: script.corey_work_alarm
    - service: light.turn_on
      data:
        entity_id: light.bed_lamp_1
        brightness: 25
    - delay: '00:03:00'
    - service: light.turn_off
      entity_id: light.bed_lamp_1

- id: boys_school_wakeup
  alias: Boys School Alarm
  trigger:
    - platform: time
      at: '06:35:00'
  action:
    - service: script.turn_on
      entity_id: script.time_for_school
    - service: homeassistant.turn_on
      entity_id: group.boys_lights_alarm
    - delay: '00:01:00'
    - service: script.turn_on
      entity_id: script.time_for_school
    - delay: '00:33:00'
    - service: script.turn_on
      entity_id: leave_for_school
    - delay: '00:01:00'
    - service: script.turn_on
      entity_id: script.leave_for_school
    - delay: '00:03:00'
    - service: homeassistant.turn_off
      entity_id: group.boys_lights_alarm

- id: courtney_school_alarm
  alias: Courtney School Alarm
  trigger:
    - platform: time
      at: '07:40:00'
  action:
    - service: homeassistant.turn_on
       entity_id: group.courtneys_room
    - service: script.turn_on
      entity_id: script.wendy_courtney_alarm
    - delay: '00:20:00'
    - service: script.turn_on
      entity_id: script.eight_am_announcement
    - service: homeassistant.turn_off
      entity_id: group.courneys_room
    - service: homeassistant.turn_on
      entity_id: group.hue_yellow
    - delay: '00:02:00'
    - service: script.turn_on
      entity_id: script.eight_two_am_announcement
    - service: homeassistant.turn_on
      entity_id: group.hue_green
    - delay: '00:03:00'
    - service: script.turn_on
      entity_id: script.courtney_bus
    - service: homeassistant.turn_on
      entity_id: group.hue_red
    - delay: '00:01:00'
    - service: homeassistant.turn_on
      entity_id: group.hue_relax

Here’s my automation booleans:

- id: work_alarm_on
  alias: Work Alarm On (school)
  trigger:
  - platform: state
    entity_id: input_boolean.corey_work_alarm_school
    from: 'off'
    to: 'on'
  action:
    - service: homeassistant.turn_on
      entity_id: automation.corey_work_alarm_school

- id: work_alarm_off
  alias: Work Alarm (school)
  trigger:
  - platform: state
    entity_id: input_boolean.corey_work_alarm_school
    from: 'on'
    to: 'off'
  action:
    - service: homeassistant.turn_off
      entity_id: automation.corey_work_alarm_school

- id: boys_alarm_on
  alias: Boys Alarm On School
  trigger:
  - platform: state
    entity_id: input_boolean.boys_school_alarm
    from: 'off'
    to: 'on'
  action:
    - service: homeassistantn.turn_on
      entity_id: automation.boys_school_wakeup

- id: boys_alarm_off
  alias: Boys Alarm Off School
  trigger:
  - platform: state
    entity_id: input_boolean.boys_school_alarm
    from: 'on'
    to: 'off'
  action:
    - service: homeassistant.turn_off
      entity_id: automation.boys_school_wakeup

- id: courtney_alarm_on
  alias: Courtney's Alarm On School
  trigger:
  - platform: state
    entity_id: input_boolean.courtney_school_alarm
    from: 'off'
    to: 'on'
  action:
    - service: homeassistant.turn_on
      entity_id: automation.courtney_school_alarm

- id: courtney_alarm_off
  alias: Courtney's Alarm Off School
  trigger:
  - platform: state
    entity_id: input_boolean.courtney_school_alarm
    from: 'on'
    to: 'off'
  action:
    - service: homeassistant.turn_off
      entity_id: automation.courtney_school_alarm

input_booleans:

  boys_school_alarm:
    name: Boys School Alarm

  courtney_school_alarm:
    name: Courtney's School Alarm

  corey_work_alarm_school:
    name: Corey's Work Alarm (School)

  corey_work_alarm_no_school:
    name: Work Alarm (no school)

If anybody could tell me what Im doing wrong I would be grateful, I have been trying to do this for a few hours now, and I think I may just be missing something obvious. But I keep getting errors and can’t figure out why.
Thanks!
Corey

Hey, so have you ever thought about template switches instead of input booleans? I like them better because it ties everything together.

Keep the following automations:

- id: work_alarm
  alias: Work Alarm
  trigger:
    - platform: time
    # When 'at' is used, you cannot also match on hour, minute, seconds.
    # Military time format.
      at: '05:55:00'
  action:
    - service: script.turn_on
      entity_id: script.corey_work_alarm
    - service: light.turn_on
      data:
        entity_id: light.bed_lamp_1
        brightness: 25
    - delay: '00:03:00'
    - service: light.turn_off
      entity_id: light.bed_lamp_1

- id: boys_school_wakeup
  alias: Boys School Alarm
  trigger:
    - platform: time
      at: '06:35:00'
  action:
    - service: script.turn_on
      entity_id: script.time_for_school
    - service: homeassistant.turn_on
      entity_id: group.boys_lights_alarm
    - delay: '00:01:00'
    - service: script.turn_on
      entity_id: script.time_for_school
    - delay: '00:33:00'
    - service: script.turn_on
      entity_id: leave_for_school
    - delay: '00:01:00'
    - service: script.turn_on
      entity_id: script.leave_for_school
    - delay: '00:03:00'
    - service: homeassistant.turn_off
      entity_id: group.boys_lights_alarm

- id: courtney_school_alarm
  alias: Courtney School Alarm
  trigger:
    - platform: time
      at: '07:40:00'
  action:
    - service: homeassistant.turn_on
       entity_id: group.courtneys_room
    - service: script.turn_on
      entity_id: script.wendy_courtney_alarm
    - delay: '00:20:00'
    - service: script.turn_on
      entity_id: script.eight_am_announcement
    - service: homeassistant.turn_off
      entity_id: group.courneys_room
    - service: homeassistant.turn_on
      entity_id: group.hue_yellow
    - delay: '00:02:00'
    - service: script.turn_on
      entity_id: script.eight_two_am_announcement
    - service: homeassistant.turn_on
      entity_id: group.hue_green
    - delay: '00:03:00'
    - service: script.turn_on
      entity_id: script.courtney_bus
    - service: homeassistant.turn_on
      entity_id: group.hue_red
    - delay: '00:01:00'
    - service: homeassistant.turn_on
      entity_id: group.hue_relax

Remove your input booleans and there automations. Use the following switch templates (I also noticed your personal automation has differing names, I fixed that in the switch templates and made a note for you).

switch:
  - platform: template
    switches:

      # switch to turn on automation for corey
      work_alarm:
        value_template: "{{ is_state('automation.work_alarm','on') }}" #You had wrong entity_id above
        turn_on:
          - service: homeassistant.turn_on
            entity_id: automation.work_alarm
        turn_of:
          - service: homeassistant.turn_off
            entity_id: automation.work_alarm

      # switch to turn on automation for boys
      boys_school_wakeup:
        value_template: "{{ is_state('automation.boys_school_wakeup','on') }}"
        turn_on:
          - service: homeassistant.turn_on
            entity_id: automation.boys_school_wakeup
        turn_of:
          - service: homeassistant.turn_off
            entity_id: automation.boys_school_wakeup

      # switch to turn on automation for courtney
      courtney_school_alarm:
        value_template: "{{ is_state('automation.courtney_school_alarm','on') }}"
        turn_on:
          - service: homeassistant.turn_on
            entity_id: automation.courtney_school_alarm
        turn_of:
          - service: homeassistant.turn_off
            entity_id: automation.courtney_school_alarm

Does this still give me the ability to turn on and off each night for changing conditions?

I finally did get it working this morning. I did split up my boys automations so if one of them doesn’t have to go to school at the normal time.

- id: cameron_school_wakeup
  trigger:
    - platform: time
      at: '06:35:00'
  action:
    - service: script.turn_on
      entity_id: script.cameron_time_for_school
    - service: homeassistant.turn_on
      entity_id: group.hue_cameron_school
    - service: notify.notify
      data_template:
        message: >
          Wake up Cameron its time to get up for school Automation Started {{ "\ud83d\udca9" }}
    - delay: '00:01:00'
    - service: script.turn_on
      entity_id: script.cameron_time_for_school
    - delay: '00:32:00'
    - service: script.turn_on
      entity_id: script.cameron_leave_for_school
    - delay: '00:01:00'
    - service: script.turn_on
      data:
        entity_id: script.cameron_leave_for_school
    - delay: '00:01:00'
    - service: homeassistant.turn_off
      entity_id: group.hue_cameron_school

- id: morgan_school_wakeup
  trigger:
    - platform: time
      at: '06:40:00'
  action:
    - service: script.turn_on
      entity_id: script.morgan_time_for_school
    - service: homeassistant.turn_on
      entity_id: group.hue_morgan_school
    - service: notify.notify
      data_template:
        message: >
          Wake up Morgan its time to get up for school Automation Started {{ "\ud83d\udca9" }}
    - delay: '00:01:00'
    - service: script.turn_on
      entity_id: script.morgan_time_for_school
    - delay: '00:28:00'
    - service: script.turn_on
      entity_id: script.morgan_leave_for_school
    - delay: '00:01:00'
    - service: script.turn_on
      data:
        entity_id: script.morgan_leave_for_school
    - delay: '00:01:00'
    - service: homeassistant.turn_off
      entity_id: group.hue_morgan_school

I did offset them a few minutes because I wasn’t sure if I could send them at the same time (I use alexa TTS to send messages to their amazon dots)

Im more then happy to use templates and it definitely looks better assuming I can still turn it on and off preferably in HomeKit.

Thanks for your help on this, Im sure I can figure out how to rewrite my boys automations based on your example. You sir are truly amazing and I really appreciate it!

Yeah, it will look like a switch/input_boolean in the user interface. It will be in the switch domain though.

im sure this is a stupid question,

should I place the switch template in template_sensors.yaml? I did, I havent got a error but cant fin the switch in the UI.

Im a idiot, I got it thanks! Im trying here… lol

1 Like

Is there a reason you wouldn’t just expose the automations to HomeKit or the front end and use the native switch on /off vs making template switches?

Sorry i ddint see this reply. You place template switches in the switch section of your configuration.

1 Like

It depends on what you are using. HomeKIt has that ability, but other components might not. I made a template switch for a few automations because the on/off functionality acted weird when they were run through alexa with emulated hue. It’s all just personal preference.

It’s all good, I just made a !include switch.yaml and all went well. This was my first switch template.

Now I can move onto my Xiaomi Motion Sensors. That’s a headache in itself lol. I appreciate you helping me out with my alarm automation!

Thanks bro!

1 Like