5 Ways to Automate the Boring Stuff
I recently did a video on Youtube where I talked about 5 of my favorite automations I use to Automate the Boring Stuff. I currently have more than 200 running in Home Assistant and while these are some of my favorite they are not my only favorite ones. In any case, if you haven’t watched that video check it out.
But since that video was just a high level look, I wanted to go into a little more detail here for anyone that wanted to get into the weeds.
Digital Cuckoo Clock
I have always liked the idea of a clock that chimed in my house. It takes something that required effort from me, like looking at a clock to see what time it was, to just listening for the chime in the background. It’s like a constant subtle reminder to keep you up to date as time passes.
I once had grandfather clock dreams. But Carlo over at vCloudInfo gave me the perfect opportunity to build one in Home Assistant.
This one is really simply to setup, in fact Carlo did all the work. We simply have to copy and paste. If you get a chance you should check out his Github Repo. There is good stuff in there.
But to set this up we simply need to copy his automation:
#####################################################################
# @CCOSTAN
# Original Repo : https://github.com/CCOSTAN/Home-AssistantConfig
## Plays the number of cuckoos per hour and 1 on the half hour.
# More Info and Video: https://www.vcloudinfo.com/2017/11/building-digital-cuckoo-clock-with-home.html
#####################################################################
- alias: Cuckoo Clock
id: 33dcd8e2-e87c-4d18-82bc-c7f9b53a1624
mode: restart
trigger:
- platform: time_pattern
minutes: 0
- platform: time_pattern
minutes: 30
condition:
- condition: time
after: '09:29:00'
before: '21:30:00'
- condition: or #Either we are home or Guest_Mode is on.
conditions:
- condition: state
entity_id: group.family
state: 'home'
- condition: state
entity_id: input_boolean.guest_mode
state: 'on'
action:
- service: script.amp_settings
data:
media_player: 'media_player.livingroomcc'
volume_level: 0.22
- wait_template: "{{ not is_state('media_player.livingroomCC', 'playing') }}"
- service: media_player.play_media
data:
entity_id: >
{% if states.group.bed.state == 'off' %}
media_player.livingroomCC
{% else %}
media_player.alarm_clock, media_player.bedroom_alarm_panel
{% endif %}
media_content_id: >
{% if now().strftime("%M")|int == 30 %}
https://raw.githubusercontent.com/CCOSTAN/Home-AssistantConfig/master/config/sounds/cuckoo-clock-01.wav
{% else %}
https://raw.githubusercontent.com/CCOSTAN/Home-AssistantConfig/master/config/sounds/cuckoo-clock-{{now().strftime("%I")}}.wav
{% endif %}
media_content_type: audio/mp4
Just copy that code, and paste it into your automation.yaml.
Carlo even provides the audio files for you. And the coolest part is that in the future if you decide to change the chime, or you find other chimes you want to use, all you have to do is update this automation.
Again, a really simple automation that can provide a nice reminder that just happens in the background.
Mail Notifications
I think most of us Smart Home types eventually start to wonder how we could get our mailbox tied to Home Assistant. After all, knowing when someone put mail in your mailbox would let you know when its time to head to the mailbox. But if you are like me distance might be an issue, and if you are in an apartment and you mailbox is in a central location then that might even be a bigger issue.
Thankfully if you are in the United States you can use the USPS informed Delivery. And if you do use USPS Informed Delivery then you really need the Mail and Packages integration from HACS.
Setting it up is like any other HACS integration, and it relies on the emails you are already getting. The integration simply logs in to your email account and reads the email. I used to do this with a script, but this integration is much better.
And once you get it setup you can setup some notifications. Like:
- alias: "Mail Notif - Mail Delieveries"
trigger:
- platform: time
at: '10:00:00'
#Trigger if mail or packages get updated
# - platform: state
# entity_id: sensor.mail_usps_mail
# - platform: state
# entity_id: sensor.mail_usps_delivering
#send only if mail or packages are more than 0
condition:
- condition: or
conditions:
- condition: template
value_template: "{{ states('sensor.mail_usps_mail') | int > 0 }}"
- condition: template
value_template: "{{ states('sensor.mail_usps_delivering') | int > 0 }}"
action:
- service: script.text_notify
data_template:
who: "jeff"
title: "Delivering Today"
message: "{{ states('sensor.mail_deliveries_message')}}"
- service: script.status_annc
data_template:
who: '{{ states.sensor.room_audio.state }}'
call_interuption: 1
speech_message: >-
{%- if states.sensor.mail_usps_mail.state | int == 1 -%}
{{ [
"USPS is delivering",
"The postal service will be leaving",
"The nice lady in the mail truck is bringing us ",
"I have scanned the incoming mail,and there is"
] | random }}
{{ states.sensor.mail_usps_mail.state }} piece of mail today.
{%- else -%}
{{ [
"USPS is delivering",
"The postal service will be leaving",
"The nice lady in the mail truck is bringing us ",
"I have scanned the incoming mail, and determined there are"
] | random }}
{{ states.sensor.mail_usps_mail.state }} pieces of mail today.
{%- endif -%}
I had some weirdness happening when it triggered straight off the sensor, so I modified it to just happen once a day, at 10 am to be precise.
Then it simply checks to see if there is actual mail showing up, and then makes an announcement. This lets us know if we need to make our daily trek to the mailbox.
But even better we can get announcements when UPS, or FedEx delivers packages. Simply just watch those sensors from the integration and send a notification:
- alias: "Delivered Package Notification"
initial_state: true
trigger:
- platform: state
entity_id: sensor.mail_fedex_delivered_2
- platform: state
entity_id: sensor.mail_ups_delivered
#send only if mail or packages are more than 0
condition:
- condition: or
conditions:
- condition: template
value_template: "{{ states('sensor.mail_fedex_delivered_2') | int > 0 }}"
- condition: template
value_template: "{{ states('sensor.mail_ups_delivered') | int > 0 }}"
action:
- service: script.text_notify
data_template:
who: "jeff"
title: "Package Delivered"
message: "Fedex/UPS just made a delivery"
- service: script.status_annc
data_template:
who: '{{ states.sensor.room_audio.state }}'
speech_message: >-
A package was just left on the porch.
call_interuption: 1
This means that we don’t have to keep checking to see if a package was delivery. We just get a notification both on our phones, and in the house.
And since this integration uses emails you can have it notify you when you amazon shipments are on their way and even when they were delivered. So if you want Home Assistant aware of your shipments, this integration and the automations you build off it might get you there.
Event Notifications
For me, I always wanted my smart home to help run my life. And part of that is keeping up with my calendar.
Thankfully Home Assistant has a google calendar integration. And so I setup a calendar just for the house. This calendar contains things like my kid’s school schedule, holidays, birthdays, doctors appointments, and so on. Basically anything that we need to keep track of.
Then I can setup an automation to remind us prior to an event. However, this part was a bit tricky and it took a couple of tries before the lightbulb of understanding went off.
But if you are using the Google Calendar integration, and have an event you want to be reminded of, you can simply add !!-00:45
to the event title if you want to be reminded 45 minutes prior.
So in the calendar the Event may look like:
Then you could have an automation in Home Assistant to create a notification:
- id: e1cb2f28-0423-11eb-adc1-0242ac120002
alias: Skylar Event Starting soon
trigger:
- platform: state
entity_id: calendar.skylar_events
attribute: offset_reached
to: True
action:
- service: script.status_annc
data:
who: '{{ states.sensor.room_presence.state }}'
call_interuption: 1
call_skylar_events: 1
- service: script.text_notify
data_template:
who: "all_ios"
message: Skylar has {{ states.calendar.skylar_events.attributes.message }} in 45 minutes.
The trigger would be when ever the offset_reached
switches to true which would be based on the !!-00:45
in the event title. So the offset is reached 45 mins prior to the calendar start time in this case.
The important thing to remember with these is there is no way for Home Assistant to see all the day’s events at one time, so I break them up into separate calendars. This also helps simply the notification automations since overlapping events would get missed.
In the above calendar event you can see a #se
in the event notes. This can be used in your google calendar configuration to separate types of events into their on “calendar” within Home Assistant. Allow you to better track the events and send notifications.
Skylar Out
Every night, when my son is in his bed we tell his google home Skylar out
and this kicks off a Google routine that does a couple of things.
First it triggers a scene in Home Assistant that adjust the lighting in his room:
- name: skylar room sleep
entities:
input_boolean.audible_notifications:
state: 'off'
light.wled_loftbed:
state: 'on'
brightness_pct: 100
rgb_color:
- 63
- 255
- 0
switch.rainbow_lamp:
state: 'on'
switch.wled_loftbed_nightlight:
state: 'on'
switch.skylar_led_cube:
state: 'on'
input_boolean.skylar_awake:
state: 'off'
input_boolean.skylar_dressed_reminder:
state: 'off'
light.skylars_dresser_lamp:
state: 'off'
id: f4e8d2f594c446ee9f0e41cf46dc1c72
This is trigger inside the Google Home Routine by choose the Adjust Scenes
action and then picking the scene you want to activate.
But we also use this to tell Home Assistant its time to switch to quiet mode. This scene turns off audible notifications, which doesn’t really turn off audible notifications but routes them to other parts of the house where they won’t wake Skylar.
Then the Google Routine plays his bedtime playlist on Apple Music since we cannot start the playlist from Home Assistant. Back when we used Spotify, this routine triggered a script in Home Assistant that activated the scene, and started Spotify in his bedroom. But Apple Music is that open.
But using this routine like this gives us the ability to tie the house switching modes to when people start going to sleep. So since of a set schedule, it is tied to when my son goes to sleep since he is almost always the first in bed.
Dog Mode
And then there was dog mode which was born out of necessity. In fact, if you want to read the story check out [Where we are going, We need dog mode]
But the basic gist is I needed a way to disarm the Home Assistant security system in the middle of the night. When I was half asleep. And not aware of enough that I should grab my phone off the night stand.
Since my security system is built on the idea that we dont want physically have to arm and disarm the security system, it didn’t really handle the exception of a dog having to go out in the middle of the night outside his normal schedule. Hence Dog Mode.
Based on time of night, and motion sensors Home Assistant decides that there is a good chance the dog is going out and so it turns on dog mode. When dog mode is opened, if a door is opened, the security alarm automation bypasses the trigger.
- id: security_breach_door
alias: Security Breach Doors
trigger:
- platform: state
entity_id:
- binary_sensor.front_door
- binary_sensor.back_door
- binary_sensor.side_door
- binary_sensor.garage_door
to: 'on'
condition:
- condition: state
entity_id: input_boolean.sentry_mode
state: 'on'
action:
- choose:
- conditions:
- condition: template
value_template: '{{ trigger.to_state.attributes.friendly_name == "Back Door"
}}'
- condition: state
entity_id: input_boolean.dog_mode
state: 'on'
sequence:
- service: script.text_notify
data:
who: "jeff"
message: "Dog Mode enabled, bypassing back door sensor."
default:
- service: script.jarvis_alert
data_template:
message: "My security protocols are being overidden,, The {{ trigger.to_state.attributes.friendly_name }} has been opened."
- service: script.text_alert
data:
who: parents
title: "Security Alert!!"
message: "{{ trigger.to_state.attributes.friendly_name }} has been opened."
- service: input_boolean.turn_on
entity_id: input_boolean.security_issue
initial_state: true
This means that we dont have to worry about disarming the system, and rearming it when he is done. Dog mode turns on automatically and then turns off returning the system back to monitoring the doors. As an added benefit, if any other door is opened while Dog Mode is on, the alarm goes off as intended.
All in all a great way to handle both those unscheduled canine bathroom breaks, and having to remember to disarm the security system.
And that’s it, five automations that help us automate the boring stuff.