I have a Philips Hue motion sensor that also provides the temperature. However, it is reporting about 3 °F too high so I want to create a rule that will update a second item with the corrected temperature for use in my sitemap, etc. However, I am getting odd results from what I thought would be an easy task. Can anyone help me figure out why this is not working?
rule "MB Temp Sensor Correction"
when
Item PC_LastSeen changed
then
logInfo("MBTempSensor", MasterBedroomTemperatureSensorTemperature.state.toString)
var Number MBTemp1 = MasterBedroomTemperatureSensorTemperature.state as Number
var Number MBTempAdj = MBTemp1 - 3
logInfo("MBTemp1", MBTemp1.toString)
logInfo("MBTempAdj", MBTempAdj.toString)
end
This is what I get in the logs when checking the values above.
This works! How did you know that the state is a QuantityType? When I look at the item and when I referred to the binding info, they both say the temperature is a Number item.
I never knew what profiles were or how they worked. This is great info. In this case, it is a little more complicated for Celsius, but I can see uses for profiles in the future.
I don’t understand what you mean. The whole point of QuantityTypes is that you may add 2mm and 3 miles without worrying about unit conversions, the framework sorts it out for you. For that to work, you do have to supply the units for each number … and we call that the QuantityType, a number-with-units.
In your case you want to subtract 3 °F, it doesn’t matter if that is from something in °C or K
When I tried using the offset profile for the channel link, I got this message in the OpenHAB logs:
2020-05-08 13:36:09.698 [WARN ] [nternal.profiles.SystemOffsetProfile] - Received a QuantityType state ‘23.12 °C’ with unit, but the offset is defined as a plain number without unit (-3), please consider adding a unit to the profile offset.
Doing the adjustment via a rule is easier as that is Fahrenheit. Trying to figure out an offset for Celsius to equal 3.5 °F was harder.
Now, I have it figured out. Using the offset profile is nice. I was able to enter the offset as -3.5 °F, and it is working fine now. No need for the rule at this point, but I am also glad to have more knowledge about how to do temperature calculations in rules, too.