I need to say command in a rule to tell my the temperature outside, but my sensor sometimes add a large number to the item.
Sometimes the number is -2.80000003, and when I use the say command it tells my something like 2.8 million degrees.
Is it possible to tell it to only add 0.1 numbers, so it only tells me -2,8
say("The temperature is " + Temp_ude.state.toString + "Grader","voicerss:daDK","sonos:PLAY1:RINCON_949F3E72CEE801400")
when
…//Your Trigger
then
var string TextString
TextString= "The temperature is "+ String::format(“Temp %.1f °C” ,Temp_ude.state.toString) + “Grader”
LogInfo (“SaySomething”, “TextString. {}”, TextString)
say(TextString,“voicerss:daDK”,“sonos:PLAY1:RINCON_949F3E72CEE801400”)
end
I get an error running the rule, I did try to only run the the say command, and there is also an error
rule "Godmorgen hilsen"
when
Item Panel_Lock changed
then
say("The temperature is "+ String::format("Temp %.1f °C" ,Temp_ude.state.toString) + "Grader","voicerss:daDK","sonos:PLAY1:RINCON_B8E937B7EB3601400")
end
I’m at my system now and can test!
This did work for me:
rule "SayTemperature"
when
Item TestSomething changed
then
var String AudioSink
AudioSink= "sonos:PLAY1:RINCON_949F3E7D2EF401400"
var String SayText
SayText="Die Temperatur ist "+ CPUTemperature.state + " Grad Celcius"
SayText=SayText.replace(".",",")
logInfo("SayTemperature", "SayText: {}",SayText)
say(SayText,"voicerss:deDE",AudioSink)
end
I needed the .replace bercause the numbers are stored “english” i.e. the decimal seperator is a point, in order to get the correct german sentence I replaced the “.” with a “,”! Otherwise the said text would have been your observed large number!
Note that only the stored number is coming from the item, hence no need for the “°C” and the preceeding “Temp”.
My CPUTemprature has a value of “54.2000000000000028421709430404007434844970703125” according a REST API call, however the SayText is " Die Temperatur ist 54,2 Grad Celcius"!!
Sorry for earlier posting with a not working example. I’m really missing the VPN to my raspi, no way to look at my rules when I’m not at home
Hi
I did try to test your code, it tells me all the numbers in the say and the loginfo
Here is the modified code
rule "SayTemperature"
when
Item Panel_Lock changed
then
var String AudioSink
AudioSink= "sonos:PLAY1:RINCON_949F3E72CEE801400"
var String SayText
SayText="Temperaturen er "+ Temp_ude.state + " Grader Celcius"
SayText=SayText.replace(".",",")
logInfo("SayTemperature", "SayText: {}",SayText)
say(SayText,voicerss:daDK,AudioSink)
end
You can do all of the changes (replace as well as the format) in one go without variable…
This is my rule file, working fine:
rule "Voice Testing Rule"
when
Item Voice_Robot changed from OFF to ON
then
say("Temperaturen i kontoret er" + kontor_Temperature.state.format("%.1f").replace(".",",") + "grader!")
end