How to control bulbs based on times of day and button

New here and new to home automation. Got my Hubitat yesterday and this is the first thing I want to get set up. I have this running on SmartThings using WebCore. There are 4 pistons that handle this.

In my basement, I have two Hue bulbs named Side and Main.

Piston 1
The Side bulb comes on based on a time at 5:00 AM.

Piston 2
The Side bulb turns off based on a time at 9:00 PM.

Piston 3
Here is the button functionality.
The button controls both lights (Side and Main).
If I press the button and both lights are on, set a variable to turn them off.
If I press the button and both lights are off, set the same variable to turn them on.
If I press the button and only one light is on, then...
-> If the time of the day is between 5:00 AM and 8:00 PM set the variable to turn them on.
-> If the time of the day is between 8:00 PM and 5:00 AM set the variable to turn them off.

Now based on the variable the following will happen.

If the variable is set to turn off
-> Turn Main off
-> If time is between 5:00 AM and 7:30 AM or between 5:00 PM and 8:00 PM
--> Set dimmer of Side to 20%
-> Else turn Side off.

If the variable is set to turn on
-> Turn both lights on
-> If time is between 5:00 AM and 8:00 AM
--> Set level of both to 95% and temperature to 4348K
-> If time is between 8:00 AM and 4:00 PM
--> Set level of both to 95% and temperature to 5900K
-> If time is between 4:00 PM and 5:00 AM
--> Set Main level to 80% and temperature to 2700K
-> If time is between 4:00 PM and 7:30 PM
-- > Set Side level to 80% and temperature to 2700K
-> If time is between 7:30 PM and 5:00 AM
--> Set Side level to 70% and temperature to 2200K

Piston 4
If Side is On
-> If time is 8:00 AM
--> Set level of Side to 95% and temperature to 5900K
-> If time is 4:00 PM
--> Set level of Side to 80% and temperature to 2700K
-> If time is 7:30 PM
--> Set Side level of Side to 70% and temperature to 2200K

If Main is On
-> If time is 8:00 AM
--> Set level of Side to 95% and temperature to 5900K
-> If time is 4:00 PM
--> Set level of Side to 80% and temperature to 2700K

Thank you all for any light :slight_smile: you can shed on how I can accomplish this.

I figure that Piston 1 and Piston 2 will be triggers in my solution. I've created those and have them paused for now.

Wow. There's a lot going on there. In WC, you are benefitting by effectively being able to have multiple pistons in one, so I think this is going to take a lot of RM rules to duplicate. I'm trying to work my way through to make sure I understand what you're trying to do. I'll respond again in a bit, unless someone else does first.

A virtual switch should be able to take the place of your variable.

Thank you @destructure00 Yeah. It was easy to do it in WC. I figured I would need a few (lots?) rules or triggers or rule/triggers but...

None of it seems that complicated, it's just a ton of different time periods and each is dependent on whether a variable is true or false. I tried to do a quick count and I'm seeing 18-ish new rules in your future :rofl:

18-ish is that it? :smiley:
I just attempted to set up one trigger with a restriction (only when on) to change the temperature of the Side bulb at a certain time and failed. I think I don't understand the restriction.

Post a screenshot of what you built.

The name doesn't match the Trigger b/c I was just trying things out.
But I just noticed something. I went in to edit the rule and came back out. Take a look at the third screen. The restricted option is not on. It was on when I first created.

image

There's some nuance that has to do with when a rule shows restricted on the apps page and when it doesn't. I can't remember the details, but from what I do remember it doesn't update in real time, so I don't typically worry about whether or not it shows restricted unless I actually open the rule.

That said, if you are only wanting the trigger to run at 7:15 when the bulb is already on, that seems like it should work. Not sure why it wouldn't.

Personally I don't like to use restrictions unless absolutely necessary. Restrictions effectively disable the rule so nothing is evaluated or run when the restrictions are in effect. This can become a problem when you have a rule or triggered rule with True/False states, and also can cause problems with delayed actions. Again, in this particular case I don't see the problem, but it might be worth changing your restriction to a condition by converting your Trigger to a Triggered Rule, then moving the restriction to a condition.

