Implement a scene in a rule

Is there any way to set different lights to different states in a single rule? Like, when a rule fires, it would set bulb A to be 2400 and 50% brightness, bulb B to 2300 and 40% brightness, and bulb C to 2500 and 45% brightness. Basically, I want a rule to set a scene.

It looks like a rule can only set most state properties to a single value for a group of lights; like, I can set the temperature of a bunch of lights to 2300, but I can't set some to 2300 and some to 2400. The only exception appears to be light level, but even then you can only configure two different values (some lights can be at one dimness, and some lights can be at another).

Not in a single rule per se. But you can create actions, such as set B to 2300 40%, and another for C to 2500 45%. Then one rule can do the A to 2400 and 50% and run those two actions also.

Hmmmā€¦Iā€™ll have to experiment with that. It would be nice if an ā€œActionsā€ rule (or any rule) could could contain multiple sets of actions (multiple instances of the ā€œSelection Actionsā€ block). The thing Iā€™m trying to avoid is (in the worst case) ending up with a separate rule for every light in every scene, in which case my rules list would be pretty huge.

Maybe Iā€™m just not in the proper mindset yet, and itā€™ll be easy.

1 Like

Yes, RM is probably not the right tool for this use case.

By what mechanism do you intend to activate such a scene?

A rule. For example, at a certain time of day, a Good Morning rule fires, and the lights in the house should be set to a particular configuration. Same thing in the evening, or at night, or when the house gets very dim during the day.

There are very few groups of lights where it makes sense for me to turn them all on to the same light level (because of brand differences and light location). I could use a scene handling app, but I like the conceptual simplicity of doing most everything through a rules engine.

That was one of the things I liked most about CoRE when I started using it ā€” I could include multiple sets of actions in a piston. Itā€™s not all that conceptually different from having a RM rule call multiple other ā€œactionsā€ rules, but thereā€™s something to be said for not having all the child rules in the top level app RM rule list.

2 Likes

I understand. You know, RM was the precursor to CoRE. Compared to CoRE, itā€™s rather simple and provides a rule engine at a basic level. Its design intentionally avoided complexity to the extent possible, while CoRE pursued a more ambitious level of complexity.

There is no likelihood that we will fundamentally redo the design of RM. WebCoRE has been ā€œportedā€ to Hubitat by members of the community, as befits its name. Choice is good.

It does occur to me that it would be easy to add a scene capability much as you describe to Simple Lighting. That is why I was curious about how you want to activate a scene. A simple approach would be to ā€œcaptureā€ a scene in a Simple Lighting rule. You would set the various selected lights to their desired settings, then hit a capture button. Then, when that SL rule was triggered, the lights would be set to those levels and colors. This would avoid the ui complexity of multi-light setup, while giving all of the benefits you are seeking in a scene. Such ā€œscenesā€ could entail lights to be turned on, off, set to some level, set to some color temperature, or set to some color ā€“ depending on the capabilities of the selected devices. Rather than these details being selected in the app ui, they would be captured by the app when the capture button is hit. Given that Simple Lighting supports the types of triggers you mentioned, and many others, this feature would cover a large set of scene use cases.

3 Likes

I used RM before CoRE, and then CoRE when RM was pulled, then webCoRE when that came out. I like RMā€™s level of simplicity, and Iā€™m fine with it not going the direction of CoRE. Thereā€™s a lot of power in being able to build complex behaviors out of simple building blocks. Itā€™s possible that a few additional blocks would be handy, though. :slight_smile:

I could see using Simple Lighting to set scenes, with a virtual switch to tie it to RM (RM turns on switch, Simple Lighting rule fires). That would certainly be easier in many cases than having to manage the states of individual lights. Iā€™d still want to use RM for the actual triggering logic, though, because Simple Lightingā€™s triggers are prettyā€¦well, simple. Like, you can only trigger on one thing.

I do still think allowing a rule to contain multiple action blocks would provide a decent amount of flexibility without requiring a significant change to how RM works (basically, a rule would have an array of associated ā€˜actionā€™ descriptors instead of a single action descriptor).

3 Likes

I dug up an old copy of Scene Machine and implemented something along these lines. I have a parent/child setup: Scene Manager and Scene. A Scene just lets you pick a bunch of lights and records their current state (on/off and level) when it updates. Each Scene also creates a corresponding virtual momentary contact switch (a simple custom device) that can be used to trigger the scene. Now RM can just hit the proper switch to engage a scene. It doesn't handle color temp yet, but otherwise it seems to work pretty well.

1 Like

One bit of oddness I ran into ā€“ refresh isnā€™t synchronous, so when I refresh a bunch of Hue lights before grabbing their state, the refreshes havenā€™t always completed by the time I actually look at the state values. If I add a 1000ms pause between the refresh and any state accesses, things seem to be up to date.

Is there any way to wait for a command to complete?

I tried this, but maybe Iā€™m not getting all of it. I was looking for a device in the form of a virtual switch by the same name and I couldnā€™t find it.

I can see this being very useful for all automation and button apps. If possible could you make the scene controller a separate entity instead of attached to simple Lighting?

A manual adjustment mode after capture would be a great addition as well
@bravenel

Thatā€™s not part of the regular Scene Machine. Hereā€™s my modified Scene app:

It uses this momentary switch class:

2 Likes

Would that scene support "Turn on this light at sunset then turn off thsat same light at sunset +20 and turn on lights." ?

No. My scene app lets you create scenes with associated momentary switches, where a 'scene' is some light configuration (turn these lights on at this level, and these other lights at this level, and turn these lights off). Turning on the switch will set the scene.

To manage the scene at some time, you could use a Rule Machine rule -- just turn on the scene's switch with whatever conditions you want to use.

Hi Jason0x43,
awesome that you make this scene app. I am also going to try it!

Edit:
Ok, I installed the scene app and got an error that required to install scene manager. parent: 'jason0x43:Scene Manager
And then the scene app and the switch driver could be installed.
But when trying to install the scene in the app page..I only see scene manager which only allows changing the light level and no colors at all.

Am I missing something? Where is the scene app itself? Strange.

Thanks and I hope to have it working soon with your help!

So, you need to add the code for both apps to your Hubitat, but you only need to install an instance of the Scene Manager. This app is used to create scenes, each of which is a child instance of the Scene app.

As far as light configuration goes, right now you can add individual lights or groups of lights and configure the on/off state and light level of each group. I don't currently have color state management in there because I use a separate app to manage the color temperature of my lights.

If other people use this app and want color management, I can see about adding it. (An earlier version of the app did handle colors, but I removed that support during a refactor.)

I would love to have the color also added to it for each separate bulb.
Pretty please? :slight_smile:

I added the ability to specify the color temperature or hue + saturation for each group. Try that out,

1 Like

Hi @jason0x43,
Awesome! This is exactly what I need and my wife will finally be happy as well. I will give it a try for sure. I will keep you posted. Many thanks!

I tested the scenes...perfect just what I needed! I am very happy with this! This should become a build in app for Hubitat in my opinion. Scenes were also much demanded for SmartThings. So Hubitat will be more popular with Scenes!
Thanks again @jason0x43!