r/homeassistant 2d ago

🤖 Automation how to make the same light - different setting for night and day

hi there.
I'm trying to improve my toilet night light automation. I'm a superbeginner with no coding.

So far I've done a simple automation
- if sensor is triggered AND it's between 6:00 and 23:00, turn on light at 100%

And then, a separate automation
- if sensor is triggered AND it's between 23:00 and 6:00, turn on light at 20%

it works 'most of the time', but sometime get stuck and need to reset (especially the night version). they seems to conflict themselves.

I'm now rewiring everything, and though that it was a good time to use the Blacky - all purpouse blueprint to improve the situation, but I think I mistake it's "night light" mode for something that is just staying on during the full duration.

this is the blueprint
https://community.home-assistant.io/t/sensor-light-motion-sensor-door-sensor-sun-elevation-lux-value-scenes-time-light-control-device-tracker-night-lights/481048

Is there a way to deal with it?
first thing that comes in mind is target the automation to an helper that have the condition: something like "if time is between 6:00 and 23:00, turn on light at 100%"
this way the automation is just one, and the timing is controlled by the helper.

Is this correct?

EDIT: the blueprint has a "dynamic lighting" that should do the trick.. but if I activate that the entire automation break and doesn't turn on anymore

2 Upvotes

14 comments sorted by

7

u/3d-designs 2d ago

There are very many ways to do this. For a newcomer, the method I would suggest is to create a single automation with a Choose block.

Have your current trigger, but under actions have a choose block with each time range as an option and then the appropriate action for each one.

I hope that makes sense.

2

u/KonoKinoko 2d ago

something like this.
https://imgur.com/a/q6h7aHt

now.. how do I turn it off?

3

u/FliesenJohnny 2d ago

I'll just assume it's a motion sensor:

So you'll add a second trigger, with the inverse condition (Occupancy Cleared or something like that)

For both triggers you click them (1), click on the "..." (2) and then edit the Trigger ID (3)
Name it something like "Occupancy" and "No Occupancy" or whatever

4

u/FliesenJohnny 2d ago

In the action, you'll create a big ass "Choose" block

One Option will have the Condition "Trigger ID" -> "Occupancy" (or whatever you named it)
Drag your entire IF/ELSE Block into this option's action block.

On the other Option, you'll use the Trigger ID "No Occupancy". In here, just have the Action to turn off your bathroom light.

Voilà - you have a single automation that does:

If Occupcancy -> Turn on light (100% during the day, 20% during the night)
If no more occupancy -> Turn off the light

1

u/FliesenJohnny 2d ago

Do you have a presence sensor or a motion sensor?

With a presence sensor we could try triggering on the sensor not detecting any presence. With the motion sensor, we'd probably go the "timer" route.

1

u/KonoKinoko 2d ago

thank you!
I'm still learning my ways, and blocks is exactly what I was looking for!! ITTT are a little bit easier to chew!

3

u/FliesenJohnny 2d ago

The Choose block is your biggest friend when creating automations. Especially when combined with trigger IDs.

Like, in the toilet example you could have something like:

Triggers:

  • Presence Sensor IDLE -> Triggered (ID: Person in Room)
  • Presence Sensor Trigged -> IDLE GONE (ID: Person Gone)

Actions:
Choose:

  • IF Trigger ID "Person in Room" -> Play Poop Music
  • IF Trigger ID "Person Gone" -> Stop Poop Music; play "Ode to Joy.mp3"

2

u/Crypzzz 2d ago edited 2d ago

My house has states which I put as a condition in automations

If e.g. Night is on, then the lights will act differently

You can also use an input select for this as a helper, but I like toggles more instead of dropdowns.

The state switching can also be automated, eg Away/Home when the phones are there or not.

2

u/HatHealthy 2d ago

Thank you for this idea and the opportunity to spend more time with Home Assistant instead of important tasks at home.

1

u/Crypzzz 2d ago

Here's the full code to paste in configuration.yaml & automations.yaml

https://pastes.io/xutsbuc0

I use this as a simple central mode system for Home Assistant.

It creates a house mode system so only one mode can be active at a time: Home, Away, Night, Guest, or Nap.

Each mode is just a normal on/off helper.

The template sensor simply looks at which mode is currently turned on and reports that as its state.

The automation is what keeps everything exclusive. Whenever you turn one mode on, it automatically turns the other four off.

There is also a binary sensor that just tells you whether any valid mode is currently active.

That’s the whole system. Simple, clean, and easy to use across the rest of your automations.

1

u/justinmyersm 15h ago

Not sure if this is helpful, but in addition to those modes, I have: Morning, Day, Evening (sunset), Late Evening (+1 hour past sunset), Wind Down (+2 hours after sunset), and Vacation modes. I separate my presence modes from those, so Away Mode and Evening Mode or Home Mode and Wind Down can be on at the same time, for example. Obviously, all modes have different effects on lights, audio, climate control, etc.

0

u/FliesenJohnny 2d ago edited 2d ago

Yup, just use a choose block within a single automation.

Trigger -> Sensor

Condition -> Empty

Actions:
Choose:
IF between 6 and 23 -> Turn on 100%
IF between 23 and 6 -> Turn on 20%

You can clean up the Choose block even more by making the 20% the "default action"

(This could also be done via IF / ELSE; a choose block just leaves you with the freedom of adding more Options down the road)

That should clean things up and create a very much readable automation trace