[SOLVED] Reducing the impact of turning off MANY lights? How to optimise

Group command concern arises from that.

Yes, but not from the script
 :wink:

[clipse.smarthome.model.script.alloff]

I had to because in my habpanel code, it dynamically populates the lights from a group, and the item.type I could only get working as a Switch

as per this:

<div class="widget" ng-if="item.type=='Switch' && itemValue(item.name)=='ON'" ng-click="sendCmd(item.name, 'OFF')">

I have a mix of switches and dimmers, so for this to work I’d need to have

 item.type=='Switch' && item.type=='Dimmer' && itemValue=(item.name=='ON'

" but i couldnt get it to function :frowning:

No, you need a different version:

 (Lights instanceof SwitchItem || Lights instanceof  DimmerItem) && Lights.state == ON

An Item can’t be Switch and Dimmer the same time :wink:

1 Like

Sorry, I mean in my HabPanel code (not the rule code you’re speaking of). The rule works, I just need to try and remove the duplicate switch items for each dimmer device but display both in my habpanel code (as not every light is a dimmer)

Ah, sorry, didn’t get this point. I don’t use HABpanel (yet), so unfortunatley I can’t help here.

No trouble! Looks like I spoke too soon.

I went ahead and removed the nested groups , by adding my switches & dimmer items into ‘gAllLights’ for simplicity

The rule however still sends commands of OFF to all lights :frowning:


rule "Turn off all lights"
when
        Item gAllLights received command OFF
then
        gAllLights?.allMembers.forEach[ AllLights |
      if (AllLights instanceof SwitchItem && AllLights.state == ON) {
         AllLights.sendCommand(OFF)
      } else if (AllLights instanceof DimmerItem && AllLights.state > 0) {
         AllLights.sendCommand(OFF)
      } //else if any other type we do nothing
]
end

Yes because you send the command to the group, openHAB will cascade the command to members.
OpenHAB does that REGARDLESS there is a rule for that trigger or not.

Understood, so the proxy solution is the only option for the rule trigger

rule "Turn off all lights"
when
        Item Proxy_gAllLights received command OFF
then
        gAllLights?.allMembers.forEach[ AllLights |
      if (AllLights instanceof SwitchItem && AllLights.state == ON) {
         AllLights.sendCommand(OFF)
      } else if (AllLights instanceof DimmerItem && AllLights.state > 0) {
         AllLights.sendCommand(OFF)
      } //else if any other type we do nothing
]
end

Yes

1 Like

Definitely. And then this rule should also work:

rule "Turn off all Lights"
when
    Item proxyAllLights received command OFF
then
    gAllLights?.allMembers.filter[Lights | !(Lights instanceof GroupItem) && Lights.getStateAs(OnOffType) == ON ].forEach[ LightsON |
        LightsON.sendCommand(OFF)
    ]
end

If there are no more groups in gAllLights, the code can be simplified to:

rule "Turn off all Lights"
when
    Item proxyAllLights received command OFF
then
    gAllLights?.members.filter[Lights | Lights.getStateAs(OnOffType) == ON ].forEach[ LightsON |
        LightsON.sendCommand(OFF)
    ]
end
2 Likes