[SOLVED] Flapping state of Group Switch item

Hi all,

I have a strange behaviour of a group switch:

Group:Switch:AND(ON,OFF) CorridorSwitch  "Lichtschalter Flur" <switch> (Corridor)

Switch  Corridor1_Toggle (CorridorSwitch)      { channel="hue:0220:1:corridor_bulb_1:brightness" }
Switch  Corridor2_Toggle (CorridorSwitch)      { channel="hue:0220:1:corridor_bulb_2:brightness" }
Switch  Corridor3_Toggle (CorridorSwitch)      { channel="hue:0100:1:corridor_bulb_3:brightness" }
Switch  Corridor4_Toggle (CorridorSwitch)      { channel="hue:0100:1:corridor_bulb_4:brightness" }

The Group switch is defined as AND.

When I switch it to “ON” the following is logged:

2019-03-09 14:18:52.888 [ome.event.ItemCommandEvent] - Item 'CorridorSwitch' received command ON
2019-03-09 14:18:52.896 [ome.event.ItemCommandEvent] - Item 'Corridor3_Toggle' received command ON
2019-03-09 14:18:52.918 [ome.event.ItemCommandEvent] - Item 'Corridor4_Toggle' received command ON
2019-03-09 14:18:52.924 [ome.event.ItemCommandEvent] - Item 'Corridor1_Toggle' received command ON
2019-03-09 14:18:52.933 [ome.event.ItemCommandEvent] - Item 'Corridor2_Toggle' received command ON
2019-03-09 14:18:52.964 [nt.ItemStatePredictedEvent] - Corridor3_Toggle predicted to become ON
2019-03-09 14:18:52.972 [nt.ItemStatePredictedEvent] - Corridor4_Toggle predicted to become ON
2019-03-09 14:18:52.976 [vent.ItemStateChangedEvent] - Corridor3_Toggle changed from OFF to ON
-----> 2019-03-09 14:18:52.980 [GroupItemStateChangedEvent] - CorridorSwitch changed from ON to OFF through Corridor3_Toggle <-----
2019-03-09 14:18:52.984 [vent.ItemStateChangedEvent] - Corridor4_Toggle changed from OFF to ON
2019-03-09 14:18:52.986 [nt.ItemStatePredictedEvent] - Corridor1_Toggle predicted to become ON
2019-03-09 14:18:52.990 [nt.ItemStatePredictedEvent] - Corridor2_Toggle predicted to become ON
2019-03-09 14:18:52.993 [vent.ItemStateChangedEvent] - Corridor1_Toggle changed from OFF to ON
2019-03-09 14:18:52.997 [vent.ItemStateChangedEvent] - Corridor2_Toggle changed from OFF to ON
2019-03-09 14:18:53.001 [GroupItemStateChangedEvent] - CorridorSwitch changed from OFF to ON through Corridor2_Toggle

Please see the -----> marked row where the Item state is switching back.

When I set up the Group switch as “OR”

Group:Switch:OR(ON,OFF) CorridorSwitch  "Lichtschalter Flur" <switch> (Corridor)

and switch it to “OFF” the following is logged:

