I have two young kids, a four-year-old and an eighteen-month-old. If you’re a parent, you know that a home with small children is just chaos. Bedtime happens when it happens. If it does. Movie night interrupts everything. Someone wakes up at 5 AM, someone else sleeps until 7. The house needs to keep track.
When I first set up Home Assistant, I did what I suppose everyone does: I created scenes. Morning scene, evening scene, movie scene. For a while it felt like there might be something there, but they kept piling up as I discovered the family’s patterns. After trying to sequence those patterns, I understood what scenes actually are: bookmarks. Say my wife and I start bingeing a series late into the night. The last thing I want when the TV goes off is the living room lighting up all over again. I needed the living room to know that the house had moved into night mode — and to settle back into night, not into the evening it was in when the movie started.
That’s the gap I kept running into. Home Assistant is incredibly powerful at connecting devices and triggering automations. But it lacks any sort of algorithm that could read patterns of use and build a logic out of them. The thing needs to be alive — flowing through moods, with rooms that sometimes diverge from the whole and then gracefully rejoin it.
So I built Mood Controller: a modular system that gives Home Assistant what it was missing — a stateful rhythm that cascades from the house level down to individual rooms, while letting each room keep its own autonomy when it needs it.
Think of it as the “Apple touch” for Home Assistant. It just works the way you’d expect it to.
The Problem: A Missing Rhythm
Home Assistant is superb at connecting and automating devices, but it has no built-in notion of rhythm — no stateful scene management. The challenge shows up the moment you want to override a room’s lighting temporarily and then have it revert to whatever the house is doing now, rather than to whatever it was doing before.
Manual override is the other half of the problem. Out of the box, Home Assistant doesn’t really handle it: once you touch a light by hand, nothing tells the system whether you meant it. Mood Controller makes that intent explicit — a room you’ve overridden stays overridden, and it can even be protected from house-wide mood changes.
The result, from the outside, is just a standard IKEA switch. Press the top button to brighten the lights, the bottom one to turn them off. In either case, another press hands the room back to the rhythm of the house.
Just that. A Zigbee switch that finally behaves the way I expect. I turn on the lights, the house moves through all its phases without disturbing me, and when I leave the room, after five minutes with no motion, it finds its way back into the rhythm.
The Core: Moods and Presets
At its heart, Mood Controller embodies a state-centric hierarchical automation philosophy, where moods cascade from the house level down to individual rooms, yet each space retains the autonomy to maintain its own state when needed. The system uses minimal helpers that serve dual purposes as both configuration points and memory, ensuring your home can gracefully recover from any disruption.
The key insight is that family life operates on two levels simultaneously. The first level is the mood — the general ambiance of the home tied to the rhythm of the day. The second level is the preset — temporary overrides for specific needs within a room, without breaking the overall flow.
Scenes gave me the first level. What was missing was the second level: the ability to say “I need this room brighter right now, but when I’m done, bring it back to the mood of the house at the current time.”
Moods
These are high-level, home-wide scenes that define the general ambiance. They are the primary states of the home. You can create as many as you need. My personal implementation uses five principal moods tied to the time of day:
- Morning: Calm and easy light to start the day
- Day: Working lighting for daytime activities
- Evening: Warm, comfortable lighting for early evening and cooking
- Unwind: Softer lighting for relaxation and bedtime reading
- Night: Dim, gentle lighting for nighttime
Presets
These are variations or modifications of a Mood, often used for manual control within a room without changing the underlying Mood. This allows for manual alternatives within the current mood without breaking the overall rhythm. My standard presets are:
- default: The intended lighting scene for the mood.
- bright: A brighter version of the current mood’s scene.
- off: Turns the lights off in the specified area.
This two-tiered system allows for both powerful, home-wide automation and intuitive, manual control via physical switches or dashboards.
Usage Examples
Here are some examples of how to call the mood_set script in your automations or dashboard actions.
# Change the mood of one or multiple areas
- service: script.mood_set
data:
target_areas:
- living_room
- kitchen
mood: unwind
# Sync all rooms to the current home mood.
- service: script.mood_set
data:
mood: "{{ states('input_text.home_mood') }}"
transition_time: 30
# Sync a specific room to the home mood.
# Useful for after an override,
# like when a movie finishes.
- service: script.mood_set
data:
target_areas:
- living_room
mood: "{{ states('input_text.home_mood') }}"
transition_time: 5
# Refresh all rooms to their current state.
# This reverts any manual light changes
# that were made outside of the mood system.
- service: script.mood_set
# Refresh a single room.
- service: script.mood_set
data:
target_areas:
- kitchen
# Set specific rooms to a new mood and preset.
- service: script.mood_set
data:
target_areas:
- bedroom
- children
mood: night
preset: default
# Toggle a preset for a physical switch.
# This call sets the kitchen to bright.
# If it's already bright, it toggles
# to the default preset.
- service: script.mood_set
data:
target_areas:
- kitchen
toggle: true
preset: bright
How It Works: The Setup (4 Steps)
1. The Helpers: input_text.home_mood
The system relies on a few key components: Home Assistant helpers for state storage, a control script, and individual scripts for each mood.
State is stored using input_text helpers. This makes the current mood and preset of any area instantly accessible to other automations.
| Helper | Type | Scope | Description |
|---|---|---|---|
input_text.home_mood |
input_text |
Global | Stores the current active Mood for the entire home. |
input_text.area_id_mood |
input_text |
Per Area | (Optional) Stores the current Mood for a specific area (e.g., input_text.kitchen_mood). |
input_text.area_id_preset |
input_text |
Per Area | (Optional) Stores the current Preset for a specific area (e.g., input_text.kitchen_preset). |
input_boolean.area_id_lock |
input_boolean |
Per Area | (Optional) A lock to prevent an area from being changed by home-wide Mood calls. |
Tip: You can still control areas that do not have dedicated
input_texthelpers. If you callmood_setwith notarget_areas, it will target all areas in your Home Assistant instance. For areas without helpers, it will apply the requested mood using thedefaultpreset. This is a great way to have secondary areas (like hallways or closets) follow the main home rhythm without needing their own complex state management.
2. The Controller: script.mood_set
This is the central nervous system of the entire setup. It is responsible for interpreting requests, determining which areas to change, and dispatching commands to the appropriate mood scripts.
- target_areas: The area(s) to apply the mood to. If left empty, applies to all unlocked areas.
- mood: the desired lighting mood (e.g., "morning", "off", "cozy").
- preset: optional override for brightness/configuration level (e.g., "bright", "dim").
- toggle: If true, toggles between the specified preset and 'default' when an area is already in the target preset state.
- transition_time: number of seconds for light transition (default: 2).
The “Smoking Gun”: Dynamic Script Execution
The core of this system’s flexibility comes from using Jinja2 templates to dynamically call scripts. A single action can trigger any mood script based on a variable, allowing for infinite scalability.
- variables: mood_script: "script.mood_{{ states('input_text.home_mood') }}" - service: "{{ mood_script }}" data: target_areas: "{{ areas }}" preset: "{{ preset }}" transition_time: "{{ transition_time }}" alias: Call the mood script continue_on_error: trueThis makes the system infinitely extensible. To add a new mood, you simply create a new
script.mood_[newmood]and the system will handle it automatically.
3. The Automation: automation.home_mood_change
When the input_text.home_mood helper changes, it calls script.mood_set to propagate that change to all unlocked rooms. The beauty of it is that if you use any “Do not disturb” or “Away” mode, you can disable the automation so that it does not trigger. You can keep updating the input_text.house_mood to keep the moods flowing. When you turn on the automation, it will automatically propagate the mood to all unlocked rooms and keep your home just like you want it.
alias: Home mood change
description: It call script.mood_set when input_text.home_mood change
triggers:
- input_text.home_mood
to: null
trigger: state
entity_id:
- automation.home_mood_change
from: "off"
to: "on"
conditions:
entity_id: script.mood_set
state: "off"
alias: This prevent possible infinite loop with mood_set
actions:
metadata: {}
data:
mood: "{{ states('input_text.home_mood') }}"
transition_time: 30
mode: restart
4. The Mood: script.mood_{mood_name}
The Individual Mood Script Architecture
Each mood requires its own script (e.g., script.mood_morning). This script defines the specific scenes for each preset within that mood.
The script is structured into three main sections:
- Preset-Agnostic Actions: A parallel block where you can define actions that should run for a room whenever this mood is set, regardless of the preset. This is ideal for setting things like speaker volume.
- Preset Logic: A
chooseblock that routes to the requested preset (default,bright,off, etc.) and applies the specific light settings for that preset in each targeted room. - Home Wide Actions: A final section that runs only if the mood was applied to the entire home. This is useful for setting global variables, like a home-wide music playlist.
(See the GitHub repository for complete mood script templates.)
Practical Examples of Mood Rhythm
In my own home, I’ve created automations that define when moods change based on time, activity, and environmental data. This gives the house a rhythm that adapts fluidly throughout the day.
Here’s how my moods typically shift:
- Morning: Set after 6:30 AM once motion has been detected for more than 45 seconds in three key rooms. This only applies if the current home mood is Night, helping the home gently transition into the day.
- Day: Activated when outdoor illuminance rises above 4200 lux, but only if the current mood is Morning or Evening.
- Evening: Triggered either at 4:30 PM or when outdoor light drops below 1000 lux in the afternoon, and only if the current home mood is Morning or Day.
- Unwind: Turns on at 6:30 PM. It’s a family cue that it’s time to start the evening routine with the kids.
- Night: At 10:30 PM, the house transitions into Night mood, turning off unnecessary lights and notifications.
How the System Lives Throughout the House
- Speaker volumes adjust automatically depending on the current mood — quieter at night, livelier during the day.
- Motion-based lighting automations are mood-aware: for example, they don’t reactivate lights during Night or when the preset is Off.
- Energy-saving logic: If a room is in the Bright preset and no motion is detected for 15 minutes, it reverts to the room’s default preset.
- Mood transitions are smart: If a room is in
Morning | Brightand the house mood shifts to Evening, the room adopts the new mood while keeping the Bright preset. - Notifications are silenced when the home is in Night mood — no interruptions.
Advanced Features
Area Locking
The system includes a locking mechanism to prevent mood changes in sensitive areas. If an input_boolean.[area_id]_lock is on, any mood_set call that targets a group of areas will automatically exclude the locked area.
Tip: A call made specifically to a single locked area will still go through. This is the desired behavior for in-room controls, allowing someone in a locked room to still adjust their own lights.
Performance Optimization
To ensure fast execution, script.mood_set intelligently groups areas by their required mood and preset combination. If 4 rooms need Morning/default and 1 room needs Morning/off, the script doesn’t make 5 individual calls. It makes two optimized calls. This significantly reduces overhead and execution time.
Event Hook: mood_setted
At the end of its execution, script.mood_set fires a custom event named mood_setted. This event includes all relevant parameters — such as the targeted areas, mood, preset, and whether the change is home-wide — allowing other automations to react dynamically.
- event: mood_setted
event_data:
target_areas: "{{ areas_resolved_unlocked }}"
mood: "{{ mood_resovled }}"
preset: "{{ preset_resolved }}"
is_homewide: "{{ is_homewide }}"
Tip: I have a script that on birthdays or special occasions found in a calendar, it will call a script bound to that occasion and overwrite some lights after the moods have been set.
Real-World Automation Examples
The true power of this system is unlocked through automation. Because the state of every room is always known and stored in helpers, you can create highly specific and intelligent automations.
Motion-Based Night Light
Turns on a dim light in the kitchen upon motion, but only if the kitchen is in the Night mood and default preset. When motion clears, it gracefully returns the room to the standard Night scene.
(Full YAML available in the GitHub repository.)
Movie Time
Locks the living room when the projector turns on. When media plays, it sets the living room into movie mode. After a 30-second pause, the living room syncs back with the home mood. When the projector turns off, the living room gets unlocked and returns to whatever mood the house is in now — not whatever it was when the movie started.
This is the automation that convinced me the system was working. The house moved from Evening to Night during a two-hour movie, and when I turned off the projector, the living room gently faded into Night — not back to Evening. That’s rhythm.
Morning Routine
Each room transitions to Morning individually as motion is detected. When all main rooms have reached Morning, the whole home officially shifts. This means if one parent is up early with the baby, the kitchen wakes up softly without blasting light into the bedroom where the other parent is still sleeping.
Children’s Room Lock
Automatically locks the children’s room during Night and Unwind moods, preventing home-wide transitions from accidentally lighting up a room where a child is sleeping. When the mood changes to something else, the room unlocks and syncs back with the home.
What I Learned Building This
Mood Controller started as a way to solve a lighting problem, but it taught me something bigger about how systems should work. The best automation isn’t the one that does the most — it’s the one you forget is there. When the house just feels right without anyone touching a switch, that’s when you know the system is working.
The architecture behind this — state hierarchies, dynamic dispatch, event hooks, area autonomy — isn’t specific to Home Assistant. It’s a pattern that applies wherever you need to manage complex, overlapping states in a system that serves humans. I’ve used the same thinking to build modular web frameworks and I’m starting to apply it to physical computing projects like automated growing systems.
If you’re a Home Assistant user frustrated by the limitations of scenes and scripts, I hope this gives you a foundation to build on. The full code, templates, and documentation are on GitHub:
github.com/ZeFish/hass_mood_controller
If you have questions, ideas, or improvements — open an issue or reach out. I’d love to hear how you adapt this to your own home’s rhythm.
Francis Fontaine is a developer and photographer based in Québec City. He builds modular systems for the web (stnd.build) and for the physical world, and believes the best technology is the kind that disappears into the background of daily life.