So it would look like the following

Trigger:
Time is 7:15

Condition:
Switch is on

Rule:
Switch is on

Actions when True:
Set bulb level and color

The trigger fires fine the first time. What I tried next is changed the time of the trigger for a few minutes later. Then turn off the lamp off from my dashboard. The triggered when fired again a few minutes later, turn the lamp on. So it ignored the fact that it was off. When I reset the time of the trigger I did it for a few minutes later since I know there is a 60 second polling that happens to get the status of the bulbs.

So the bulb doesn't update it's status in real time? What kind of bulb? And what is doing the 60 second polling? Hubitat doesn't poll automatically, if you have a non-updating device and haven't configured anything to poll, it won't ever be updated automatically.

It is a Hue bulb. I read in another thread that when a Hue bulb status changes Hue doesn't report that so HE is polling for information every 60 seconds. I don't have the thread open anymore though, sorry.

Gotcha, I don't know much about Hue bulbs or how they work...don't have any myself. I'm assuming they are paired to the Hue hub, not directly to Hubitat?

Correct. Paired to the Hue hub for performance reasons.

This is what I have now. Once again I turned off the lamp from the dashboard. At 7:45 when the rule ran, the light when on which of course is not what I want.

Yea using restrictions I've made 1 really smart button by my bedroom door.
Each rule looks at it's time restrictions and the state of the main light which controls the group I call "main lighting".

Okay. It is working now without me making changes. I'm wondering if there was something wrong with the network.

Ok let's see how much work we can make for you :stuck_out_tongue:

I didn't make any attempt here to check the logic to see if it can be made more efficient since there's so much going on, just tried to duplicate what you already have in webCoRE.

All of this assumes that your Hue bulbs are updating their on/off states correctly...if they aren't updating then that's a different issue that needs to be addressed before these will work correctly.

Also, as I explained above, I prefer to use Triggered Rules instead of Triggers with restrictions whenever possible. If you're more comfortable with Triggers and restrictions, you could change the conditions to restrictions in several of these. I just listed them out how I would do them.

I think these two can be combined into a single Rule.

  • Condition: Time between 5am and 9pm
  • Rule: Time between 5am and 9pm
  • Actions when True: Turn on side bulb
  • Actions when False: Turn off side bulb

For starters, you'll need to create a Virtual Switch to take the place of your variable.

Then I think you're going to need 4 Triggered Rules:

Triggered Rule 1:

  • Trigger: Button Pushed
  • Condition: Main Bulb, Side Bulb (all) on
  • Rule: Main Bulb, Side Bulb (all) on
  • Actions when True: Turn off virtual switch

Triggered Rule 2:

  • Trigger: Button Pushed
  • Condition: Main Bulb, Side Bulb (all) off
  • Rule: Main Bulb, Side Bulb (all) off
  • Actions when True: Turn on virtual switch

Triggered Rule 3:

  • Trigger: Button Pushed

  • Conditions:
    -- Main Bulb, Side Bulb (all) on
    -- Main Bulb, Side Bulb (any) on
    -- Time between 5am and 8pm

  • Rule:
    -- Main Bulb, Side Bulb (any) on
    -- AND
    -- NOT(Main Bulb, Side Bulb (all) on)
    -- AND
    -- Time between 5am and 8pm

  • Actions when True: Turn on virtual switch

Triggered Rule 4:

  • Trigger: Button Pushed

  • Conditions:
    -- Main Bulb, Side Bulb (all) on
    -- Main Bulb, Side Bulb (any) on
    -- Time between 8pm and 5am

  • Rule:
    -- Main Bulb, Side Bulb (any) on
    -- AND
    -- NOT(Main Bulb, Side Bulb (all) on)
    -- AND
    -- Time between 8pm and 5am

  • Actions when True: Turn off virtual switch


If I'm reading this right, you are wanting these actions to take place whenever the variable changes? This needs a Trigger and a Triggered Rule

Trigger:

  • Trigger: Virtual Switch turns off
  • Actions: Turn off Main Bulb

