During my holiday season I had a bit time to try Google Cloud TTS. Phantasic speach quality. When I try to say the current temperature of my outside netatmo module, it gives me the exact value, including all 19 decimal places…that is actually too acurate for me. I just need maximum one decimal place, so only the rough temperature;-) Unfortunately I don’t get it.
This I use as part of my (yet) very easy rule:
say("Es sind draußen " + Netatmo_Outdoor_Temperature.state.toString + "Grad")
Not sure of it myself - I’ve had a lot of issues wrangling UoM types when casting between types in my rules…I’ve ended up just using the basic item types and formatting the states myself.
thanks for the quick answer. The rule now looks like:
rule "Voice Testing Rule"
when
Item Voice_Robot changed from OFF to ON
then
say("Es sind draußen " + Netatmo_Outdoor_Temperature.state.format("%d") + "Grad")
end
Actually this does not work. in openhab.log it says:
[ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'Voice Testing Rule': d != java.math.BigDecimal
Forgot to mention, taht I’m on OpenHAB 2.5.0 Build #1486.
Hi @H102
thanks for pointing me to that answer. Actually I missed that initially.
Unfortunately that also does not work. It still gives the very accurate number on SONOS and not the rounded value.
My rule now is:
rule "Voice Testing Rule"
when
Item Voice_Robot changed from OFF to ON
then
say("Es sind draußen " + Netatmo_Outdoor_Temperature.state.toString + "Grad")
end
I have a similar situation, with a very precise float temp value coming from the OneWire binding.
Here’s the code I’ve been using to round the value to create a spoken status message…
Message = "It is " + new DateTimeType().format("%1$tl %1$tM on %1$tA %1$tB %1$td") + "."
Message = Message + " "
/* Precision formatting hack to convert .state to DecimalType, then floatValue, then String
* As default, owInside.state.toString gives 19.0625, and we only need 19.1
*/
Message = Message + "The temperature is " + String::format("%.1f", (owInside.state as DecimalType).floatValue()) + " indoors" + " and " + String::format("%.1f", (owOutside.state as DecimalType).floatValue()) + " outside."
Say(Message)
The full Java docs give the details of the format string, e.g. "%.1f" above gives one digit after the point.