Bathroom lighting features by time of day?

I have been trying to bring an idea to reality using rule Machine but haven't been having much luck so I thought I'd try here.

I have the following bathroom light devices:
Kasa Switch (wifi)
Sengled rgbw light bulb (zigbee)
ZooZ motion sensor (Zwave)

All are setup within HE and work well.

What I want to do is have the bulb and switch work.normally (switch turns.on/off light bulb) between sunrise and midnight.

BUT between midnight and sunrise I want the motion sensor to turn on the light bulb and it should be red (30%)

I have been able to get the motion sensor to turn the light on between midnight and sunrise AND it is red.

The issue is that I need to make sure that the light switch is left on after midnight so the bulb will have power to do so.

Is there a way to set up a timer that would turn on the switch at midnight so that when the motion sensor detects motion the bulb can come.on? But then turn off the switch at sunrise so it can be use in a standard way?

Hope I explained this clearly I have a rule that I have been tweaking and trying to get it to work but no luck. I can add screen caps of it will help.

Thanks as always.

Might ask to go back a step.... Are you saying that the Kasa switch provides power to the Sengled Zigbee bulb? I would have thought normally a zigbee bulb was left with power continually provided, then turned on / off via a hub like HE? If my assumptions about your setup are correct, what are you trying to achieve by having a switch controlling power to the smart bulb?


It doesn't look like those Kasa switches have the ability to decouple the relay control from the paddle. For a lot of smart switches, there's a "smart bulb" type configuration that lets you disable power control with the paddle. That's ideal for smart bulbs as it makes sure they are always powered. You then just setup rules to control the bulb directly with paddle presses.

You have a few options. It looks like you can set a schedule for the switch directly in the Kasa app. That would allow you to have the switch turn on midnight-sunrise. You could then just use a rule in HE turn handle bulb on/off with motion.

Alternatively, you can set the switch schedule using a simple automation rule. Then setup another rule for the lights with motion.

The gap would be, what state is the bulb in when the switch turns on. You'll need to address that too. I presume the bulb turns back on when power is restored (switch is turned on). Both propositions above would have the bulb come on with the switch at midnight.

My first inclination would be to setup the motion rule in rule machine. That way, you can write it to say "at 12:01 am, turn off the bulb" and a second statement for handling turning the light on with motion the remainder of the night.


I'm trying to account for manual use.of the switch. In the case that someone would turn the light off manually after using the bathroom now there is no power to the bulb. For when the motion sensor would turn on the bulb between midnight and sunrise

THat makes sense.... but I expect either the switch needs to control the bulb rather than the power to the bulb, or the bulb adjusted to be a "dumb" bulb....


You're going to have headaches with that switch and what you want to do. I can attest from experience. A much better option would be to swap out the Kasa switch with something like a Zooz ZEN26. With those, you can disabled the paddle controlling power. It will still send the z-wave message for the paddle being pressed, so you can write a simple automation rule to sync the bulb with the switch. That would completely get rid of the problem of someone killing power to the bulb on accident.

If you don't want to take that route, I imagine I can draft something up to help nudge you along, but I'm thinking this will take a bit of debugging to get it dialed in. The biggest hurdle will be figuring out how quickly after power is restored that the bulb will start processing commands. That may be "immediate" from a human perspective, but could be a 250 ms gap from the computer side of the house which will influence how the rules are written.

Either way, I'm thinking that you're going to have some "weirdness" in the experience. You can write a rule to turn the switch back on if someone turns it off, but that will most likely result in the bulb also coming on. So, then you add a line to the rule to turn the bulb back off. There's still going to be a small window that the bulb will flick back on.


Thanks for all of the information and suggestions. I will mess with it this weekend and report back . Very helpful (as always!)

1 Like

OK. Its been over a month since I last posted regarding this inquiry, I think that I got it working but need to tweak it (questions to follow)

Recap: I was looking for a way to have the light in the toilet area of the bathroom be a manual operation with white light during the day and a motion activated red light between midnight and sunrise.

Here is what I did:
As advised on this thread I set the switch to turn on at 12a (via the Kasa App)

I used HE Rule Machine to set the mode from to test mode (this mode name will change) at 12:01a (back to Night mode after a minute)

I created another rule that turns off the bulb when the mode is changed to test mode.

This works as designed: all day the light switch is off and can be used to manually turn on/off the toilet area switch (white lighting)
At midnight the switch turns to an ON state and the bulb comes on.
At 12:01 the mode is changed and the lightbulb turns off.

Success!! (well kinda) Here are the followup questions I have.

Is there a way for me to edit the code to make the time the bulb turns off less than a minute? (i.e. 12a switch comes on and at 12:00:05a the bulb turns off) ?

Currently when the light is turned out between sunrise and midnight it is a warm white. I want it to be a cool white (too match the color of other bulbs in the bathroom) Is it just a matter of setting the 'SET COLOR COMMAND' to cool white?
Will that setting stick? Will it throw off the rule i have set to turn the bulb red when motion is detected between 12a and sunrise?

I am pretty sure I tried this setting in all of the testing I have done but am going to try again. Thought Id ask the knowledgeable community anyway.

Thanks for all of the advice/help and time spent o this thread. I used the info to get to where the automation is now. I am happy enough with it but just want to tweak it to get it closer to exactly where I want it.


Replace test_light with your switch (assuming you have it added through the Kasa integration) and master bath pooper light with your bulb. This takes care of color management and what-not. You'll just need a second rule to turn the light on with motion and turn the light off after motion stops.

1 Like

Thanks for the suggestion. I will give this a try. Id love to have less rules for one solution. Ill let you know how it turns out.

@FriedCheese2006 That worked well!! Such a cleaner solution than my patchwork one. As always thanks for the time!!!

1 Like