Turn on switch when 1 or more items (in group) are active

I’m looking for an example of how one would accomplish this.

I Have some exterior lights, some of them are dimmers, some are switches. They are all members of the same group (exterior).
what I’d Like to do is have another switch item that turns on if 1 or more of the exterior lights are active(meaning either ON or >=1%) and off if all the exterior lights are off.

Anyone know of an example that might point me in the right direction?

without giving you the full answer (the actual rule code), i will give you some ideas on how to implement this:
a) Use different subgroups (with a proper function) for each item type. Put all Dimmer items in a Dimmer Group (e.g. gExterior_Dim) and all Switch items in a Switch Group (e.g. gExterior_Sw)
b) Write a rule that checks the state of the 2 groups (filter through the members or simply check the state for number of active members) and evaluate the 2 Group states: if Switch Group has state ON (or >=1) or Dimmer Group has state >=1% (or >=1) fire the next rule condition (turn on the target switch)

Reason: If you group together different types of items with an aggregate fucntion, the Group state could become UNDEF.
You can always put these 2 subgroups in a larger group (gExterior).

More info on Groups here: http://docs.openhab.org/configuration/items.html#group-type

edit: You could try to use a Group:Number type on the gExterior… that should give you the number of active member items as the state.

To provide the code that does what Dim describes with a slight variation:

You can create a Switch Item that get linked to or bound to your Dimmer Items. Those Switches will be set to ON if the Dimmer is > 0%. With that the code would become

Group:Switch:Count ExteriorSwitches
rule "Exterior Lights Status"
when
    Item ExteriorSwitches changed
then
    if(ExteriorSwitches.state > 0) {
        // turn on your switch
    }
    else {
        // turn off your switch
    }
end

I personally think that the cost of a few extra Switches more than pays for the simplification you get above by avoiding an extra Group for the Dimmers and the code necessary to process both Groups.

The state of ExteriorSwitches will be the number of lights that are ON.

2 Likes

Thank you so much, I have much better understanding now. I can’t wait till I have time to try it out

Just FYI you can do this via the paperUI provided all your things are defined there with a few clicks
The ‘Function’ field gives you exactly what you want. That’s how I have implemented this and it works just fine