this post was submitted on 11 Jun 2025
1 points (100.0% liked)

Home Assistant

412 readers
2 users here now

Home Assistant is open source home automation that puts local control and privacy first. Powered by a worldwide community of tinkerers and DIY...

founded 2 years ago
MODERATORS
 
This is an automated archive made by the Lemmit Bot.

The original was posted on /r/homeassistant by /u/ZaFish on 2025-06-10 23:04:19+00:00.


https://github.com/ZeFish/hass_mood_controller

Hey, r/homeassistant!

Like many of you, I love Home Assistant for its power to connect everything. But I always felt something was missing—a kind of "rhythm" for my home's lighting. The problem was this: I’d set the perfect "Evening" mood across the house, then start a movie in the living room which triggers a special "Movie" scene. When the movie ends, I don't want the lights to go back to what they were before the film; I want them to sync up with the current home-wide mood, which might have transitioned to "Night" while I was watching.

Over time, I created this script that began as a proof of concept but after a year it became my own Home Assistant Mood Controller, a scripting system that brings stateful, hierarchical control to the lighting. It ensures my home's atmosphere is always in sync with our daily routine.

TLTR BEGIN

It’s like having metadata for your areas. Some sort of exif data that you find in jpg that contain information like camera and lens model. Only this time it is information about a room. Based on that information you can change the action of your switches and do pretty much all you ever desire in automation.

TLTR END

The Core Idea: Moods and Presets

The system is built on a simple two-tiered philosophy: Moods and Presets.

Moods are the high-level, home-wide scenes that define the general ambiance. They are the primary states of your home. My setup uses five moods based on the time of day:

  • Morning: Calm, easy light to start the day.
  • Day: Bright, functional lighting.
  • Evening: Warm, comfortable lighting.
  • Unwind: Softer lighting for relaxation.
  • Night: Very dim, gentle lighting.

Presets are variations of a Mood, used for temporary, room-level control without breaking the overall rhythm. I use those in my physical room switches. The standard presets are:

  • default: The main scene for the current mood.
  • bright: A brighter version of the current scene.
  • off: Turns the lights off in that specific area.

This means you can have the whole house in the Evening mood, but temporarily set the kitchen to the bright preset for cooking, all with a single, consistent system. I've also added a toggle feature so a single button on a physical switch can toggle between "bright" and "default". That mean I can always have a nice ambiance while being able to have working light anytime and since those are on switches, it is easy for people to use.

How It Works: The 4 Key Parts

The whole system is built on a few core components that work together:

  1. ⁠⁠⁠⁠State Helpers (input_text): The current mood and preset for the home and each individual area are stored in input_text helpers. This is the magic that makes the system "stateful"—any other automation can instantly know the exact state of any room.
  2. ⁠⁠⁠⁠The Controller (script.mood_set): This is the central script that does all the work. You call it with the area, mood, and preset you want. It's the only script you ever need to interact with directly.Here's how you'd call it to sync the living room back to the main house mood after a movie:
action:
      - service: script.mood_set
        data:
          target_areas: living_room
          mood: "{{ states('input_text.home_mood') }}"

  1. ⁠⁠⁠⁠The Automation (automation.home_mood_change): A simple automation that watches the main input_text.home_mood helper. When that helper changes (e.g., from Evening to Night), it calls script.mood_set to propagate that change to all the rooms in the house (that aren't locked).
  2. ⁠⁠⁠⁠The Mood Scripts (script.mood_{mood_name}): This is where you define what your lights actually do. For each mood (like Morning), you create a script that defines the scenes for each preset (default, bright, etc.). The controller script dynamically calls the correct mood script based on the variables you pass.

Some features that I needed over time

  • Area Locking: Have a room you don't want to be affected by house-wide changes (like a sleeping baby's room)? Just turn on an input_boolean.[area_id]_lock. The system will skip it, but you can still control the room's lights with local controls.
  • Performance Optimized: The script is smart. If you tell it to set 4 rooms to default and 1 room to off, it makes two optimized calls instead of five, which keeps things fast.
  • Event Hook: The controller fires a mood_setted event when it's done, so you can hook in other automations for even more advanced control.

Automation Ideas (My recent rabbit hole!)

Because the state of every room is always known, you can create some really intelligent automations

Movie Time Automation

This automation locks the living room when the projector turns on. When a movie starts playing, it sets a special "Movie" mood. If you pause for more than 30 seconds, it syncs the lights back to the current house mood, and when the movie is over, it unlocks the room and restores the home mood.

alias: Movie
triggers:
  - trigger: state
    entity_id: - media_player.projector
    to: playing
    id: Playing
  - trigger: state
    entity_id: - media_player.projector
    to: idle
    id: Stop
    for: "00:00:30"
  - trigger: state
    entity_id: - binary_sensor.movie_mode
    to: "off"
    id: Projector Off
actions:
  - choose:
      - conditions:
          - condition: trigger
            id: Playing
        sequence:
          - action: script.mood_set
            data:
              target_areas: - living_room
              mood: Movie
      - conditions:
          - condition: trigger
            id:
              - Stop
              - Projector Off
        sequence:
          - action: script.mood_set
            data:
              target_areas: - living_room
              mood: "{{ states('input_text.home_mood') }}"

Motion-Based Night Light

This only triggers if the kitchen is already in the Night mood. If motion is detected, it switches to a special motion preset (a dim light). When motion stops for 2 minutes, it sets the preset back to default (the standard Night scene).

alias: Kitchen - Night - Motion
trigger:
  - platform: state
    entity_id: binary_sensor.kitchen_motion_occupancy
    to: "on"
    id: "Detected"
  - platform: state
    entity_id: binary_sensor.kitchen_motion_occupancy
    to: "off"
    for: "00:02:00"
    id: "Cleared"
condition:
  - condition: state
    entity_id: input_text.kitchen_mood
    state: "Night"
action:
  - choose:
      - conditions:
          - condition: trigger
            id: "Detected"
        sequence:
          - service: script.mood_set
            data:
              target_areas: - kitchen
              preset: motion
      - conditions:
          - condition: trigger
            id: "Cleared"
        sequence:
          - service: script.mood_set
            data:
              target_areas: - kitchen
              preset: default

On a practial level...

I have one automation for each mood that know the rhythm that I like.

Morning : Is set after 6:30 when tree principal room had motion for more than 45 seconds. At that time, the house get into Morning mood and all the rooms follow. It only apply in the morning when the current home mood is Night.

Day : This one is actually only set when the outdoor luminance is above 4200 and the current home mood is either Morning or Evening

Evening : This one get set when outdoors illuminance gets above 1000 in the afternoon or at 4:30pm and only when the current home mood is Morning or Day

Unwind : This one goes on at 6:30pm, it let my kids know if time for night routine

Night : at 10:30pm the home goes into night mood

Other things I like to do with that stateful lighting system

  • My speaker volume follows the mood
  • I get many motion automation based on the current mood of the room
  • When any room is in preset bright without motion for more than 15 minutes, it goes back to preset default
  • When the rooms are in the preset off, i make sure there is no motion automation that can turn the light back on
  • If a room is currently in morning|bright and the house mood change to evening, the room will follow the house mood but will keep it's preset so will go to evening|bright
  • Remove all the notification when the house is in mood Night

I've put together a github with the full code, setup instructions, and more automation examples. https://github.com/ZeFish/hass_mood_controller

I'd love to hear what you think! Has anyone else built a similar system?

no comments (yet)
sorted by: hot top controversial new old
there doesn't seem to be anything here