NCO
(E. Gerland)
September 12, 2018, 7:47am
1
All,
I am using successfully the following template for indicating the state of switches:
<button class="btn" style="width: 100%; height: 100%; padding: 0; background: inherit; outline: none">
<span>
<widget-icon iconset="'smarthome-set'" icon="'car_doorR'" size="32" state="itemValue('CarDrReLeft')" />
</span>
<span style="color: {{itemValue('CarDrReLeft')=='ON' ? 'white' : '#7B879C'}}">
HL
</span>
</button>
Because the items changed to Contacts (Door contacts of the new Volvo Binding), I struggle to get the icon to reflect the state.
For the widget’s text i just changed it to
<span style="color: {{itemValue('CarDrReLeft')=='OPEN' ? 'white' : '#7B879C'}}">
HL
</span>
and I tried to do the same on the icon, but did not succeed.
<button class="btn" style="width: 100%; height: 100%; padding: 0; background: inherit; outline: none">
<span>
<widget-icon iconset="'smarthome-set'" icon="'car_doorR'" size="32" state="itemValue('CarDrReLeft')=='OPEN' ? 'white' : '#7B879C'" />
</span>
<span style="color: {{itemValue('CarDrReLeft')=='OPEN' ? 'white' : '#7B879C'}}">
HL
</span>
</button>
any suggestion is greatly appreciated.
NCO
(E. Gerland)
September 21, 2018, 11:58am
2
No one?
I can’t imagine, that no one uses contacts on habpanel
MDAR
(Stuart Hanlon, UK importer of Velbus hardware)
September 21, 2018, 1:07pm
3
Hi
This is just a pure guess…
“Are contacts exposed to HabPanel”
Meaning, can you see the Contact item in a normal HabPanel widget?
NCO
(E. Gerland)
September 21, 2018, 1:53pm
4
Yes, I can select the contact item on e.g. the button widget.
And with the
NCO:
<span style
the Text HL reflects the state open / closed correctly
KidSquid
(The Squid)
September 21, 2018, 2:33pm
5
I’ve never included the ==OPEN, I’ve always created three versions of the icon as that’s how the docs say to create variable icons…the garage example below is from a contact.
so in my case below…
Garage2.png
Garage2-open.png
Garage2-closed.png
<widget-icon iconset="'custom-icon'" icon="'Garage2'" size="120" state="itemState('LtGarageDrSensor2')" />
NCO
(E. Gerland)
September 21, 2018, 4:10pm
6
hmmm… that wouldn’t help me, because I just have one svg icon.
Thanks a lot for your help, though.
NCO
(E. Gerland)
September 28, 2018, 7:45pm
7
No one can help me to reflect the item state in th icon?
ysc
(Yannick Schaus)
September 28, 2018, 7:58pm
8
<widget-icon iconset="'smarthome-set'" icon="'car_doorR'" size="32" state="itemState('CarDrReLeft')=='OPEN' ? 'ON' : 'OFF'" />
NCO
(E. Gerland)
September 29, 2018, 5:14am
9
Thanks so much, Yannick.
So I assume, that the following syntax means: handle OPEN like the conditions for ON (of a switch) otherwise OFF.
ysc:
==‘OPEN’ ? ‘ON’ : ‘OFF’"
I have tried before
state="itemState('CarDrReLeft')=='OPEN' ? 'OPEN' : 'CLOSED'" />
but this was obviously misinterpreted…
Thank you so much!!
ysc
(Yannick Schaus)
October 2, 2018, 7:11am
10
In computer programming, ?: is a ternary operator that is part of the syntax for basic conditional expressions in several programming languages. It is commonly referred to as the conditional operator, inline if (iif), or ternary if. An expression a ? b : c evaluates to b if the value of a is true, and otherwise to c.
It originally comes from CPL, in which equivalent syntax for e1 ? e2 : e3 was e1 → e2, e3.
Although many ternary operators are possible, the conditional operator is so common, and ...
NCO
(E. Gerland)
October 2, 2018, 9:38am
11
Fair enough.
You found one (of my numerous) gap in knowledge about programming.
The good Thing about openHAB is, that it enables people like me to look like a Programming pro (with the help of you guys @Kai , @ysc , @rlkoshak , @vzorglub ) in comparison to my friends and family.