20 minute read

3 actually smart automations from my personal home

Everyone has their own favorite automations. These are the ones I’m most proud of from my own personal setup.

Making a light go on when a motion sensor detects movement or making a vacuum automatically clean a room on a schedule is something everyone thinks about. But here I’m going to expose 5—and a bonus one—home automations that some of you may have overlooked or completely forgot.

These are all implemented in my Home Assistant setup. You may read something like “helper” or “boolean” at some point. That’s all Home Assistant lingo.

Prevent vacuum if anyone is sleeping

I never said these would be easy or have a straight forward setup. But the truth is that, after setting it up, you will be wondering why you haven’t done it before.

The premise on this one is simple: you have your vacuum on a schedule. But for some reason, on a certain day, someone is sleeping by the time the cleaning should be happening. So you be a nice person and prevent the cleaning from waking up the person.

Here’s what you need

The script

It’s nice to uncouple the logic into a script because you can then call this script whenever you want. Either from within another automation, say when you leave your home on a specific day, or even when you press a button in a dashboard.

YAML
12345678910111213141516171819
sequence:
  - action: vacuum.send_command
    data:
      command: app_segment_clean
      params:
        - repeat: "1"
          segments: >
            {% set cleaning_rooms = [] %}
            {% if is_state('input_boolean.is_cleaning_kids_bedroom', 'on') %}
            {% set cleaning_rooms = cleaning_rooms + [17] %}
            {% endif %}
            {% if is_state('input_boolean.is_cleaning_upstairs_bathroom', 'on') %}
            {% set cleaning_rooms = cleaning_rooms + [21] %}
            {% endif %}
    target:
      entity_id:
        - vacuum.roborock_s5_max
alias: Vacuum Clean Rooms
description: ""

The automation

This automation does a bunch of validations and only then calls the script from above to actually clean the rooms.

In this case, I have configured it so that it runs every weekday at 12:30. Then I enable a few room boolean helpers to clean just a few rooms. Then I check if my daughter is sleeping, because if she is, it will need to wait until she wakes up within the next hour—I get notified when this condition is true. When that happens, I just call the script from above so that the vacuum can actually clean the rooms.

YAML
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
alias: "@12:30"
description: ""
triggers:
  - trigger: time
    at: "12:30:00"
conditions:
  - condition: time
    weekday:
      - mon
      - tue
      - wed
      - thu
      - fri
actions:
  - action: input_boolean.turn_on
    metadata: {}
    data: {}
    target:
      entity_id:
        - input_boolean.is_cleaning_kids_bedroom
        - input_boolean.is_cleaning_upstairs_bathroom
  - if:
      - condition: state
        entity_id: input_boolean.is_daughter_sleeping
        state: "on"
    then:
      - action: notify.notify
        metadata: {}
        data:
          message: I’ll resume the cleaning when daughter awakes
          title: Vacuum paused
      - wait_for_trigger:
          - trigger: state
            entity_id:
              - input_boolean.is_daughter_sleeping
            to: "off"
        continue_on_timeout: false
        timeout:
          hours: 1
          minutes: 0
          seconds: 0
      - action: script.vacuum_clean_rooms
        data: {}
    else:
      - action: script.vacuum_clean_rooms
        data: {}
mode: single

Open gates when arriving home

Think about this: you’re arriving home, driving, and will need to open both the driveway gate as well as the garage gate. You have been using a remote attached to your car keys or stored somewhere inside your car. But it not always works first try. Sometimes you need to press a button a dozen times until the gate actually opens.

Let’s make it smarter!

Here’s what you need

The script

This is only needed because the Shelly 1 Mini doesn’t know whether the gates are open or closed. Perhaps there’s some other smarter relay that would know that and would save some complexity here as well as the need for the contact sensor. But anyway, this is my setup.

It checks if the driveway gate is closed and if it is, toggle—that’s the keyword—the driveway gate. Then wait 250 ms and toggle again.

So, what’s actually happening here? The gate works by electrical impulses.

This means that:

The thing here is that the Shelly only pushes an impulse when it changes from off state to on. So we have to manually turn the Shelly switch off so that we can push just 1 impulse when we actually want to interact with it. Hence the last step on this script.

In other words, the relay is state agnostic. It doesn’t know the current state of the gate, it just sends impulses.

YAML
123456789101112131415161718192021222324252627
sequence:
  - if:
      - condition: state
        entity_id: binary_sensor.driveway_gate_magnetic_sensor
        state: "off"
        for:
          hours: 0
          minutes: 0
          seconds: 5
    then:
      - action: switch.turn_on
        metadata: {}
        data: {}
        target:
          entity_id: switch.driveway_gate
      - delay:
          hours: 0
          minutes: 0
          seconds: 0
          milliseconds: 250
      - action: switch.turn_off
        metadata: {}
        data: {}
        target:
          entity_id: switch.driveway_gate
