Technology Solutions for Everyday Folks
Snip of details when creating a Home Assistant helper entity for a timer object.

Turn off the fan already! Tales of an automation modification

It's been a couple months since my last post, and while I had some things in the queue I have lacked time to finish them out due to MMS in early May, being involved in a community theatre production that just wrapped up a couple weeks ago, and for random reasons building a chicken coop of all things. ¯\_(ツ)_/¯

Here's to a return of more regular posts, assuming I have adequate time to write and revise them!

Reviewing Home Assistant Automations

As I wrote about before, I've solved a situation with a bathroom fan by creating an automation that takes into account a couple of factors: correcting adjusting for human behavior, environmental fluctuations (dynamic values), and balancing the impact (not wasting electricity). The resulting automation I had created in Home Assistant has been working very well, but I knew I would likely need to adjust it as the system entered the last season of its inaugural run.

I had built out the original automation in late fall, before the heating system was in operation. Fall also basically solved for spring. Throughout the winter, the dynamic sensor value worked great and the fan just worked as expected. That left summer...its own unique beast.

The Original Dynamic Range

My original assumptions worked well for a set of sensors where moderate variation in humidity existed, as it does through the majority of the year. My original YAML for the dynamic range was:

{% if avghumidity < 40 %}
  45
{% elif avghumidity > 70 %}
  80
{% else %}
  {{ avghumidity + 5.5 }}
{% endif %}

The floor and ceiling values were set at 40% and 70%, respectively. The resulting setpoint floor/ceiling for the automations were then 45% and 80%, otherwise +5.5% of the average value.

Summertime: A Different Creature

When we're in air conditioning mode for longer stretches (more than a couple days in a row), the humidity variation throughout the house levels out more dramatically than in the heating season. There's still temperature variation, but for this automation we don't care about temperature, just the humidity. When there's so little variation in the overall humidity throughout the house, the fan would run for an extended time to get to that magic setpoint, often hanging out getting stuck just a couple tenths of a percent away from the desired value.

This required a modification to the existing range, and also a "backup" or failsafe end to the runtime.

Look at the Data

Once I knew there was a problem, I spent a few days looking at the chart data. It's difficult to show this in a meaningful way (hence no picture in this post), but what I observed is that aforementioned "getting stuck" point, which was usually within 0.5% of the desired value. I made a simple adjustment to the YAML for the sensor value accordingly:

{% if avghumidity < 40 %}
  46
{% elif avghumidity > 70 %}
  80
{% else %}
  {{ avghumidity + 6 }}
{% endif %}

This minor adjustment would help address that minor variation without making a big impact on the rest of the seasons.

Time for a Backup Plan

It was also time to create the backup/failsafe plan for shutting down the fan. The backup was to create a "max runtime" timer to shut off the fan regardless of other conditions — it would never run longer than this time. This addition boiled down to a couple of steps:

  1. Create a "helper" (timer) in Home Assistant: Mine is set for 90 minutes;
  2. Add this second timer to the "start the timer" automation (I had a separate 20 minute timer that would allow the humidity to rise sufficiently before any other automations would kick in);
  3. Adjust the "human behavior" automation to restart the fan if preemptively shut off: I added a second condition to only restart the fan if the 90 minute timer was still active; and
  4. Add a separate automation to always shut off the fan when the timer ends.

Why 90 Minutes?

In looking at the data, most of the time the humidity level would drop to near the desired value around an hour after the fan was started. I still want the dynamic value to do most of the heavy lifting, but I don't want the thing running for two hours or more. 90 minutes felt like a reasonable balance to get started. It's easy to manipulate the duration of a time if need be in the future.

Does it Work?

100%

When I look at the automations page in Home Assistant, I can see the last trigger time (loosely) for automations side by side. I'm writing this the day after they were last triggered so the times are relative but here's what it says:

  • Bathroom | Fan | Off (by Dynamic Humidity) — the desired automaton trigger — 18 hours ago
  • Bathroom | Fan | Stays On (by Humidity) — the "human behavior" trigger — 19 hours ago
  • Bathroom | Fan | Off (Max Runtime) — the backup trigger — 21 hours ago

There were multiple showers yesterday, so all three of these were run in the same day! My favorite is the "human behavior" one since someone tried to shut it off manually (old habits die hard?), but it noped out of that and then shut it off within an hour later. As it was intended.

Automations like these are super useful, and seeing how they can work together to accomplish the goal is one of many things I love about Home Assistant.