Need help with HABApp Rule

I can’t quite get this to work… can you post the import commands? I’m sure I’m doing something dumb but can’t pinpoint it…

What is the error message?
I think it should be something like:

import HABApp
from HABApp.openhab.items import StringItem

I’m trying to work with group items, not strings…if that makes a difference. Here is the code:

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


class myClass(HABApp.Rule):
    def __init__(self):
        super().__init__()

        for member in self.openhab.get_item('g3Tasmotas').members:
            item = GroupItem.get_item(member.name)
            log.warning(item.name)


myClass()
log = logging.getLogger('MyRules')
myClass()
 

There are a lot of error lines, but they start with this:

2021-09-13 11:16:57.307 [ERROR] [HABApp.Rules                        ] - Error "8 validation errors for OpenhabItemDefinition
members -> 2 -> members -> 6 -> commandDescription -> commandOptions -> 0 -> label
  field required (type=value_error.missing)
members -> 2 -> members -> 6 -> commandDescription -> commandOptions -> 1 -> label
  field required (type=value_error.missing)
members -> 2 -> members -> 6 -> commandDescription -> commandOptions -> 2 -> label
  field required (type=value_error.missing)
members -> 2 -> members -> 6 -> commandDescription -> commandOptions -> 3 -> label
  field required (type=value_error.missing)
members -> 4 -> members -> 9 -> commandDescription -> commandOptions -> 0 -> label
  field required (type=value_error.missing)
members -> 4 -> members -> 9 -> commandDescription -> commandOptions -> 1 -> label
  field required (type=value_error.missing)
members -> 4 -> members -> 9 -> commandDescription -> commandOptions -> 2 -> label
  field required (type=value_error.missing)
members -> 4 -> members -> 9 -> commandDescription -> commandOptions -> 3 -> label
  field required (type=value_error.missing)" in load:

I think i see the problem. You created a group og tasmota devices called g3Tasmotas. And in

item = GroupItem.get_item(member.name)

you assume the each item in the group is again a group. I think that is not ture. Maybe those tasmotas are of type switch or contact or somethin like that.

Maybe you should erase the item line and modiy your log statement to

log.warning(member.name)

and you shoudl delete the first

myClass()

statement.

WIth this changes you should see the names of alle your group members.

To make it complete

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


class myClass(HABApp.Rule):
    def __init__(self):
        super().__init__()

        for member in self.openhab.get_item('g3Tasmotas').members:
            log.warning(member.name)


log = logging.getLogger('MyRules')
myClass()

It seems that you get an insufficient reply from the rest api (the label is missing from the item definition).
Which version of openhab are you running? Could you request the item definition through the rest api and post it here?

Also @Dibbler42 cleaned up your rule nicely.

1 Like

Thanks Gents.

Perhaps it is a size/capacity issue? I’ll send the file to you @Spaceman_Spiff privately if I can. It is about 10k lines. These tasmota groups contain lots of sub-items such as unifi data and the other tasmota telemetry. I was trying to use this looping to periodically auto-assign metadata like list order, widget, state description, etc. to newly created items.

Sorry for the incomplete answer… juggling this morning.

Running 3.2.0M2

I get similar errors when using a different group, and the cleaned-up code above.

Here is the group definition without member items:

{
  "members": [],
  "link": "http://pi-openhab:8080/rest/items/g3Tasmotas",
  "state": "NULL",
  "editable": true,
  "type": "Group",
  "name": "g3Tasmotas",
  "label": "Tasmotas",
  "category": "tasmota",
  "tags": [],
  "groupNames": [
    "g3Virtual"
  ]
}

Sure - just pm me the file. I’ll take a look at it.

Alternatively you can send me the (rest) item definition of
member 2 (which should be a group) → member 6

Thanks. Looks like your profile is private, so I don’t think I can?

Thanks to @rlkoshak for moving this thread.

@Spaceman_Spiff - yes, it seems like I have a rogue item in the group. I’ll have to poke around and see if I can clear it out without digging into the json file.