Group switch not updating

I just updated to 2.5.0.RC1 and in habpanel now if I click a group switch item it no longer updates the state unless I reload the page. It will however update the state of the group if I turn on an individual light in the group.

Looking at the log I believe this might be related to not seeing a GroupItemStateChangedEvent when sending the group a command directly. But I do see a GroupItemStateChangedEvent when I interact with a switch directly.

Results from

smarthome:send KTN_LightBulb_01_Switch ON
17:18:09.201 [INFO ] [smarthome.event.ItemCommandEvent     ] - Item 'KTN_LightBulb_01_Switch' received command ON
17:18:09.212 [INFO ] [arthome.event.ItemStatePredictedEvent] - KTN_LightBulb_01_Switch predicted to become ON
17:18:09.218 [INFO ] [smarthome.event.ItemStateChangedEvent] - KTN_LightBulb_01_Switch changed from OFF to ON
17:18:09.219 [INFO ] [home.event.GroupItemStateChangedEvent] - GRP_KTN_Lights changed from OFF to ON through KTN_LightBulb_01_Switch
smarthome:send GRP_KTN_Lights ON
17:22:12.252 [INFO ] [smarthome.event.ItemCommandEvent     ] - Item 'GRP_KTN_Lights' received command ON
17:22:12.255 [INFO ] [smarthome.event.ItemCommandEvent     ] - Item 'KTN_LightBulb_03_Switch' received command ON
17:22:12.262 [INFO ] [smarthome.event.ItemCommandEvent     ] - Item 'KTN_LightBulb_02_Switch' received command ON
17:22:12.267 [INFO ] [smarthome.event.ItemCommandEvent     ] - Item 'KTN_LightBulb_01_Switch' received command ON
17:22:12.271 [INFO ] [arthome.event.ItemStatePredictedEvent] - KTN_LightBulb_03_Switch predicted to become ON
17:22:12.276 [INFO ] [arthome.event.ItemStatePredictedEvent] - KTN_LightBulb_02_Switch predicted to become ON
17:22:12.280 [INFO ] [arthome.event.ItemStatePredictedEvent] - KTN_LightBulb_01_Switch predicted to become ON
17:22:12.284 [INFO ] [smarthome.event.ItemStateChangedEvent] - KTN_LightBulb_03_Switch changed from OFF to ON
17:22:12.285 [INFO ] [smarthome.event.ItemStateChangedEvent] - KTN_LightBulb_02_Switch changed from OFF to ON
17:22:12.286 [INFO ] [smarthome.event.ItemStateChangedEvent] - KTN_LightBulb_01_Switch changed from OFF to ON

Shouldn’t I see a line that says GRP_KTN_Lights changed from OFF to ON? If I check the status of the group it will say the group is on. But without an event I don’t think habpanel knows to update.

How is your Group defined?

Through PaperUI

Not what did you use, how is the Group defined? Did you give it a type (e.g. Switch) other than Group? What is Autoupdate set to? If you set autoupdate to “Veto an autoupdate” than the Group wouldn’t change it’s state in response to the command. That is what appears could be the case as I don’t see the “predicted to become” for the GRP_KTN_Lights. Do you have an aggregation function? If not, I’m not sure the Group state would ever change even in response to a command.

It’s also not clear in the logs what GRP_KTN_Lights was before it received the command. If it was already ON than there’s no change so you wouldn’t see a changed state.

That group has a base type of Switch, a Function of All OFF -> OFF else ON, and an Auto Update of “Enforce an auto update”

GRP_KTN_Lights was OFF before I sent the ON command.

Should I indeed see a change event for a group item? I assume I should, but I’m not positive if that is how it was working before, since I never really checked until something stopped working.

Yes I think so. I do in my events.log at least. But the change isn’t a response to the command, it’s in response to the members changing state.

