Adding items to a group sets state to NULL

Using 3.3.0 on Raspbian

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

That’s a different order.

Create the item
Set a value
Create the group
Add the item to the group
Item value is now NULL

I haven’t used Karaf except to restart bindings. Can you do “insert item in group” from the console?

Oh I misunderstood your case.
I tried reproducing this again using code but it doesn’t exhibit the behaviour you described.

Here’s my code (written in jruby)

items.build do
  number_item "NumberA", state: 1
  group_item "NumberGroup"
end
logger.info NumberGroup.members.include?(NumberA) # => false
logger.info NumberA.groups.include?(NumberGroup) # => false
NumberGroup.add_member(NumberA.java_object)
logger.info NumberGroup.members.include?(NumberA) # => true
logger.info NumberA.groups.include?(NumberGroup) # => true
logger.info NumberA.state # => 1

The logger shows the state as “1”.

Can you provide something that I can execute/try to reproduce on my system?

I’m doing everything from the UI:

(Edit item)
(Add to group testGroup)

openhab> status ThermostatCave_Connected                                                                                                                                                                                             
ON

(Save)

openhab> status ThermostatCave_Connected                                                                                                                                                                                             
NULL

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)

I also just tried this from the UI, and the item didn’t change to NULL.

I suspect you may have a rule somewhere that caused this.

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.

@rlkoshak could you verify this please?

  • Create an Item
  • Set its state
  • create a Group
  • Go to the Item (not the group), and set the item’s group membership to the created group
  • Now the item’s state is null

It is fine when I first went to the Group, and added the item to the group.

1 Like

Thanks for following through @JimT, and for pointing out the workaround.

I’m not seeing the same behavior. Maybe there is something different in how I did my steps.

  1. Created TestSwitch and toggled it to OFF
  2. Create TestGroup:Switch:AND(ON, OFF)
  3. 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 created the group without aggregate functions. Just a plain group.
Through UI, on oh4 snapshot

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.

NULL only appears in three of my log lines:

  1. First statement change from NULL to ON
  2. 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.
  3. 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.

Regardless an issue needs to be filed I think.

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.

Adding the Group was a red herring!

Merely going to EDIT then SAVING the item would cause this issue. It has nothing to do with Group memberships at all.

I am on 4.0.0-SNAPSHOT - Build #3371 (after M1)

Steps to reproduce

  • Go to Items, click an item
  • Click Edit (top right)
  • Click Save
  • Item state is now NULL
3 Likes

@ysc is this a bug in MainUI or in core?