[SOLVED] One slider to control them all (hue lights)

I’m trying to use one slider to control the brightness of different hue lights seperately. So I have 5 lights for instance. I have a slider on the left, and I added 5 buttons, representing each light.

What I’d like, is to be able to select a light using one of those buttons, and then use the slider to contorl the brightness.

    Dimmer   LR_Light1_Brightness "Brightness" ({channel="hue:0220:00178812ef2f:1:brightness"}
    Dimmer   LR_Light2_Brightness "Brightness" ({channel="hue:0220:00178812ef2f:2:brightness"}

I tried to use a string item LightName

String LightName "LR_Light1_Brightness "

to store the selected dimmer items name (e.g. ‘LR_Light1_Brightness’) when the button for light 1 is selected. This part works.

Then I used the string item as the item to be controlled from the slider. This part doesn’t work. It’s probably not possible to do it like this, but has anybody got an idea that could work?

To be clear: I don’t want a slider that works on a group of lights; I want to be able to control 5 lights seperately, with one slider, depending on the selected light.

Ok, you need a dummy item linked to the dimmer on the UI

Dimmer myDimmer

Then a rule:

rule "DImmer command to selected light"
when
    item myDimmer changed
then
    if (LightName != NULL) {
        sendCommand(LightName.state.toString, myDimmer.state.toString)
    }
end

This sounds like a good use case for dynamic Group membership.

You can change an Item’s Group membership through Rules.

Given:

Group:Dimmer ControlLights
Group:Switch EnableControl
Dimmer   LR_Light1_Brightness "Brightness" {channel="hue:0220:00178812ef2f:1:brightness"}
Switch LR_Light1_Brightness_Enable (EnableControl)
...
import org.eclipse.smarthome.model.script.ScriptServiceUtil

rule "Light enabled/disabled"
when
    Member of EnableControl received command
then
    val light = ScriptServiceUtil.getItemRegistry.getItem(triggeringItem.name.replace("_Enable", "")
    if(receivedCommand == ON) ControlLights.addMember(light)
    else ControlLights.removeMember(light)
end

Put ControlLights on your sitemap or HABPanel as a Dimmer/Slider/Whatever is appropriate and all of the Switches. As you toggle the Switches the Items will be added/removed from ControlLights and they will respond to the commands sent to ControlLights.

Thanks @vzorglub! I didn’t know that you could have dummy objects, thats very helpfull.

@rlkoshak this suits my needs even better. I’ll have a go at this one, thanks!

should it not work like this for a JS rule?

items.getItem("Group Name").removeMember(items.getItem("Item Name"));

Not quite, though 6 years ago there wasn’t a JS Scripting.

In JS Scripting there’s

items.Item_Name.removeGroups("Group_Name");

Always check the docs if what you first try doesn’t work.

1 Like

Thank you.
Always struggeling with the docs. Where can I find java script class library?
I tried the JS script, but get following log message:

Could not update element with key EG_Wohnen_Beleuchtung_Weihnachtsbaum_Switch in ManagedItemProvider, because it does not exist.

Does this not work with filebased defined items?

The add-on docs includes the full reference. JavaScript Scripting - Automation | openHAB

File based Items may be read only. Everything wise that’s fine based certainly is read only.

Personally, I never really liked dynamic group membership and find the semantic model, item metadata, and tags to be more flexible.

Maybe you have a better idea for my use-case?
I have an equipment defined as a power outlet in my semantic model. If I switch on “Christmas Mode” this power outlet should be removed from my semantic model (not visible in the UI anymore) and a new Item should be created as a light (same channel as the removed power outlet), added to the semantic model and additionally into the group “all living room lights”.
As a result: it’s not only about visualization in the UI, during christmas the power outlet is switched by the the light group, the rest of the year the power outlet is just switched on it’s own.
Of course if christmas mode is switched off, it goes the other way around.
Would it be possible somehow with tags/metadata?

I have a similar use case. During Christmas I’ve a could of almost plus that control lights. The rest of the year the same plugs control humidifers.

So first of all, it’s not the what plug that is being controlled, it’s the humidifier or lights. So I have two items, one for each device. Both items are linked to the same channel. Both Items have appropriate semantic tagging.

I have a separate Switch Item called “TisTheSeason” which I flip ON when the lights are set up and OFF the rest of the year.

The behavior of the two Items is controlled by separate rules from everything else. So, for example, instead of having the light Item be a member of a Lights Group, I’ve a rule that triggers when the lights group receives a command and forward that command to the light. There is another set of rules to control the switch based on the measured humidity.

When TisTheSeason changes to ON, the humidifier rules are disabled and the light rules are enabled. When it changes to OFF the light rules are disabled and the humidifier rules are enabled.

Both Items have custom default list item widget metadata so that the light Item is only visible when TisTheSeason is ON and the humidifier Item is only visible when it’s OFF.

everything about this smart plug flips when it’s put to a new purpose over the holidays, the rules, the UI, etc.