20│2019-12-11 12:39:40.049 [ome.event.ItemCommandEvent] - Item 'gLights_ALL' received command OFF                                                                                                                         │
20│2019-12-11 12:39:40.054 [ome.event.ItemCommandEvent] - Item 'aFrontLamp' received command OFF                                                                                                                          │
20│2019-12-11 12:39:40.058 [ome.event.ItemCommandEvent] - Item 'aFamilyLamp' received command OFF                                                                                                                         │
20│2019-12-11 12:39:40.058 [ome.event.ItemCommandEvent] - Item 'aFamilyLamp2' received command OFF                                                                                                                        │
20│2019-12-11 12:39:40.066 [ome.event.ItemCommandEvent] - Item 'aPorchLight' received command OFF                                                                                                                         │
20│2019-12-11 12:39:40.070 [ome.event.ItemCommandEvent] - Item 'aMBR_Lights' received command OFF                                                                                                                         │
20│2019-12-11 12:39:40.070 [nt.ItemStatePredictedEvent] - aFrontLamp predicted to become OFF                                                                                                                              │
20│2019-12-11 12:39:40.075 [nt.ItemStatePredictedEvent] - aFamilyLamp predicted to become OFF                                                                                                                             │
00│2019-12-11 12:39:40.110 [nt.ItemStatePredictedEvent] - aPorchLight predicted to become OFF                                                                                                                             │46
20│2019-12-11 12:39:40.113 [nt.ItemStatePredictedEvent] - aMBR_Lights predicted to become OFF                                                                                                                             │
20│2019-12-11 12:39:40.125 [GroupItemStateChangedEvent] - gLights_ALL changed from OFF to ON through aFrontLamp                                                                                                           │
20│2019-12-11 12:39:40.126 [vent.ItemStateChangedEvent] - aFrontLamp changed from ON to OFF                                                                                                                               │
20│2019-12-11 12:39:40.127 [vent.ItemStateChangedEvent] - aFamilyLamp changed from ON to OFF                                                                                                                              │
20│2019-12-11 12:39:40.128 [GroupItemStateChangedEvent] - gLights_ALL changed from ON to OFF through aFamilyLamp2

I notice I’ve got some weirdness going on there too, not sure what that “changed from OFF to ON” is all about, the Group was already ON, but you can see the changed events on the Group gLights_ALL.

So I just made a test group and put one of my kitchen lights into that group as well. When I turn the test group on it turns on my kitchen light and the status of my Kitchen Lights group gets updated automatically on Habpanel. But the switch for the Test Group itself does not update. Not unless I reload the page.

19:26:35.072 [INFO ] [smarthome.event.ItemCommandEvent     ] - Item 'test_group' received command OFF
19:26:35.074 [INFO ] [smarthome.event.ItemCommandEvent     ] - Item 'KTN_LightBulb_01_Switch' received command OFF
19:26:35.080 [INFO ] [arthome.event.ItemStatePredictedEvent] - KTN_LightBulb_01_Switch predicted to become OFF
19:26:35.084 [INFO ] [smarthome.event.ItemStateChangedEvent] - KTN_LightBulb_01_Switch changed from ON to OFF
19:26:35.085 [INFO ] [home.event.GroupItemStateChangedEvent] - GRP_KTN_Lights changed from ON to OFF through KTN_LightBulb_01_Switch

So it seems like updating is only working when a group is not directly called.

If it worked before I suspect it might be due to a regression introduced by https://github.com/openhab/openhab-webui/pull/128 - basically this filters events received to a select few topic patterns (smarthome/items/*/statechanged,smarthome/items/*/*/statechanged,smarthome/webaudio/playurl) since they were supposed to be the only ones relevant to HABPanel: ItemStateChangedEvent, GroupItemStateChangedEvent, and the one to play audio through the webaudio sink.

Can you try querying the events endpoint with curl on your openHAB machine and see if there is any event coming up when you send the command to your group?
curl http://localhost:8080/rest/events

Here are all the events I see when I click the Group Switch “GRP_KTN_Lights”

event: message
data: {"topic":"smarthome/items/GRP_KTN_Lights/command","payload":"{\"type\":\"OnOff\",\"value\":\"ON\"}","type":"ItemCommandEvent"}

event: message
data: {"topic":"smarthome/items/KTN_LightBulb_03_Switch/command","payload":"{\"type\":\"OnOff\",\"value\":\"ON\"}","type":"ItemCommandEvent"}

event: message
data: {"topic":"smarthome/items/KTN_LightBulb_02_Switch/command","payload":"{\"type\":\"OnOff\",\"value\":\"ON\"}","type":"ItemCommandEvent"}

event: message
data: {"topic":"smarthome/items/KTN_LightBulb_01_Switch/command","payload":"{\"type\":\"OnOff\",\"value\":\"ON\"}","type":"ItemCommandEvent"}

event: message
data: {"topic":"smarthome/items/GRP_KTN_Lights/state","payload":"{\"type\":\"OnOff\",\"value\":\"ON\"}","type":"ItemStateEvent"}

