binia
(Thomas)
July 18, 2018, 7:49am
#1
I have an item.
For example, a temperature item.
It’s stored in my custom widget.
{{'% .1f' | sprintf: itemValue ('KChe_Temperatur'). split ('') [0]}}
As a result, I get 24.5
I would like to split this up.
{{'% .0f' | sprintf: itemValue ('KChe_Temperatur'). split ('') [0]}}
gives 24.
Now I would like to have the number after the comma individually to make it different in my widget.
Is that possible?
hr3
(Harry)
July 18, 2018, 9:22am
#2
{{'%f' | sprintf:itemValue('KChe_Temperatur').split('.')[1].substring(0,1)}}
vzorglub
(Vincent Regaud)
July 18, 2018, 10:09am
#3
@hr3
I am using the new UoM items and the dummy widgets don’t update straight away in HABpanel.
I don’t know html and I was wondering how to create a equivalent dummy widget that would display the UoM values.
Could you help, thanks
binia
(Thomas)
July 18, 2018, 10:33am
#5
and is it posible with a full nummber?
Like a 554
I want to show the 55 in a big div and the 4 in a smal
hr3
(Harry)
July 18, 2018, 1:01pm
#6
Change the substring-parms.
binia
(Thomas)
July 18, 2018, 1:02pm
#7
{{'%s' | sprintf:itemValue('KChe_CO2Gehalt').split(' ')[0].substring(2)}}
i have solve it. Thanks
hr3
(Harry)
July 18, 2018, 1:26pm
#8
If it’s a integer you don’t need the split-function.
For this solution you ever muß have the same number of digits.
hr3
(Harry)
July 18, 2018, 2:19pm
#9
Number:Temperature Temp1 "Temp 1[%.1f %unit%]"
sitemap tmp label="TMP" {Default item=Temp1}
<h2>{{itemValue('Temp1')}}</h2>
<h2>{{'%s' | sprintf:itemValue('Temp1').substring(1,4)}}</h2>
<h2>{{'%.0f' | sprintf:itemValue('Temp1').split('.')[0]}},{{'%s' | sprintf:itemValue('Temp1').split('.')[1]}}</h2>
<h2>{{'%.1f' | sprintf:itemValue('Temp1').split(' ')[0]}}{{itemValue('Temp1').split(' ')[1]}}</h2>
2 Likes
binia
(Thomas)
July 19, 2018, 1:53pm
#10
Now i have a misstake in the Temp.
<div class="main">{{'%.0f' | sprintf:itemValue('KChe_Temperatur').split(' ')[0]}}<div class="sub">,{{'%f' | sprintf:itemValue('KChe_Temperatur').split('.')[1].substring(0,1)}}</div></div>
Its 25.8 C here but the Result in the widget shows 26,8
The first Item round up the 25,8 to 26 and the Sec Items is ,8.
Is it Posible to fix the round up?
Thanks
hr3
(Harry)
July 19, 2018, 2:17pm
#11
<div class="main">{{itemValue('KChe_Temperatur').split('.')[0]}}<div class="sub">,{{itemValue('KChe_Temperatur').split('.')[1].substring(0,1)}}</div></div>
1 Like
ysc
(Yannick Schaus)
July 22, 2018, 8:23pm
#12
You can also use %d
as a pattern i.e. {{'%d' | sprintf:itemValue('KChe_Temperatur').split(' ')[0]}}
to get the integer part of the number without rounding.
vzorglub
(Vincent Regaud)
July 24, 2018, 8:11am
#13
@hr3
Thanks that works in a template widget.
Now, I am sorry but I am ok at coding but not HTML stuff, never touched as I have never really been interested.
How can I make that template widget look like the dummy widget?
Current with the <h2>
html tag:
Wanted:
But with the temperature icon?
Thanks
hr3
(Harry)
July 24, 2018, 8:22am
#14
<widget-icon iconset="'eclipse-smarthome-classic'" icon="'temperature'" state="item.state"/>
vzorglub
(Vincent Regaud)
July 24, 2018, 8:28am
#15
Thanks,
That’s what I have now:
<div class="text-center" style="font-size: 10pt">
<span>Open Temp</span>
</div>
<div class="text-center" style="font-size: 36pt; color:#FF7B00">
<span>{{'%.1f' | sprintf:itemValue('openWeather_Current_Temperature').split(' ')[0]}}{{itemValue('openWeather_Current_Temperature').split(' ')[1]}}</span>
</div>
<widget-icon iconset="'eclipse-smarthome-classic'" icon="'temperature'" state="item.state"/>
I have replicated the text styles of the dummy widget, but your suggestion for the icon display a thermometer under the text. How do I specifify the icon to be in the background?
Also, can I use the builtin: Smart Home Set
of icons?
I know, sounds very noobs, but I have never really touched this kind of stuff before…
Thanks
vzorglub
(Vincent Regaud)
July 24, 2018, 9:29am
#17
That’s what I am getting away from because at the moment it’s broken with the Units
hr3
(Harry)
July 24, 2018, 10:23am
#18
I think that would be fixed in the future.
I would use the dummy-widget und prepare a (string) dummy-item in a rule for the moment.
hr3
(Harry)
July 24, 2018, 11:09am
#19
This works with items with and without UoM similarly.
vzorglub
(Vincent Regaud)
July 24, 2018, 11:59am
#20
Coolio, I’ll give it a go