# HABApp - Get Group State

**URL:** <https://community.openhab.org/t/habapp-get-group-state/120605>\
**Category:** 3rd Party\
**Created:** [April 11, 2021, 12:06am UTC](https://community.openhab.org/t/habapp-get-group-state/120605 "2021-04-11T00:06:50Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![alfista2600](https://community.openhab.org/letter_avatar_proxy/v4/letter/a/3d9bf3/32.png) [@alfista2600](https://community.openhab.org/u/alfista2600)\
**Post date:** [April 11, 2021, 12:06am UTC](https://community.openhab.org/t/habapp-get-group-state/120605/1 "2021-04-11T00:06:50Z")

</div>

Hey @Spaceman_Spiff,

Still trying to get started with some simple rules.

I’m trying to get the ON/OFF state of a group. The API Explorer returns this:

```yaml
{
  "members": [
    {
      "link": "http://pi-openhab:8080/rest/items/g3ChronosOffWhenBright",
      "state": "100",
      "type": "Dimmer",
      "name": "V_Lights_KitchenSink",
      "label": "Sink Lights",
      "category": "slider",
      "tags": [
        "Control",
        "Light"
      ],
      "groupNames": [
        "g3ChronosOffWhenSleep",
        "g3ChronosOffWhenBright"
      ]
    }
  ],
  "groupType": "Switch",
  "function": {
    "name": "OR",
    "params": [
      "ON",
      "OFF"
    ]
  },
  "link": "http://pi-openhab:8080/rest/items/g3ChronosOffWhenBright",
  "state": "ON",
  "editable": true,
  "type": "Group",
  "name": "g3ChronosOffWhenBright",
  "label": "Bright - Off",
  "category": "sun",
  "tags": [
    "Switch"
  ],
  "groupNames": []
}

```

and in a HABAPP rule these commands:

```yaml
        group_item = GroupItem.get_item("g3ChronosOffWhenBright")
        log.warning(group_item)

```

return:

```yaml
<GroupItem name: g3ChronosOffWhenBright, value: None, last_change: 2021-04-10 17:44:30.610776, last_update: 2021-04-10 17:44:30.610776>

```

Maybe I’m missing something (wouldn’t be the first time) but it appears that it is not returning the group state?

---

<div class="post-metadata">

**Author:** ![Spaceman\_Spiff](https://community.openhab.org/user_avatar/community.openhab.org/spaceman_spiff/32/56883_2.png) [@Spaceman\_Spiff](https://community.openhab.org/u/Spaceman_Spiff)\
**Post date:** [April 11, 2021, 4:38am UTC](https://community.openhab.org/t/habapp-get-group-state/120605/2 "2021-04-11T04:38:16Z")

</div>

Do you see the corresponding event in the HABApp log if you flip one of your switches?

Also take a look at the MultiModeItem. It allows to easily build logic without having to use groups.

---

<div class="post-metadata">

**Author:** ![alfista2600](https://community.openhab.org/letter_avatar_proxy/v4/letter/a/3d9bf3/32.png) [@alfista2600](https://community.openhab.org/u/alfista2600)\
**Post date:** [April 11, 2021, 10:52am UTC](https://community.openhab.org/t/habapp-get-group-state/120605/3 "2021-04-11T10:52:38Z")

</div>

A restart of the service resolved the problem. I can’t remember if I restarted it since I created that group. Thanks for the tips. I’ll look into MMI anyway.

---

<div class="post-metadata">

**Author:** ![alfista2600](https://community.openhab.org/letter_avatar_proxy/v4/letter/a/3d9bf3/32.png) [@alfista2600](https://community.openhab.org/u/alfista2600)\
**Post date:** [April 11, 2021, 11:36am UTC](https://community.openhab.org/t/habapp-get-group-state/120605/4 "2021-04-11T11:36:26Z")

</div>

@Spaceman_Spiff - Well, I spoke too soon.

I am no longer getting NULL values, but the value doesn’t change when I toggle g3ChronosOffWhenBright manually in MainUI. here is my whole code (apologies if code fence is wrong):

```yaml
import HABApp
from HABApp.core.events import ValueChangeEvent
from HABApp.openhab.items import NumberItem, GroupItem
import logging

class MyRule(HABApp.Rule):
    def __init__ (self):
        super(). __init__ ()
        self.listen_event('V_HABApp_Ping', self.on_change, ValueChangeEvent)

    def on_change(self, event: ValueChangeEvent):
        sensor_item = NumberItem.get_item('Hue_SensorLightOutdoor_Illuminance')
        group_item = GroupItem.get_item("g3ChronosOffWhenBright")

        if sensor_item.get_value() > 100:
            log.warning(str(group_item.get_value()))
            if str(group_item.get_value()) == "ON":
                log.warning('Chronos - Off When Light')
                group_item.oh_send_command("OFF")
        else:
            if str(group_item.get_value()) == "OFF":
                log.warning('Chronos - On When Dark')
                group_item.oh_send_command("ON")

log = logging.getLogger('MyRule')
MyRule()

```

---

<div class="post-metadata">

**Author:** ![Spaceman\_Spiff](https://community.openhab.org/user_avatar/community.openhab.org/spaceman_spiff/32/56883_2.png) [@Spaceman\_Spiff](https://community.openhab.org/u/Spaceman_Spiff)\
**Post date:** [April 11, 2021, 3:01pm UTC](https://community.openhab.org/t/habapp-get-group-state/120605/5 "2021-04-11T15:01:52Z")

</div>

You are listening to `V_HABApp_Ping` instead of your group item.  
Also you can use `group_item.value` instead of `get_value(default=99)` which exists to provide a default if the value is `None`

---

<div class="post-metadata">

**Author:** ![alfista2600](https://community.openhab.org/letter_avatar_proxy/v4/letter/a/3d9bf3/32.png) [@alfista2600](https://community.openhab.org/u/alfista2600)\
**Post date:** [April 11, 2021, 3:17pm UTC](https://community.openhab.org/t/habapp-get-group-state/120605/6 "2021-04-11T15:17:22Z")

</div>

I was just using V\_HABAPP\_Ping as a proxy for the item that I wanted to use, as it updates every 20 seconds.

I am not trying to detect changes to the group item directly. Just if another item changes, check the status of the group item, and if it is ON turn it OFF.

I’ll do a few more tests.

---

<div class="post-metadata">

**Author:** ![alfista2600](https://community.openhab.org/letter_avatar_proxy/v4/letter/a/3d9bf3/32.png) [@alfista2600](https://community.openhab.org/u/alfista2600)\
**Post date:** [April 11, 2021, 4:27pm UTC](https://community.openhab.org/t/habapp-get-group-state/120605/7 "2021-04-11T16:27:31Z")

</div>

@Spaceman_Spiff Nope. I’m either an idiot or there is something wrong. Likely the former. But I’ve simplified the code for testing purposes down to:

```yaml
from HABApp.openhab.items import GroupItem
import logging

log = logging.getLogger('MyRule')
group_item = GroupItem.get_item("g3ChronosOffWhenBright")
log.warning(group_item.value)
log.warning(group_item.get_value())
group_item.oh_send_command("ON")
log.warning(group_item.value)
log.warning(group_item.get_value())
group_item.oh_send_command("OFF")
log.warning(group_item.value)
log.warning(group_item.get_value())

```

I even added some sleep commands between the send\_command and logging the value. In all cases I only read OFF:

I can probably work around it… but just trying to get the basics working before migrating rules.

 ![image](https://community-openhab-org.s3.dualstack.eu-central-1.amazonaws.com/original/3X/f/2/f2154f1846f758acba6c722f23bc45661681163b.png)

---

<div class="post-metadata">

**Author:** ![Spaceman\_Spiff](https://community.openhab.org/user_avatar/community.openhab.org/spaceman_spiff/32/56883_2.png) [@Spaceman\_Spiff](https://community.openhab.org/u/Spaceman_Spiff)\
**Post date:** [April 11, 2021, 4:51pm UTC](https://community.openhab.org/t/habapp-get-group-state/120605/8 "2021-04-11T16:51:22Z")

</div>

You need larger delays, try 100 ms.  
Please also take a look at the `HABApp_events.log`. There you see all changes that get read from openhab and you should easily see the values change.  
Also check the “read\_only” config switch.

Last but not least check `openhab.log` for errors

---

<div class="post-metadata">

**Author:** ![alfista2600](https://community.openhab.org/letter_avatar_proxy/v4/letter/a/3d9bf3/32.png) [@alfista2600](https://community.openhab.org/u/alfista2600)\
**Post date:** [April 11, 2021, 5:24pm UTC](https://community.openhab.org/t/habapp-get-group-state/120605/9 "2021-04-11T17:24:29Z")

</div>

I see them changing in HABApp\_events, and in openhab.log. I had set the sleep interval between changing the state to 2s and 1s before the last post (it complained about a long running script both times). I just tried with .1s and same result (as expected).

```auto
[2021-04-11 13:17:07,638] [HABApp.EventBus] INFO | g3ChronosOffWhenBright: <GroupItemStateChangedEvent name: g3ChronosOffWhenBright, value: OFF, old_value: ON>
[2021-04-11 13:17:55,805] [HABApp.EventBus.openhab] DEBUG | {'topic': 'openhab/items/g3ChronosOffWhenBright/command', 'payload': '{"type":"OnOff","value":"ON"}', 'type': 'ItemCommandEvent'}
[2021-04-11 13:17:55,805] [HABApp.EventBus] INFO | g3ChronosOffWhenBright: <ItemCommandEvent name: g3ChronosOffWhenBright, value: ON>
[2021-04-11 13:17:55,823] [HABApp.EventBus.openhab] DEBUG | {'topic': 'openhab/items/g3ChronosOffWhenBright/V_Lights_KitchenSink/statechanged', 'payload': '{"type":"OnOff","value":"ON","oldType":"OnOff","oldValue":"OFF"}', 'type': 'GroupItemStateChangedEvent'}
[2021-04-11 13:17:55,825] [HABApp.EventBus] INFO | g3ChronosOffWhenBright: <GroupItemStateChangedEvent name: g3ChronosOffWhenBright, value: ON, old_value: OFF>
[2021-04-11 13:18:38,205] [HABApp.EventBus.openhab] DEBUG | {'topic': 'openhab/items/g3ChronosOffWhenBright/command', 'payload': '{"type":"OnOff","value":"OFF"}', 'type': 'ItemCommandEvent'}
[2021-04-11 13:18:38,205] [HABApp.EventBus] INFO | g3ChronosOffWhenBright: <ItemCommandEvent name: g3ChronosOffWhenBright, value: OFF>
[2021-04-11 13:18:38,224] [HABApp.EventBus.openhab] DEBUG | {'topic': 'openhab/items/g3ChronosOffWhenBright/V_Lights_KitchenSink/statechanged', 'payload': '{"type":"OnOff","value":"OFF","oldType":"OnOff","oldValue":"ON"}', 'type': 'GroupItemStateChangedEvent'}
[2021-04-11 13:18:38,224] [HABApp.EventBus] INFO | g3ChronosOffWhenBright: <GroupItemStateChangedEvent name: g3ChronosOffWhenBright, value: OFF, old_value: ON>
[2021-04-11 13:18:38,286] [HABApp.EventBus.openhab] DEBUG | {'topic': 'openhab/items/g3ChronosOffWhenBright/command', 'payload': '{"type":"OnOff","value":"ON"}', 'type': 'ItemCommandEvent'}
[2021-04-11 13:18:38,286] [HABApp.EventBus] INFO | g3ChronosOffWhenBright: <ItemCommandEvent name: g3ChronosOffWhenBright, value: ON>
[2021-04-11 13:18:38,339] [HABApp.EventBus.openhab] DEBUG | {'topic': 'openhab/items/g3ChronosOffWhenBright/V_Lights_KitchenSink/statechanged', 'payload': '{"type":"OnOff","value":"ON","oldType":"OnOff","oldValue":"OFF"}', 'type': 'GroupItemStateChangedEvent'}
[2021-04-11 13:18:38,339] [HABApp.EventBus] INFO | g3ChronosOffWhenBright: <GroupItemStateChangedEvent name: g3ChronosOffWhenBright, value: ON, old_value: OFF>

```

I can just never successfully read the group value or get\_value(). It always comes back as OFF.

---

<div class="post-metadata">

**Author:** ![alfista2600](https://community.openhab.org/letter_avatar_proxy/v4/letter/a/3d9bf3/32.png) [@alfista2600](https://community.openhab.org/u/alfista2600)\
**Post date:** [April 11, 2021, 11:22pm UTC](https://community.openhab.org/t/habapp-get-group-state/120605/10 "2021-04-11T23:22:18Z")

</div>

Further simplifying… this code logs OFF whether the group specified is ON or OFF.

```csv
from HABApp.openhab.items import GroupItem
import logging

log = logging.getLogger('MyRule')
group_item = GroupItem.get_item("g3ChronosOffWhenBright")
log.warning(group_item.get_value())
log.warning(group_item.value)

```

---

<div class="post-metadata">

**Author:** ![Spaceman\_Spiff](https://community.openhab.org/user_avatar/community.openhab.org/spaceman_spiff/32/56883_2.png) [@Spaceman\_Spiff](https://community.openhab.org/u/Spaceman_Spiff)\
**Post date:** [April 12, 2021, 3:43am UTC](https://community.openhab.org/t/habapp-get-group-state/120605/11 "2021-04-12T03:43:02Z")

</div>

I’ll investigate - you’re doing everything right.

---

<div class="post-metadata">

**Author:** ![alfista2600](https://community.openhab.org/letter_avatar_proxy/v4/letter/a/3d9bf3/32.png) [@alfista2600](https://community.openhab.org/u/alfista2600)\
**Post date:** [April 12, 2021, 1:43pm UTC](https://community.openhab.org/t/habapp-get-group-state/120605/12 "2021-04-12T13:43:34Z")

</div>

Cool. Please let me know if there is anything I can do to help.

here is the item definition I created for testing purposes if it helps.

```csv
{
  "members": [
    {
      "link": "http://pi-openhab:8080/rest/items/g3ChronosOffWhenBright",
      "state": "100",
      "type": "Dimmer",
      "name": "V_Lights_KitchenSink",
      "label": "Sink Lights",
      "category": "slider",
      "tags": [
        "Control",
        "Light"
      ],
      "groupNames": [
        "g3ChronosOffWhenSleep",
        "g3ChronosOffWhenBright"
      ]
    }
  ],
  "groupType": "Switch",
  "function": {
    "name": "OR",
    "params": [
      "ON",
      "OFF"
    ]
  },
  "link": "http://pi-openhab:8080/rest/items/g3ChronosOffWhenBright",
  "state": "ON",
  "editable": true,
  "type": "Group",
  "name": "g3ChronosOffWhenBright",
  "label": "Bright - Off",
  "category": "sun",
  "tags": [
    "Switch"
  ],
  "groupNames": []
}

```

---

<div class="post-metadata">

**Author:** ![Spaceman\_Spiff](https://community.openhab.org/user_avatar/community.openhab.org/spaceman_spiff/32/56883_2.png) [@Spaceman\_Spiff](https://community.openhab.org/u/Spaceman_Spiff)\
**Post date:** [May 2, 2021, 12:29pm UTC](https://community.openhab.org/t/habapp-get-group-state/120605/13 "2021-05-02T12:29:47Z")

</div>

I’ve just released [0.30.0](https://community.openhab.org/t/habapp-0-30/121752) which fixes the issue.