event: message
data: {"topic":"smarthome/items/KTN_LightBulb_03_Switch/statepredicted","payload":"{\"predictedType\":\"OnOff\",\"predictedValue\":\"ON\",\"isConfirmation\":false}","type":"ItemStatePredictedEvent"}

event: message
data: {"topic":"smarthome/items/KTN_LightBulb_03_Switch/state","payload":"{\"type\":\"OnOff\",\"value\":\"ON\"}","type":"ItemStateEvent"}

event: message
data: {"topic":"smarthome/items/KTN_LightBulb_02_Switch/statepredicted","payload":"{\"predictedType\":\"OnOff\",\"predictedValue\":\"ON\",\"isConfirmation\":false}","type":"ItemStatePredictedEvent"}

event: message
data: {"topic":"smarthome/items/KTN_LightBulb_02_Switch/state","payload":"{\"type\":\"OnOff\",\"value\":\"ON\"}","type":"ItemStateEvent"}

event: message
data: {"topic":"smarthome/items/KTN_LightBulb_01_Switch/state","payload":"{\"type\":\"OnOff\",\"value\":\"ON\"}","type":"ItemStateEvent"}

event: message
data: {"topic":"smarthome/items/KTN_LightBulb_03_Switch/statechanged","payload":"{\"type\":\"OnOff\",\"value\":\"ON\",\"oldType\":\"OnOff\",\"oldValue\":\"OFF\"}","type":"ItemStateChangedEvent"}

event: message
data: {"topic":"smarthome/items/KTN_LightBulb_02_Switch/statechanged","payload":"{\"type\":\"OnOff\",\"value\":\"ON\",\"oldType\":\"OnOff\",\"oldValue\":\"OFF\"}","type":"ItemStateChangedEvent"}

event: message
data: {"topic":"smarthome/items/KTN_LightBulb_01_Switch/statechanged","payload":"{\"type\":\"OnOff\",\"value\":\"ON\",\"oldType\":\"OnOff\",\"oldValue\":\"OFF\"}","type":"ItemStateChangedEvent"}

event: message
data: {"topic":"smarthome/items/test_group/KTN_LightBulb_01_Switch/statechanged","payload":"{\"type\":\"OnOff\",\"value\":\"ON\",\"oldType\":\"OnOff\",\"oldValue\":\"OFF\"}","type":"GroupItemStateChangedEvent"}

event: message
data: {"topic":"smarthome/items/KTN_LightBulb_01_Switch/state","payload":"{\"type\":\"OnOff\",\"value\":\"ON\"}","type":"ItemStateEvent"}

event: message
data: {"topic":"smarthome/items/KTN_LightBulb_01_Color/state","payload":"{\"type\":\"HSB\",\"value\":\"0.0,0,100\"}","type":"ItemStateEvent"}

event: message
data: {"topic":"smarthome/items/KTN_LightBulb_01_Color/statechanged","payload":"{\"type\":\"HSB\",\"value\":\"0.0,0,100\",\"oldType\":\"HSB\",\"oldValue\":\"0.0,0,0\"}","type":"ItemStateChangedEvent"}

event: message
data: {"topic":"smarthome/items/KTN_LightBulb_02_Color/state","payload":"{\"type\":\"HSB\",\"value\":\"0.0,0,45\"}","type":"ItemStateEvent"}

event: message
data: {"topic":"smarthome/items/KTN_LightBulb_02_Switch/state","payload":"{\"type\":\"OnOff\",\"value\":\"ON\"}","type":"ItemStateEvent"}

event: message
data: {"topic":"smarthome/items/KTN_LightBulb_02_Color/statechanged","payload":"{\"type\":\"HSB\",\"value\":\"0.0,0,45\",\"oldType\":\"HSB\",\"oldValue\":\"0.0,0,0\"}","type":"ItemStateChangedEvent"}

event: message
data: {"topic":"smarthome/items/KTN_LightBulb_03_Color/state","payload":"{\"type\":\"HSB\",\"value\":\"0.0,0,100\"}","type":"ItemStateEvent"}

event: message
data: {"topic":"smarthome/items/KTN_LightBulb_03_Switch/state","payload":"{\"type\":\"OnOff\",\"value\":\"ON\"}","type":"ItemStateEvent"}

