OH2 - OH3 Sitemap to Main UI migration. Can't find the appropriate widgets

Further tests lead to:

              - component: oh-label-cell
                config:
                  action: group
                  actionGroupPopupItem: gLicht
                  title: Lichter
                  expandable: false
                  icon: =(items.gLicht.state == 'ON')?'oh:light-on':'oh:light-off'
                  label: =(items.gLicht.state)

Unfortunately
label: =(items.gLicht.label)
does not work. I thought this could result in “Lichter an: 5”…

Are you using the UI or editing files?
I think if you use both then things don’t work properly.
I use the UI only. I don’t edit any files.
The widgets don’t show real time (or I can’t work out how to do it) but the properties tab is real time and that was the screen shot I posted.

I want to use text files only but it is hard to achieve (reason: Versioning with git). The MQTT things for example only work (at least I couldn’t achieve it) when using the UI.
I got a bit closer


Instead of the Text “OPEN” I’d like to see the number of the opened windows.

This is the code I have so far:

              - component: oh-label-cell
                config:
                  action: group
                  actionGroupPopupItem: gKontakte
                  label: =items.gKontakte.state
                  title: Fenster
                  icon: =(items.gKontakte.state == 'OPEN')?'oh:contact-open':'oh:contact-closed'
                  footer: footer
                  expandable: false

and the items in a text file:

Group:Contact:OR(OPEN, CLOSED) gKontakte “Offene Fenster/Türen [(%d)]”

//Group:Contact:COUNT(“OPEN”) gKontakte “Offene Fenster/Türen [%d]”

/* Fenster */
Contact Fenster_KG_Werkstatt “KG Werkstatt [MAP(de.map):%s]” (gKontakte, KG_Werkstatt) { channel=“knx:device:bridge:kontakte:Fenster_KG_Werkstatt” }
Contact Fenster_KG_Gast “KG Gast [MAP(de.map):%s]” (gKontakte, KG_Gast) { channel=“knx:device:bridge:kontakte:Fenster_KG_Gast” }

You need to introduce 3 new groups, one for open windows, one for closed windows :

Group:SUM gKontakte "Fenster/Türen"
Group:Contact:COUNT("OPEN") gKontakteOffen "Offene Fenster/Türen"
Group:Contact:COUNT("CLOSED") gKontakteGeschlossen "Geschlossene Fenster/Türen"

Having this, You can either show all contacts, or just open or closed contacts and will get the number as a state.

Hello Hans-Jörg,

the state gives always a “OPEN” or “CLOSED” regardless which group state I take as am item.

I have:

Group:Contact:SUM gKontakte "Offene Fenster/Türen"

Group:Contact:COUNT("OPEN") gKontakteOffen "Offene Fenster/Türen"
Contact Fenster_OG_Buero        "OG Büro [MAP(de.map):%s]"        <window> (gKontakte, gKontakteOffen, OG_Buero)     { channel="knx:device:bridge:kontakte:Fenster_OG_Buero" }
Contact Fenster_OG_Bad          "OG Bad [MAP(de.map):%s]"         <window> (gKontakte, gKontakteOffen, OG_Bad)       { channel="knx:device:bridge:kontakte:Fenster_OG_Bad" }

and this in the label field:

label: =items.gKontakteOffen.state

The log sais:

09:04:37.406 [INFO ] [nhab.event.GroupItemStateChangedEvent] - Item ‘gKontakte’ changed from CLOSED to OPEN through Fenster_OG_Buero
09:04:37.408 [INFO ] [nhab.event.GroupItemStateChangedEvent] - Item ‘gKontakteOffen’ changed from CLOSED to OPEN through Fenster_OG_Buero
09:04:40.678 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item ‘Fenster_OG_Buero’ changed from OPEN to CLOSED

Sorry, my fault,

2 Likes

This was it, thank you very much.
Now the number of opened windows is correctly displayed

1 Like

In ye olden days of OH2,

Group:Contact::OR(OPEN,CLOSED) someGroup "my label [%d]"

had magical properties. The basic state of the Group would be OPEN or CLOSED, as seen by rules or (usefully) by dynamic icons, but the [%d] state presentation gave a sitemap display of a count of ‘active’ members.

So far as I know this hidden count still exists in OH3, but is not accessible in MainUI. Has anyone fathomed it out?

Unfortunately not, I tried with several fields (.label, .text) but without success.
There is also another difference, dimmer items e.g.:

Dimmer Licht_EG_Essen_Tisch        "EG Esszimmertisch [%d %%]"   <light> (gLicht, gLichterAn)              { channel="knx:device:bridge:lichter:Licht_EG_Essen_Tisch" }

Don’t count when using this approach for lights. With the OH2 mechanism this was possible, just all light and dimmer items were through into the same group and also an active dimmer item was counted.

