I’ve recently started using groups for status reporting (battery levels, devices offline, etc.) and I’ve noticed that adding an existing item (“Garage temp sensor battery level”) to a group (“Batteries”) changes the state of the item to NULL. In many cases, this is fine, as it gets corrected soon, but in some cases, these values are updated very infrequently (less than once / day).
Is this expected behavior?
Is there a workaround?
The log doesn’t seem to reflect the change to NULL – presumably it is written to reflect the change in group membership
2023-03-05 13:26:22.981 [INFO ] [openhab.event.ItemUpdatedEvent ] - Item 'BasementWaterSensor_BatteryLevel' has been updated.
2023-03-06 01:34:56.849 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'BasementWaterSensor_BatteryLevel' changed from NULL to 100
2023-03-06 01:34:56.854 [INFO ] [hab.event.GroupItemStateChangedEvent] - Item 'BatteryGroup' changed from NULL to 100 through BasementWaterSensor_BatteryLevel```
I haven’t tested this, but either the newly added item has a NULL state, or it could be a bug in openhab. A workaround, if it’s a bug, would be to just update that newly added item to its own state, perhaps that might work.
These aren’t newly added items, they’ve been there a year or more. When you go too edit item, the value shows (I e. “100”, then after adding to the group, it displays NULL.
I just did a quick test and cannot replicate the problem you’re describing.
Here’s what I did
I started with two items and a group
Group:Number:SUM Numbers
Number Number1 (Numbers)
Number Number2 (Numbers)
openhab> status Numbers
0
openhab> status Number1
NULL
openhab> status Number2
NULL
openhab> status Numbers
0
openhab> update Number1 1
Update has been sent successfully.
openhab> status Numbers
1
So at this point, the group Numbers is 1 even though Number2 is NULL
Then I added Number3 to the mix:
openhab> status Number3
NULL
openhab> status Numbers
1
openhab> update Number3 2
Update has been sent successfully.
openhab> status Numbers
3
It’s behaving as expected. FTR though I’m doing this on openhab 4.0-snapshot, although I’d imagine it works the same way on 3.4.x
The UI also shows NULL at this point, but I didn’t capture it before the binding flipped it back to ON (I chose to test with something that gets refreshed regularly)
Oh wait, now I did it the same way you did - I edited the item and added a group to the item instead of adding the item to the group. And yes the item became NULL.
I’m not seeing the same behavior. Maybe there is something different in how I did my steps.
Created TestSwitch and toggled it to OFF
Create TestGroup:Switch:AND(ON, OFF)
Navigated to the Item and added it to the Group
NOTE: I did all this through the UI, I’m using file based syntax above for convenience.
Here are the logs:
20│2023-03-15 12:23:00.117 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'TestSwitch' changed from NULL to ON │
20│2023-03-15 12:23:06.466 [INFO ] [openhab.event.ItemCommandEvent ] - Item 'TestSwitch' received command OFF │
20│2023-03-15 12:23:06.467 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'TestSwitch' changed from ON to OFF │
20│2023-03-15 12:25:06.682 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'TestSwitch' changed from NULL to OFF │
20│2023-03-15 12:25:06.683 [INFO ] [openhab.event.ItemUpdatedEvent ] - Item 'TestSwitch' has been updated. │
20│2023-03-15 12:25:06.767 [INFO ] [hab.event.GroupItemStateChangedEvent] - Item 'TestGroup' changed from NULL to OFF through TestSwitch │
20│2023-03-15 12:25:19.588 [INFO ] [openhab.event.ItemCommandEvent ] - Item 'TestSwitch' received command ON │
20│2023-03-15 12:25:19.590 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'TestSwitch' changed from OFF to ON │
20│2023-03-15 12:25:19.590 [INFO ] [hab.event.GroupItemStateChangedEvent] - Item 'TestGroup' changed from OFF to ON through TestSwitch │
20│2023-03-15 12:25:25.789 [INFO ] [openhab.event.ItemCommandEvent ] - Item 'TestSwitch' received command OFF │
20│2023-03-15 12:25:25.791 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'TestSwitch' changed from ON to OFF │
20│2023-03-15 12:25:25.791 [INFO ] [hab.event.GroupItemStateChangedEvent] - Item 'TestGroup' changed from ON to OFF through TestSwitch │
That first line happened when I initially created the Item, which is kind of weird, as is the change from NULL to OFF. I should note I’m on OH 4.0 SNAPSHOT #3368
I haven’t tried this with a SWITCH yet, but it’s happening for me with both CONTACT and NUMBER groups. So far, my groups have included aggregation functions.
Rich, in your log, you’ll notice that there’s an un-noted change from OFF to NULL when the ItemUpdatedEvent occurs. This corresponds to what I’ve seen in my cases.
I noticed this because some of my battery levels only update when there’s motion, and there’s been no one home for an extended time.
Fourth statement change from NULL to OFF which corresponds to be toggling it from the UI to ensure it had a state, and this is the weird one which I did note above.
Sixth statement change from NULL to OFF for the TestGroup which corresponds to the TestSwitch changing to OFF and the aggregation function populating the Group’s state.
In all three cases the change is from NULL, not to NULL.
So there is something that is changing the state of the Item to NULL without generating an event, which I didn’t even think was possible. But it seemed to do it after I sent the command from the UI and it eventually settled on the correct state. It doesn’t remain NULL and in this case it’s only null for a hundred msecs or so.
It’s the fifth line that I think is the culprit. My “I’ve never looked at the code, but if I had to guess” theory is that the call to create the group membership for the item is somehow wiping out the value as an unintended side effect.
I cannot replicate this error at all on 4.0M1. I’ve tried the sequence both with a unlinked switch item and an switch item linked to a channel. I see no intermediate null values.