2019-03-09 14:25:31.819 [ome.event.ItemCommandEvent] - Item 'CorridorSwitch' received command OFF
2019-03-09 14:25:31.830 [ome.event.ItemCommandEvent] - Item 'Corridor3_Toggle' received command OFF
2019-03-09 14:25:31.845 [ome.event.ItemCommandEvent] - Item 'Corridor4_Toggle' received command OFF
2019-03-09 14:25:31.856 [ome.event.ItemCommandEvent] - Item 'Corridor1_Toggle' received command OFF
2019-03-09 14:25:31.864 [ome.event.ItemCommandEvent] - Item 'Corridor2_Toggle' received command OFF
2019-03-09 14:25:31.876 [nt.ItemStatePredictedEvent] - Corridor3_Toggle predicted to become OFF
2019-03-09 14:25:31.905 [nt.ItemStatePredictedEvent] - Corridor4_Toggle predicted to become OFF
2019-03-09 14:25:31.916 [nt.ItemStatePredictedEvent] - Corridor1_Toggle predicted to become OFF
2019-03-09 14:25:31.928 [nt.ItemStatePredictedEvent] - Corridor2_Toggle predicted to become OFF
2019-03-09 14:25:31.954 [vent.ItemStateChangedEvent] - Corridor3_Toggle changed from ON to OFF
-----> 2019-03-09 14:25:31.960 [GroupItemStateChangedEvent] - CorridorSwitch changed from OFF to ON through Corridor3_Toggle <-----
2019-03-09 14:25:31.964 [vent.ItemStateChangedEvent] - Corridor4_Toggle changed from ON to OFF
2019-03-09 14:25:31.967 [vent.ItemStateChangedEvent] - Corridor1_Toggle changed from ON to OFF
2019-03-09 14:25:31.970 [vent.ItemStateChangedEvent] - Corridor2_Toggle changed from ON to OFF
2019-03-09 14:25:31.973 [GroupItemStateChangedEvent] - CorridorSwitch changed from ON to OFF through Corridor2_Toggle

Please see again the -----> marked row where the Item state is switching back.

I have a rule “CorridorSwitch changed from ON to OFF”.

No matter how I define the switch, the rule gets triggered twice.

Any idea?

Please send also the rule :slight_smile:

That’s quite normal. The recalculation of the group state is triggered by Corridor3_Toggle changing. At this point, Corridor1,2,4 are still ON, so you get group state ON.
After a short while, the group state recalculation will be triggered again by another member changing, and again after that probably.

The part that is unclear is why your Group was at state OFF before you sent any command.

Hi again,

@Udo,
to avoid any flaw in the rule causing the issue I simple reduced it to

when CorridorSwitch changed from ON to OFF
send telegram message
end

so the rule is not the problem :slight_smile:

@rossko57,
what you say seems correct.
E.g. in the upper scenario:
Toggle 3 changes first to “ON” and recalculates the group. As the group is defined as “AND” and the others are still “OFF” the group changes back to “OFF”.
Toggle 4 and 1 are next, recalculate the group as “OFF” and find it as “OFF” already so that does not trigger another change of the group.
Toggle 2 is last, finally finds the group as “ON” and sets CorridorSwitch to “ON”.

This is the behaviour, but is this the desired behaviour?

It makes any “changed from … to …” rule useless.

Oh, I’d missed that you’d been changing between AND and OR functions.

I don’t quite follow your last example there. AND as a group function, works with part in brackets. AND(ON,OFF) means that if all members are ON then set group state ON. Otherwise, set it OFF.
The group will still go OFF if all members are OFF, that is to say it is not a logical AND.

You will get multiple updates when changing a group member. Updates do not necessarily cause a change, of course. That’s just how the mechanism works.

In your case, you are changing multiple members at much the same time. You’re definitely going to get multiple updates! And it’s all going to happen chaotically in parallel. The system does not stop and wait for the effects of one event before taking the next action.

It all depends what you do in the rule. You may need to wait a little for group state to settle down, if you are causing multiple changes for example.

The puzzle from your two examples at the top here, is why your group was in the “wrong” state to begin with. Had you just edited the group? I don’t think state gets recalculated until some member changes.

Sorry but that was a classical beginner’s mistake.

If I put my rule as “received command OFF” rather than “changed from ON to OFF” that only reacts on the initial command and ignores the status changes in between.

@Udo again,
It was the rule :flushed:

Let’s all get back to sleep.

No, its fine. It is certainly worth considering the choice of rule trigger carefully, it all depends what you need.
For example, your new rule listening for a group command won’t respond to someone/something changing an individual member. Which might be what you want, of course.

Your original listening for change (rather than update) is fine. The unexpected part comes from group being in “wrong” state to begin with somehow - I think was just a consequence of in-flight edits.

When using a trigger Item myGroupItem received command the rule will trigger myGroupItem.members.size times.
There is another option, though: Member of myGroupItem received command will trigger once for each item that received a command.

Careful Udo, I’m pretty sure there is only one command event directly for the Group Item.