Group item not really OFF after changing state to OFF

Hi,

today I had the effect that a group of motion detectors was not switched to OFF although all members in that group were OFF. The log told that the group changed to OFF but the rule was not triggered. So I read the item’s state from the Karaf console, seeing that the group state stil was ON although all member items had the state OFF.

Only when I switched off the group item manually the rule “Presence check” checked the correct state depending on that item.

Here’s an extract from the event log:
2018-01-23 08:16:00.487 [vent.ItemStateChangedEvent] - KitchenMotion changed from ON to OFF
2018-01-23 08:16:04.718 [vent.ItemStateChangedEvent] - LivingroomMotion changed from ON to OFF
2018-01-23 08:17:06.711 [vent.ItemStateChangedEvent] - LivingroomMotion changed from OFF to ON
2018-01-23 08:17:37.703 [vent.ItemStateChangedEvent] - LivingroomMotion changed from ON to OFF
2018-01-23 08:17:44.193 [vent.ItemStateChangedEvent] - CorridorMotion changed from ON to OFF
2018-01-23 08:19:28.789 [vent.ItemStateChangedEvent] - BathroomMotion changed from ON to OFF
2018-01-23 08:19:28.792 [GroupItemStateChangedEvent] - gIndoorMotion changed from ON to OFF through BathroomMotion

Here you can see that all members of gIndoorMotion had changed to off so that as an result the log says that gIndoorMotion changed to OFF, too.

But it wasn’t really as I could see in item’s state in Karaf. Then I switched the group off manually. After that the group state was correct and the “Presence check” was triggered accordingly.

Here’s the definiton of the group:
Group:Switch:OR(ON,OFF) gIndoorMotion “Bewegungsmelder innen”

Until today morning I never had that behaviour before. But now I’m in doubt that maybe might be a bug in the current OH2 version I’m using so that presence check might not work as expected.

My current version of OH2 is 2.2.0 running on RPI3.

Thanks and best regards,
Jens

Read How to ask for assistance

I accidently hit “Open topic” to soon in my first edit. Sorry!

No prob. But can you post your rule also?

Not only the rule the definition auf the group too.

Here’s the rule. But the rule was not the problem. After I switched off the group item the rule was triggered as expected.

rule "Check for presence"
when
        Time cron "0 */5 * * * ?"