event: message
data: {"topic":"smarthome/items/KTN_LightBulb_03_Color/statechanged","payload":"{\"type\":\"HSB\",\"value\":\"0.0,0,100\",\"oldType\":\"HSB\",\"oldValue\":\"0.0,0,0\"}","type":"ItemStateChangedEvent"}

So there is a

data: {"topic":"smarthome/items/GRP_KTN_Lights/state","payload":"{\"type\":\"OnOff\",\"value\":\"ON\"}","type":"ItemStateEvent"}

But the switch doesn’t update in openhab until a page refresh.

Okay, thank you for that, it’s interesting - from what I gathered, when a group’s state changes because one of its members changed, you get a GroupItemStateChangedEvent on the group and a ItemStateChangedEvent on the child item (the use case I tested), but if you send a command to a group, you never get an ItemStateChangedEvent on the group itself, even though its state effectively changes - either because you sent a command, or because the child items’ state change which caused the state of the group to change. You get an ItemStateEvent though, but those are the ones I wanted to filter out, because it’s not useful information since HABPanel maintains the state of all items internally and only state changes are relevant.

It’s probably very confusing, saying it like this, but since the state of the group effectively changed, shouldn’t we get a ItemStateChangedEvent on the group item in this case? (@maintainers?)

Looking at events.log I see GroupItemStateChangedEvent when a Group changes but I never see an ItemStateChangedEvent. I don’t know if that means that the log statement is suppressed or at a lower level for Groups or if that means there is no ItemStateChangedEvent.

2019-12-13 10:13:42.221 [GroupItemStateChangedEvent] - gIndoorTemps changed from 19.1333333333333333333333333333333 °C to 19.10 °C through vNateBR_Temperature

Either would be great, but the problem here seems to be that you don’t get any “changed” (ItemStateChangedEvent or GroupItemStateChangedEvent) events on the group item when you send a command to it (even if it caused its children to change their state).

My example logs from above show the Group gLights_ALL changing in response to a command and it did receive a GroupItemStateChangedEvent in that case when one of it’s members changed. It’s not clear to me why it works for me but not OP.

I should add: I won’t mind HABPanel processing ItemStateEvent again if it helps, but the purpose of https://github.com/openhab/openhab-webui/pull/128 was to avoid having to process those events which in many cases merely “confirm” the current state of an item - it’s a performance hit, causes CPU usage, battery drains etc; for instance, I have several items whose states are set by the HTTP1 binding every few seconds, which means many ItemStateEvents are sent every second even though the state hasn’t changed, those aren’t really useful to process.

This seems … unlikely. Whether you send a command to a group or do something to a member, it will not change the group state directly. Later, if a member updates in response to that command or some other action, then the group will update (and should make an event).
The group has no way to know why that update was triggered, what the original action was.

IIRC the GroupItemStateChangedEvent will be sent if the state of a group item changes through one of its members.

In case we want to trigger an event it should be an ItemStateChangedEvent. Currently the implementation of the GroupItem suppresses the emitment of an event. The setState(State) method overrides the default behavior of an item. According to the JavaDoc on setState(State) in GenericItem this implementation is wrong. Changing the code is not a big deal. Shall I propose a change?

See code in GenericItem and GroupItem.

1 Like

Thanks @cweitkamp for investigating!

I’d say generally speaking, every state change should be reflected in a ItemStateChangeEvent, so I’m in favor of this! :slight_smile:

What I still don’t understand, if we look back at @sovapatr’s example above, when the GRP_KTN_Lights group is switched to ON, we see its members receive the ON command, as expected, and since it causes their state to change, which in turn causes the group’s state to be changed, shouldn’t GroupItemStateChangedEvents be emitted as well?

A command could lead to a change of the state. The group proxies the commands to its members. I do not know the flow in detail but I could imagin that the state of the group has been changed by the command before one of the members state changed …

It shouldn’t. Group state should reflect the aggregation function over it’s members.
(Obviously in real life a Group command may ultimately cause member updates, in turn causing Group update - but it’s not guaranteed)

I suppose it’s arguable. Group states change indirectly (function of members) which is what GroupItemStateChangedEvent reprsents I suppose.
The question becomes is ItemStateChangeEvent supposed to indicate only direct updates, or indirect ones too?
If all updates, what s the purpose of the GroupItemStateChangedEvent - it adds no new knowledge.
Perhaps it is redundant - these decisions were made a long time ago.

That’s what I meant above, apparently even in this case no events (apart from a ItemStateEvent) seem to be emitted on the group, which is abnormal IMHO.