bots444
(Matt Botsford)
December 11, 2018, 3:57pm
1
Hi guys. I’m having a bit of trouble and was wondering if anyone could help me. I bought some Xiaomi temperature and humidity sensors to put around my house. I am trying to convert the values from Celsius to Fahrenheit but can’t seem to figure out how to do it. I am attempting to do this in a template widget. I read on the forum that you should be able to just do the math within the widget but that doesn’t seem to work. This is what I have.
Room Temp
Temperature: {{itemValue('Room_Temperature') * 1.8 + 32}}
When I do that the value is returned as NaN. Anyone know what im doing wrong here?
vzorglub
(Vincent Regaud)
December 12, 2018, 7:45am
2
Please post your item definitions
bots444
(Matt Botsford)
December 12, 2018, 12:29pm
3
Sorry about that. Here is the items file for the gateway and one of the sensors
//Gateway
Switch Gateway_AddDevice { channel=“mihome:gateway:7c49eb1b8f29:joinPermission” }
Dimmer Gateway_Brightness { channel=“mihome:gateway:7c49eb1b8f29:brightness” }
Color Gateway_Color { channel=“mihome:gateway:7c49eb1b8f29:color” }
Dimmer Gateway_ColorTemperature { channel=“mihome:gateway:7c49eb1b8f29:colorTemperature” }
Number Gateway_AmbientLight { channel=“mihome:gateway:7c49eb1b8f29:illumination” }
Number Gateway_Sound { channel=“mihome:gateway:7c49eb1b8f29:sound” }
Switch Gateway_SoundSwitch <soundvolume_mute> { channel=“mihome:gateway:7c49eb1b8f29:enableSound” }
Dimmer Gateway_SoundVolume { channel=“mihome:gateway:7c49eb1b8f29:volume” }
//Basement Temperature and Humidity Sensor
Number:Temperature Basement_HT_Temperature { channel=“mihome:sensor_ht:158d00023d295f:temperature” }
Number:Dimensionless Basement_HT_Humidity { channel=“mihome:sensor_ht:158d00023d295f:humidity” }
Number Basement_HT_Battery { channel=“mihome:sensor_ht:158d00023d295f:batteryLevel” }
Switch Basement_HT_BatteryLow { channel=“mihome:sensor_ht:158d00023d295f:lowBattery” }
vzorglub
(Vincent Regaud)
December 12, 2018, 2:38pm
4
Number:Temperature Basement_HT_Temperature "[%.1f °F]" { channel=“mihome:sensor_ht:158d00023d295f:temperature” }
Should do the trick!
2 Likes
H102
(CM6.5 H102)
December 12, 2018, 2:41pm
5
@vzorglub Beat me to it again.
I was trying to remember how to make the degrees symbol on my linux PC.
1 Like
bots444
(Matt Botsford)
December 12, 2018, 2:43pm
6
Thank you so much. I’m going to try this when I get home. That Xiaomi Gateway is a PIA. I’m going to reset it and start this from scratch.
vzorglub
(Vincent Regaud)
December 12, 2018, 2:45pm
7
I never remember I copy them from the openhab log!!
H102
(CM6.5 H102)
December 12, 2018, 2:51pm
8
Got it, F °
Ctrl + Shift + u (this will show an underlined u) and then the unicode value (in this case B0
) and follow it by an enter .
bots444
(Matt Botsford)
December 13, 2018, 3:46am
9
So I just tried what you said and it just put the F° on there but still the C° number value. Can I put a math conversion in what you gave me to change the value?
vzorglub
(Vincent Regaud)
December 13, 2018, 7:19am
10
Yes,
Change your item:
Number:Temperature Basement_HT_Temperature "[%.1f °C]" { channel=“mihome:sensor_ht:158d00023d295f:temperature” }
in your sitemap:
Text item=Basement_HT_Temperature label="Temp Basement [%.1f °F]"
And OH will handle the conversion
2 Likes
bots444
(Matt Botsford)
December 13, 2018, 2:34pm
11
I was able to get this to work in the site map with the changes you suggested. I am trying to use the Habpanel to display this information because this is going to be a wall mounted set up. I was looking at doing this through a custom template. But it doesn’t seem to work there.
Im using the following in a custom widget {{itemValue(‘Basement_HT_Temperature’)}}
H102
(CM6.5 H102)
December 13, 2018, 2:40pm
12
Try this
{{'% .1f' | sprintf: itemValue ('Basement_HT_Temperature'). split ('') [0]}}
bots444
(Matt Botsford)
December 13, 2018, 2:54pm
13
That didn’t work either it just output the text
H102
(CM6.5 H102)
December 13, 2018, 2:56pm
14
Im still learning HABPanel myself.
Try this
{{itemValue('Basement_HT_Temperature').split(' ')[1]}}
bots444
(Matt Botsford)
December 13, 2018, 2:57pm
15
Trust me I appreciate all your help here, I’m new to this too. When i did that it just gives me the C degree, no value
H102
(CM6.5 H102)
December 13, 2018, 3:02pm
16
Forgot the first part.
{{'%.1f' | sprintf:itemValue('Basement_HT_Temperature').split(' ')[0]}}{{itemValue('Basement_HT_Temperature').split(' ')[1]}}
bots444
(Matt Botsford)
December 13, 2018, 3:04pm
17
Ok that got me the value reported by the item, so now it says 21.4C. Still not in Fahrenheit
H102
(CM6.5 H102)
December 13, 2018, 3:05pm
18
If you drop the UOM on the item, like below, what happens?
Number Basement_HT_Temperature "[%.1f °F]" { channel=“mihome:sensor_ht:158d00023d295f:temperature” }
bots444
(Matt Botsford)
December 13, 2018, 3:10pm
19
That changed the C to an F but still the Celsius value displayed. So now it says 21.4F
H102
(CM6.5 H102)
December 13, 2018, 3:13pm
20
Yep, that confirms that the UOM takes care of the conversion from item to sitemap only.
May need a rule to convert the temp.