then
        if (Presence.state == ON) {
                constraint_count = 0
                phone_count = gMobiles.members.filter(s | s.state == ON).size
                if(phone_count == 0) {
                        logInfo("PresenceCheck", "No phone within reach, checking for flapping")
                        if(gMobiles.members.filter(s | s.changedSince(now.minusMinutes(presence_timeout), "influxdb")).size == 0) {
                                phone_present = false
                                logInfo("PresenceCheck", "No phone was present during the last " + presence_timeout + " minutes")
                        }
                        else {
                                constraint_count = constraint_count + 1
                                phone_present = true
                                logInfo("PresenceCheck", "At least one phone present during the last " + presence_timeout + " minutes")
                        }
                }
                else {
                        if (phone_count < 2) {
                                phone_count_text = "is "
                                phone_text = " phone"
                        }
                        else {
                                phone_count_text = "are "
                                phone_text = " phones"
                        }
                        constraint_count = constraint_count + 1
                        phone_present = true
                        logInfo("PresenceCheck", "Currently there " + phone_count_text + phone_count + phone_text + " present")
                }

                if((gIndoorMotion.state == OFF) && (gIndoorMotion.members.filter(m | m.changedSince(now.minusMinutes(presence_timeout), "influxdb")).size == 0)) {
                        motion_occured = false
                        logInfo("PresenceCheck", "No motion occured during the last " + presence_timeout + " minutes")
                }
                else {
                        constraint_count = constraint_count + 1
                        motion_occured = true
                        logInfo("PresenceCheck", "Motion occured during the last " + presence_timeout + " minutes")
                }

                if((gWeightSwitches.state == OFF) && (gWeightSwitches.members.filter(s | s.changedSince(now.minusMinutes(presence_timeout), "influxdb")).size == 0)) {
                        weight_on_sensor = false
                        logInfo("PresenceCheck", "No one sat on the sofa or laid in bed in the last " + presence_timeout + " minutes")
                }
                else {
                        constraint_count = constraint_count + 1
                        weight_on_sensor = true
                        logInfo("PresenceCheck", "Somebody sat on sofa or laid in bed during the last " + presence_timeout + " minutes")
                }

                if(CorridorDoorContact.state == CLOSED ) {
                        door_open = false
                        logInfo("PresenceCheck", "Front door is closed")
                }
                else {
                        door_open = true
                        constraint_count = constraint_count + 1
                        logInfo("PresenceCheck", "Front door is open")
                }

//              if((phone_present == false) && (motion_occured == false) && (door_open == false) && (weight_on_sensor == false)) {
                if(constraint_count == 0) {
                        logInfo("PresenceCheck", "Nobody is at home: setting Presence to OFF")
                        sendCommand(Presence, OFF)
                }
                else {
                        logInfo("PresenceCheck", constraint_count + " constraints are met, somebody is at home: no further triggering")
                }
        }
        else {
                //For initialisation. If Presence is undefined or off, although it should be on.
                if((gMobiles.members.filter(s | s.state == ON).size > 0) || (gIndoorMotion.members.filter(s | s.state == ON).size > 0) || (gWeightSensors.members.filter(s | s.state == ON).size > 0)) {
                        logInfo("PresenceCheck", "Setting presence to ON during initialisation")
                        sendCommand(Presence, ON)
                }
                else if (Presence.state == "Undefined" || Presence.state == "Uninitialized" || Presence.state == NULL) {
                        logInfo("PresenceCheck", "Presence state is UNKNOWN, setting Presence to OFF")
                        sendCommand(Presence, OFF)
                }
        }
end

Here’s the group definition again:
Group:Switch:OR(ON,OFF) gIndoorMotion "Bewegungsmelder innen" <motion>

Here’s the result in the log, where you can see, that my rule detects motion although there was no motion.

2018-01-23 08:55:00.151 [INFO ] [smarthome.model.script.PresenceCheck] - No phone within reach, checking for flapping
2018-01-23 08:55:00.238 [INFO ] [smarthome.model.script.PresenceCheck] - No phone was present during the last 10 minutes
2018-01-23 08:55:00.263 [INFO ] [smarthome.model.script.PresenceCheck] - Motion occured during the last 10 minutes
2018-01-23 08:55:00.364 [INFO ] [smarthome.model.script.PresenceCheck] - No one sat on the sofa or laid in bed in the last 10 minutes
2018-01-23 08:55:00.373 [INFO ] [smarthome.model.script.PresenceCheck] - Front door is closed
2018-01-23 08:55:00.379 [INFO ] [smarthome.model.script.PresenceCheck] - 1 constraints are met, somebody is at home: no further triggering

Sometimes it happen, that the group is not updated after update of items file. Write a little rule to browse members of group to verify this.

rule "Loop through groupitems"
when
	Item swLoopThroughGroupitems changed to ON
then
	logInfo("Logger","LoopThroughGroupitems")
	logInfo("Logger","##########################################")

	logInfo("Logger","gSwitches-List")
	logInfo("Logger","==========================================")	
	gSwitches.members.forEach[item |
		logInfo("Logger","gSwitches Itemname: "+item.name + ": "+ item.state.toString)
	]

	swLoopThroughGroupitems.postUpdate(OFF)
end

Done so. Here’s the output of your rule:

2018-01-23 14:14:11.833 [INFO ] [clipse.smarthome.model.script.Logger] - LoopThroughGroupitems
2018-01-23 14:14:11.836 [INFO ] [clipse.smarthome.model.script.Logger] - ##########################################
2018-01-23 14:14:11.838 [INFO ] [clipse.smarthome.model.script.Logger] - gSwitches-List
2018-01-23 14:14:11.841 [INFO ] [clipse.smarthome.model.script.Logger] - ==========================================
2018-01-23 14:14:11.887 [INFO ] [clipse.smarthome.model.script.Logger] - gSwitches Itemname: LivingroomMotion: OFF
2018-01-23 14:14:11.891 [INFO ] [clipse.smarthome.model.script.Logger] - gSwitches Itemname: KitchenMotion: OFF
2018-01-23 14:14:11.896 [INFO ] [clipse.smarthome.model.script.Logger] - gSwitches Itemname: CorridorMotion: OFF
2018-01-23 14:14:11.901 [INFO ] [clipse.smarthome.model.script.Logger] - gSwitches Itemname: BedroomMotion: OFF
2018-01-23 14:14:11.906 [INFO ] [clipse.smarthome.model.script.Logger] - gSwitches Itemname: BathroomMotion: OFF

But that’s no wonder because at 09:32 I switched the group item off manually in Karaf console and as an result all group items were switched off, too:

2018-01-23 09:32:57.938 [ome.event.ItemCommandEvent] - Item 'gIndoorMotion' received command OFF
2018-01-23 09:32:57.943 [ome.event.ItemCommandEvent] - Item 'LivingroomMotion' received command OFF
2018-01-23 09:32:57.954 [ome.event.ItemCommandEvent] - Item 'KitchenMotion' received command OFF
2018-01-23 09:32:57.966 [ome.event.ItemCommandEvent] - Item 'CorridorMotion' received command OFF
2018-01-23 09:32:57.984 [ome.event.ItemCommandEvent] - Item 'BedroomMotion' received command OFF
2018-01-23 09:32:57.991 [ome.event.ItemCommandEvent] - Item 'BathroomMotion' received command OFF

And afterwards, the presence rule detected the state correctly and switched Presence to off.

2018-01-23 09:35:00.471 [vent.ItemStateChangedEvent] - Presence changed from ON to OFF
2018-01-23 09:35:00.583 [vent.ItemStateChangedEvent] - PresenceText changed from ja to nein
2018-01-23 09:35:00.626 [ome.event.ItemCommandEvent] - Item 'TurnEverythingOff' received command ON

You mentioned that group items are not updated correctly after editing ANY items file? So what is the solution then? Restart of OH2 after editing items? Will there be a fix shortly for that behaviour?

The only way to ensure that all items are correct in groups is to restart OH.

This is an old problem but still exist.

And another problem. Sometimes it looks good by my check rule but still a problem with the group

Example:
group Group:Switch:OR(ON,OFF)

If you change it to
Group:Number:sum

This sometimes confuses the group and only restart helps.

To understand it correctly: does this issue only occur when I edit group items or items within that group or when I edit ANY item in an items file?
I ask that because I cannot remember that I have edited that group in question during the last months.

Can I avoid that behaviour when I switch off or on the group item manually directly after editing the items file?

For me this is not totally clear what really goes on. Sometimes all works fine at all, sometimes partly not, sometimes totally not.

I restart OH whenever I change the group item and not when I change items itself. If I think something is wrong, I restart it on any occation to be sure to have a correct reload of all definitions.

OK, good to know. I hope that behaviour will be fixed in near future.
Until then I will adopt your approach to restart OH2 when unexpected behaviour in relation with groups occurs.

Thanks for your immediate replies!

If anyone of you finds a minimal reproducible example where something goes wrong, please make sure that you file an issue at https://github.com/eclipse/smarthome/issues so that it can be addressed - thanks!

1 Like

Hello Kai,

good to know that this is the right way.

I hesitate a little bit to address everything which works incorrect and raise an issue. I will do this even more now.

As long as you are in doubt whether there is an issue or not, it is indeed better to first discuss it here.

But for anything that you can clearly identify as a bug and have an easily reproducible scenario, bug reports are very welcome and much encouraged!