Say command and number item

Hi

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

Try this:

say("The temperature is ", String::format("Temp %.1f °C", Temp_ude.state) + "Grader","voicerss:daDK","sonos:PLAY1:RINCON_949F3E72CEE801400")

I get this error, when trying to run the rule

2018-11-26 21:00:49.908 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'Godmorgen hilsen': f != org.eclipse.smarthome.core.library.types.DecimalType

What error were you getting before?
I added .toString below.

say("The temperature is ", String::format("Temp %.1f °C", Temp_ude.state.toString) + "Grader","voicerss:daDK","sonos:PLAY1:RINCON_949F3E72CEE801400")

I get this error now

2018-11-26 21:31:04.740 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'Godmorgen hilsen': f != java.lang.String

with this command, it works

say("Godmorgen alle sammen,.....  temperaturen udenfor er lige nu" + Temp_ude.state + "Grader","voicerss:daDK","sonos:PLAY1:RINCON_949F3E72CEE801400")
  
1 Like

Awesome!

@Dim will be glad to hear the news.

I knew we could figure it out.:joy: Now I gotta read more on using say.:smile:

1 Like

Sorry the 2. command works with no errors in the log, but it still tells me the temperature with all the zeros.

I will send you in the deep waters, but you will be able to see several examples of what you want to do:

This one uses another scripting engine (JSR223) and you don’t have to use exactly the same stuff.
You can see several formatting examples in the code.

1 Like

Why don’t you compose the string to be said in an extra variable an let the TTS say this variable?

I am not sure what you saying, can you show me an example?

Something like this:

rule “SaySomething”

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

Hi

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 get this error

2018-11-28 15:37:51.092 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'Godmorgen hilsen': f != java.lang.String

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 :disappointed:

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
2018-11-28 21:02:35.254 [INFO ] [marthome.model.script.SayTemperature] - SayText: Temperaturen er 3,2222222 Grader Celcius

How does your item looks like, my is like this;

Number 		Temp_ude			"Temperatur [%.1f °C]"		<temperature>		(Temperatur,Vejr)	

Hi

Now it works, this is the right format for the command:

Temp_ude.state.format("%.1f")

Actually my item has no formatting in the definition, I have that in the sitemap file.
I can’t say why it works differently.

Thanks for your help, it really helped me with this code, because i had the same issue.

SayText=SayText.replace(".",",")

If your problem is solved, please mark the post that solved it with “solution” checkmark

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
1 Like