rule "wu pws submit"
when
Time cron "0 */1 * * * ?"
then
var string logstring = "weatherunderground.rules";
logInfo(logstring,"Triggered rule");
var double tempval = (Netatmo_Outside_Temperature.state as QuantityType<Number>)
logInfo(logstring,"Netatmo_Outside_temperature: {}", tempval);
end
(FYI: I’m hacking with the WeatherUnderground PWS Send rules that i found in this forum)
Obviously that number doesn’t have this resolution and it gets the " ℃" unit, which I suspect is my casting error. This problem greatly impact my rules as it seems that dumb comparison doesn’t work either, such as “27.5 > 28.299999237060546875 ℃” which clearly it is not.
How do I “strip” out the unit ? Should I create a new, different item ?
Thanks
rule "wu pws submit"
when
Time cron "0 */1 * * * ?"
then
var string logstring = "weatherunderground.rules"
logInfo(logstring,"Triggered rule")
var Number tempval = (Netatmo_Outside_Temperature.state as QuantityType<Number>).doubleValue
logInfo(logstring,"Netatmo_Outside_temperature: {}", tempval.toString)
end
such resolution is way beyond the capability of the sensor thus I think is a strange conversion artifact.
It solves the comparison error, btw, so I’m quite happy
It is a side effect with how most programming languages represent floating point numbers. It can not represent every possible number between the max value (somewhere around 1.710^308) and the minimum value (somewhere around -1.710^308). Instead it gets as close as it can but that often results in decimal places that seem to go on forever.
For the most part it is a quirk that developers just need to be aware of and deal with. The usual solution is to round the value when presenting it to the user but keep all the decimal places for calculations.