[SOLVED] Say 'rough' temperature

Hi all,

happy new year to the OpenHAB community!

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")

I also checked the rounding topic, described here https://community.openhab.org/t/how-can-i-round-a-value-to-2-digits/45828/14. unfortunately that did not help me much.

Many thanks!

Matthias

What does your items file for Netatmo_Outdoor_Temperature look like?

Similar to this:

Number:Temperature Netatmo_Outdoor_Temperature        "Temperature [%.1f %unit%]"          <temperature>      { channel = "netatmo:NAModule1:home:outside:Temperature" }

Also, it may help if you post the entire rule.

Instead of using the .toString method, use the .format method, which allows you to use string formatters on the state…i.e.

say("Es sind draußen " + Netatmo_Outdoor_Temperature.state.format("%d") + "Grad")

will only say the integer part of the temperature, leaving off the decimal…

1 Like

Great idea @bartus.:+1:

I would think that using the new UoM on the item like in the example above would work.:thinking: Any thoughts on why it wouldn’t?

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.

Hi @bartus, Hi @H102,

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.

Cheers,
Matthias

Did you try the original rule using the item example posted above?

What does your item look like?

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

and the relevant item is.

Number Netatmo_Outdoor_Temperature  "Terasse [%.1f %unit%]"           <temperature>   (temp, draussen)                ["CurrentTemperature"]  {channel = "netatmo:NAModule1:4aaba655:030000374eb9:Temperature" }

Matthias

I’m not sure how this will work with say but you can try this way:

say("Es sind draußen " + "Number={}", String::format("%.2f", (TestNumberItem.state as Number).doubleValue))

Do you know if the item will work with a JS transformation?

Hi,

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.

Hope this helps,

James

2 Likes

Hi @FloatingBoater

you solution actually works.

say("Es sind draußen " + String::format("%.1f", (Netatmo_Outdoor_Temperature.state as DecimalType).floatValue())+" Grad.")

gives me now a good and understandable output.

Many thanks!

Matthias

1 Like