alias: Open driveway gate
description: ""

And yes, if you were wondering, it does leave the gate open. That’s because my gate has an internal logic board that ends up automatically closing it after a short period of time, so I don’t even bother with that.

The automation

This is triggered when my phone changes to home state. Then it checks if I’m driving and if that’s the case, it waits 10 seconds so that I have time to actually pull up to the gate. Then it opens the driveway gate and waits 3 seconds. And lastly it also opens the garage gate.

This setup works most of the time.

But here’s one edge case that this automation doesn’t cover: say you left your home in a hurry. After a few minutes you realized you forgot something and go back home. When you arrive home this automation will be triggered, so both your driveway and garage gates will open. But you’re most likely to park your car on the street since you’re just picking up something you forgot and will be back in the car within a few minutes. But your gates are open now. You will have to close them manually, unless your gates close automatically after some time, like my driveway gate does.

YAML
1234567891011121314151617181920212223242526272829
alias: "@pedro.arrives_home.driving"
description: ""
triggers:
  - trigger: state
    entity_id:
      - device_tracker.pmpintos_iphone
    to: home
conditions:
  - condition: state
    entity_id: input_boolean.is_pedro_driving
    state: "on"
actions:
  - delay:
      hours: 0
      minutes: 0
      seconds: 10
      milliseconds: 0
  - action: script.open_driveway_gate
    metadata: {}
    data: {}
  - delay:
      hours: 0
      minutes: 0
      seconds: 3
      milliseconds: 0
  - action: script.open_garage_gate
    metadata: {}
    data: {}
mode: single

You could work around the edge case from above simply by creating another automation that’s triggered when you’re away. And when that happens both the driveway and the garage gates get closed. I also have this in place, but for the garage gate only.

