Switch, adjust item label depending on current


(Marco Höfle) #1

Hello,
I have a KNX switch actor which can measure the electrical current.
Currently I have two items, a number item and the actual switch item:

Switch Steckdose_Outdoor_Terrasse "Steckdose Terrasse"            (gOutdoor) { knx="12/3/20+<13/3/20" }
Number Steckdose_Outdoor_Terrasse_Strom "Steckdose Strom [%d mA]"       (gOutdoor) { knx="<7.012:5/3/21" }

Instead of the static name “Steckdose Terrasse” I would prefer “Steckdose Terrasse, Strom: 2483 mA” to have one item less.
I still need the switch button though.

Has anyone an Idea how to achieve this?

BR
Marco


( ) #2

Hello,

you can not change the label of an item dynamically. It’s a label and supposed to be constant.
That said, what you can do is display different sitemap elements depending on certain conditions. An example of how I use that feature is:

Switch item=Flur_Deckenlicht visibility=[Flur_Deckenlicht_Unreach == OFF] icon="lamp_globe_light"
Text   item=Flur_Deckenlicht visibility=[Flur_Deckenlicht_Unreach != OFF] icon="error2" label="Flur Deckenlicht [N/A ✘]"

Adding the current current reading to your label is not possible but honestly also not meaningful. That part should go into the right part of a sitemap element. You will need to look for another solution.


(Marco Höfle) #3

Hello Thom,
thanks for your explanation that labels of Items cannot dynamically be changed.
Right now all items which are “draussen” are part of Group gOutdoor
Currently:

       Frame label="Haus"
        {
                Group item=gEG label="Erdgeschoss" icon="groundfloor"
                Group item=gOG label="Obergeschoss" icon="firstfloor"
                Group item=gKG label="Keller" icon="cellar"
                Group item=gOutdoor label="draussen" icon="garden"
        }

When doing that with the visibility feature I suppose I cant use groups anymore and I have to do
something like

        Frame label="Haus"
        {
                Group item=gEG label="Erdgeschoss" icon="groundfloor"
                Group item=gOG label="Obergeschoss" icon="firstfloor"
                Group item=gKG label="Keller" icon="cellar"
//              Group item=gOutdoor label="draussen" icon="garden"
                Text label="draussen" icon="garden"
                {
                        Frame
                        {
                                Switch item=Steckdose_Outdoor_Terrasse
//                              Text item=Steckdose_Outdoor_Terrasse_Strom visibility=[Steckdose_Outdoor_Terrasse_Strom > 0]
                                Text item=Steckdose_Outdoor_Terrasse_Strom visibility=[Steckdose_Outdoor_Terrasse == ON]
                        }
                }
        }


( ) #4

Hmmm yes. In general I would not go with this design. It’s not really neat if you think about it. Maybe you can take some ideas from the list of best practices I’ve posted over here:


(Marco Höfle) #5

It was the first step and taken from the demo sitemap after a fresh installation.

I’ll replace the groups where I need better control of the Layout.

I like your Grafana graphs. But you cannot have them interactively where you can zoom in and out with the mouse, can you?


( ) #6

yes you can but it’s not in the example yet.

See: InfluxDB+Grafana persistence and graphing --> “…as dynamic ‘Webview’ Element with JavaScript library”


(Rossko57) #7

There is a way to set the value of the item.label string within a rule.
It doesn’t seem to be documented. It might be unsupported and go away in future releases.


Behaviour is a bit quirky


Fire alarm trigger and notification
Combining 2 item states in a sitemap section display?
( ) #8

Oha :zipper_mouth_face: learn something new everyday… I did not know that and actually thought the option is not available by design.


Dynamic label for a switch
(Marco Höfle) #9

Hello thanks for the hints.
I am almost there. I have this rule:

rule "rule-Steckdose-label"
when
  Item Steckdose_Outdoor_Terrasse_Strom received update
then
	var Number strom = (Steckdose_Outdoor_Terrasse_Strom.state as DecimalType)/1000.0;
	var lab = (Math::round(strom.floatValue * 100.0)/100.0).toString
	logInfo("Strom", lab)
	Steckdose_Outdoor_Terrasse.label = "Steckdose Terrasse, Strom: " + lab + " A"
end

I need to refresh the browser window to see the updated label. However, the rule itself is triggered as the log is updated.
Is it the same for you?


(Frederic Mariën) #10

Hi @marco_hoefle,

Did you manage to get the label updated without the need to refresh the browser?
I’m having the same issue at the moment.

Thanks!


(Marco Höfle) #11

Hello Frederic,
didnt work reliable, I switched to the “visibility” method without showing dynamic values.
BR
Marco