With the COUNT “ON” approach:

Group:Number:COUNT(“ON”) gLichterAn

Only switches are counted,

It still exists for BasicUI AFAIK, but not for MainUI. Had a chat about it with Yannick some time ago. It is not on the roadmap atm.

Well yes, these have state 0-100 so SUM obviously will give results like 456 while COUNT( >0) just doesn’t work.

You can put Dimmers into Switch flavoured Group, and the OR function will recognise >0 as ON, but that doesn’t help because of the regression losing %d functionality.

COUNT is documented as working with ‘regular expression’. I wonder if is possible to work out what not-“0” would look like. That would mess up with 0.0, but that’s not usually seen in Dimmers.
Not-0 isn’t quite the same as ON, remembering NULL etc. but it’s close.

So the only solution is to calculate the number of active dimmers in a rule?
the procedure would than be:

  1. Item for the active dimmer count
  2. group for all dimmers
  3. loop in a rule through all members of the dimmer group and count those having a state greater 0
  4. update the active dimmer count item
  5. use the active dimmer item in the Main UI

No.
I had a look around for COUNT expression uses, found this

I could not get Group:Number:COUNT("^[1-9]*$") to work as used there.

I stole a “test for non-zero” expression from somewhere else, tried
Group:Number:COUNT("^[1-9]\\d*(?:\\.\\d+)?$")
and that seems to work pretty well. Non-zero dimmers are counted, decimal or integer.
0 NULL or UNDEF are not counted.
Quirk - decimals less than 1 e.g. 0.9 not counted, treated as OFF - do you care? Decimals are rare but allowed in Dimmers.

Don’t ask me how it works or how it could be improved to handle Switch members in the same group, that would be useful.

The question is: will it work in the next release? I am intending to replace proprietary KNX visualizations with OpenHAB.

Will what work? Why would you expect it to go away?

For counting switches, contacts and dimmers as part of the same group this should work:

Group:Number:SUM testCountALL
Group:Number:COUNT("^[1-9]|ON|OPEN|0.0*[1-9]") testCountON "Number of active test items [%d]" (testCountALL)
Group:Number:COUNT("^(0(.0+)*)|OFF|CLOSED|NULL|UNDEF") testCountOFF "Number of INactive test items [%d]" (testCountALL)

Contact contact1        "Contact 1 [%s]" <window>  (testCountON, testCountOFF)
Switch switch1          "Switch 1 [%s]"  <light>   (testCountON, testCountOFF)
Dimmer dimmer1          "Dimmer 1 [%s]"  <heating> (testCountON, testCountOFF)

I tested with all three kinds of items and got correct results for dimmers with both integer and decimal values (0, 0.0, 1, 1.0, …) as well as “UNDEF” and “NULL” values.

“correct” means I consider “CLOSED” contacts and UNDEF or NULL items to be part of the OFF/inactive group.

2 Likes

That’s brilliant :smiley:
Should work as-is with Rollershutter (same state type as Dimmer)

Can you add Color types - state format a,b,c and find non-zero c - without messing up dimmer? Regex is beyond me.

Can you add Color types

Oh, here’s a challenge … :smile:
I’ll give it a shot, might take some days, though

Okay, here you go: This should work for switches, contacts, dimmers and color items:

Group:Number:SUM testCountALL
Group:Number:COUNT("^(([1-9][0-9.-]*$)|ON|OPEN|0[.]0*[1-9]|([0-9. ]+,[0-9. ]+,[0. ]*[1-9][0-9.]*))") testCountON "Number of active test items [%d]" (testCountALL)
Group:Number:COUNT("^((0$)|(0.0+$)|OFF|CLOSED|NULL|UNDEF|([0-9. ]+,[0-9. ]+, *0+(.0+)?$))") testCountOFF "Number of INactive test items [%d]" (testCountALL)

Compared to the first attempt (without color) it became slighty more complicated, but should also fix some issues with the first attempt :slight_smile:

I tested the expressions against these test cases:

ON-Values:
1
ON
OPEN
0.1
1.0
2
30
123
229,100,99
255,32,33
0,0, 0.00001
0,0,99
OFF-Values:
0
OFF
CLOSED
0.0
UNDEF
NULL
229, 100, 0.00000
229,100,0

Note, however, that I have some light things which have separate On/Off switches, where the third color value is >0 even though the switch and the light are OFF.

Unfortunately, RegExes are always Write-Only (i.e. one should never try to read and understand them…), so I hope these will never need to be changed :slight_smile:

Hope this works for you!

3 Likes

Hi Jens,
now the dimmers count as well with one line instead of having a separate rule.
You are the master :wink:
Thanks yo
Marco