Oh, and in case you were wondering how does Home Assistant know if you’re driving, that’s the missing puzzle piece. That happens outside of Home Assistant, for me. I have an automation in iOS Shortcuts that gets triggered when my phone connects via Bluetooth to my car. Inside that automation what it does is a Call service action, the service being input_boolean.turn_on, since you want it to turn your “Is driving” boolean on. Then you select your server where you have Home Assistant running and provide the service data as a JSON object, like this {"entity_id": "input_boolean.is_pedro_driving”}.

Multimedia alarm clock

The last one I have for you is the one that gets used the most around here, I would say. Of course one can just rely on a good old alarm clock, or even a phone. But mine uses: phone on my nightstand, watch on my wrist, blinds and TV in my bedroom. And it has an auto switch off feature!

Here’s what you need

The script

Again, by decoupling the logic into a script, we can not only call this from an automation, as we’ll do below, but also from a dashboard button, which I also have.

This script starts by turning the TV on. From my experience this works far more reliably when the TV is connected via Ethernet instead of Wi-Fi. Your milage may vary. I’ve read some people can get around this by disabling some “eco” features from the TV that prevent it from going into deep sleep. Give it a try!

YAML
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
alias: Play music on Bedroom TV
description: ""
sequence:
  - action: wake_on_lan.send_magic_packet
    data:
      broadcast_port: 9
      mac: CC:00:BB:11:AA:22 # Replace with the MAC address of your TV
  - wait_for_trigger:
      - trigger: state
        entity_id:
          - media_player.bedroom_tv
        to: "on"
    timeout:
      hours: 0
      minutes: 1
      seconds: 0
    continue_on_timeout: false
  - action: media_player.play_media
    metadata: {}
    data:
      media_content_id: "109"
      media_content_type: channel
    target:
      entity_id: media_player.bedroom_tv
  - action: media_player.volume_set
    metadata: {}
    data:
      volume_level: 0.03
    target:
      entity_id: media_player.bedroom_tv
  - delay:
      hours: 0
      minutes: 5
      seconds: 0
      milliseconds: 0
  - action: media_player.volume_set
    metadata: {}
    data:
      volume_level: 0.05
    target:
      entity_id: media_player.bedroom_tv
  - delay:
      hours: 0
      minutes: 10
      seconds: 0
  - action: media_player.volume_set
    metadata: {}
    data:
      volume_level: 0.07
    target:
      entity_id: media_player.bedroom_tv

It then waits for the TV to connect to Home Assistant, which can take some time, and then changes to a specific music channel and sets the volume at 3%—this is because the last thing the TV does at night right before I fall asleep is setting the volume to 1%. Then it waits 5 minutes and increases the volume to 5%. Then waits another 10 minutes and sets the volume at 7%, which is quite noticeable at this level. Lastly, it opens the blinds to let the light in.

The automation

In reality, the trigger is 10 minutes before my alarm clock starts. Which means that by the time my phone and wrist start chirping at me, the TV will already be blasting some music.

The conditions for this automation to run are: I’m sleeping, and I’m at home. So that this doesn’t run when I’m sleeping in a hotel somewhere else.

YAML
1234567891011121314151617181920
alias: "@pedro.alarm_clock"
description: ""
triggers:
  - trigger: template
    value_template: >-
      {{ (states('input_datetime.next_alarm_clock_time') | as_timestamp - 600) == states('sensor.date_time').replace(', ', ' ') | as_timestamp }}
conditions:
  - condition: state
    entity_id: input_boolean.is_pedro_sleeping
    state: "on"
  - condition: state
    entity_id: device_tracker.pmpintos_iphone
    state: home
actions:
  - action: script.turn_on
    metadata: {}
    data: {}
    target:
      entity_id: script.play_music_on_bedroom_tv
mode: single

Lastly, but not part of this automation, is another iOS Shortcut I run when I wake up. I pick up my phone, turn off the alarm clock and click a widget that tells Home Assistant I’m not sleeping anymore. This triggers another automation that turns off the TV after 10 minutes. By the time I’m dressed and out the bedroom, the TV will shut itself off.

Other automation ideas worth mentioning

The original plan was to make this a 5 automation blog post. But you can see this quickly becomes big enough to be hard to follow. For the following 3 automations I’m just going to briefly mention them without going over my whole setup.

Toggle lights when dark or bright

Instead of relying on a fixed schedule, like 20:00, to make your lights shine—which can be easily unnecessary during the summer, or perhaps you will need them earlier on cloudy days—you can rely on a lux sensor placed somewhere inside your house.

This will tell you how bright it is inside, and whether or not you need to turn on the lights. I personally have mine setup at 12 lux. Meaning that below that, the lights will turn on. It doesn’t matter if it’s winter or summer, if it’s cloudy or rainy, or even just smoky outside. If it’s dark, the lights will be on.

Mosquito killer and towel dryer timer safeguards

Everyone hates mosquitos. That’s arguably a safe assumption to make, I believe. Whether you are one more prominent to get bitten or just hate to bothered by them racing by your ears, a mosquito killer can do wonders for you.

I personally have mine connected to a smart plug all the time. When I enable it, an automation will start a 1 hour timer. When that timer ends, the plug gets turned off automatically. This way you can close all the blinds by sunset and turn on the mosquito killer. In about 1 hour the air will be breathable again and you don’t need to remember to turn it off.

Same for towel dryers. I personally hang my shower tower right after using it, and turn on the dryer. You know, because I appreciate dry towels. To make sure it only runs for 1 hour at a time, I use the same setup from above. Start a timer and wait for it to end. When it does, turn off the plug.

It also prevents your kids from “accidentally” turning the dryer on and leaving it running a few days in a row.
Ask me how I know.

Changing modes on security cameras

Most security camera systems will have multiple modes. For instance, when you’re at home, you don’t want to sound an alarm when they detect movement, since it’s most likely going to be you, or someone from your household.

But when you’re away, that’s another story.

Some systems might have geolocation features that automatically do this for you. We have Eufy. And it never worked reliably for us. So we had to manually change the modes ourselves. Of course this means that plenty of times the mode was set to home when we have been away all day.
Home Assistant to the rescue!

When nobody is at home, Home Assistant automatically changes the mode to away for us. And when we get home, it changes to home. No more remembering. No more forgetting. No more issues.

Another use case we have is when we spend a long period of time in the backyard. Say we’re grilling some meat, or just chilling outside. When that’s the case, we don’t want to be pinged every few seconds because there’s a person outside. Of course there is, it’s us!

So we have a “backyard” mode. In this mode, we don’t get any notifications from the cameras. Instead, when this mode is enabled, a timer starts. While that timer is elapsing, we aren’t bothered. Whenever the backyard cameras sense movement while in the backyard mode, the timer gets reset. When that timer ends, Home Assistant changes the mode back to “home”, so that we are warned about backyard movement again.

Bottom line

Work smarter, not harder.

You know this one? Sometimes we actually need to work harder to be able to work smarter. When it comes to Home Assistant, that’s usually the case. We can do pretty much anything with it. The downside is that, most of the time, we need to do plenty of configuration beforehand.

But it’s all worth it in the end.
Right…? Right?!

Photo of Pedro