Triggered Rule:

  • Trigger: Virtual Switch turns off

  • Conditions:
    -- Time between 5am and 7:30am
    -- Time between 5pm and 8pm

  • Rule:
    -- Time between 5am and 7:30am
    -- OR
    -- Time between 5pm and 8pm

  • Actions when True: Dim Side Bulb to 20%

  • Actions when False: Turn off Side Bulb


I'm seeing 1 Trigger and 5 Triggered Rules here:

Trigger

  • Trigger: Virtual Switch turns on
  • Actions: Turn on Side Bulb, Main Bulb

Triggered Rule 1

  • Trigger: Virtual Switch turns on
  • Condition: Time between 5am and 8am
  • Rule: Time between 5am and 8am
  • Actions when True:
    -- Dim Side Bulb, Main Bulb to 95%
    -- Set color temperature Side Bulb, Main Bulb to 4348K

Triggered Rule 2

  • Trigger: Virtual Switch turns on
  • Condition: Time between 8am and 4pm
  • Rule: Time between 8am and 4pm
  • Actions when True:
    -- Dim Side Bulb, Main Bulb to 95%
    -- Set color temperature Side Bulb, Main Bulb to 5900K

Triggered Rule 3

  • Trigger: Virtual Switch turns on
  • Condition: Time between 4pm and 5am
  • Rule: Time between 4pm and 5am
  • Actions when True:
    -- Dim Main Bulb to 80%
    -- Set color temperature Main Bulb to 2700K

Triggered Rule 4

  • Trigger: Virtual Switch turns on
  • Condition: Time between 4pm and 7:30pm
  • Rule: Time between 4pm and 7:30pm
  • Actions when True:
    -- Dim Side Bulb to 80%
    -- Set color temperature Side Bulb to 2700K

Triggered Rule 5

  • Trigger: Virtual Switch turns on
  • Condition: Time between 7:30pm and 5am
  • Rule: Time between 7:30pm and 5am
  • Actions when True:
    -- Dim Side Bulb to 70%
    -- Set color temperature Side Bulb to 2200K

This will become 3 Triggered Rules:

Triggered Rule 1

  • Trigger: Time is 8am
  • Condition: Side Bulb is on
  • Actions when True:
    -- Dim Side Bulb to 95%
    -- Set color temperature of Side Bulb to 5900K

Triggered Rule 2

  • Trigger: Time is 4pm
  • Condition: Side Bulb is on
  • Actions when True:
    -- Dim Side Bulb to 80%
    -- Set color temperature of Side Bulb to 2700K

Triggered Rule 3

  • Trigger: Time is 7:30pm
  • Condition: Side Bulb is on
  • Actions when True:
    -- Dim Side Bulb to 70%
    -- Set color temperature of Side Bulb to 2200K

Did you mean to set level and color of Main Bulb instead of Side Bulb here?

This will become 2 Triggered Rules:

Triggered Rule 1

  • Trigger: Time is 8am
  • Condition: Main Bulb is on
  • Actions when True:
    -- Dim Main Bulb to 95%
    -- Set color temperature of Main Bulb to 5900K

Triggered Rule 2

  • Trigger: Time is 4pm
  • Condition: Main Bulb is on
  • Actions when True:
    -- Dim Main Bulb to 80%
    -- Set color temperature of Side Main to 2700K

I ran into a problem with the Virtual Switch.

Scenario

Lights are Off
I press the button
Lights come on
From the dashboard, I turn one of the lights off
I press the button
Nothing happens. The reason that nothing happens, I think, is that the Virtual Switch is still on from the first time.

Of course, I can't set the Virtual Switch to off when I turn off the light from the dashboard since that will turn the other light off too.

What I ended up doing, for now, is execute actions from the push button events. Some of these have restrictions. I tried to execute rules instead of actions but the True part of the condition would always get executed and the false part never did.

I don't know if there is a better way to get around the V-Switch not being reset.

When one light is on and the other is off, there's a time component to whether or not the VS turns on or off when you press the button. Is it not doing what you wanted? Also need to check to be sure the hub is receiving the bulb on/off states since those are conditions to be evaluated when the button is pressed. If the hub doesn't know the correct state of the bulb, it won't run the right actions.