jwiseman
(Mr. Wiseman (OH 4 on Pi4))
August 28, 2023, 12:59pm
1
I have a group (Group:Number:AVG) that I show on an eMail coming out of OH 3.4.
{ awaymessage.append("\n - Average Rating is " + gAirIndoorRating.state + “%”) }
This is how it’s being shown → Average Rating is 94.33333333333333333333333333333333%
The item is defined as this and I even tried the meta option to fix it but it didn’t work.
Group:Number:AVG gAirIndoorRating "Average Air Quality Indoor Rating [%.0f %%]" { stateDescription=""[pattern="%.1f",min="0",max="100", readOnly=true] }
My system is file based, so the solution would need to be in within the .item / .rule files.
Best, Jay
Please be aware that the pattern is only for displaying the state in UI. If you want a specific format in a rule, you have to use something like String.format("%.1f",gAirIndoorRating.state.toString)
jwiseman
(Mr. Wiseman (OH 4 on Pi4))
August 28, 2023, 4:48pm
3
Used your syntax but it failed with this error.
Script execution of rule with UID ‘default-194’ failed: f != java.lang.String in default
Here’s the eMail syntax for that line.
{ awaymessage.append(“\n - Average Rating is “) }
{ awaymessage.append(String.format(”%.1f”,gAirIndoorRating.state.toString) + “%”) }
Best, Jay
yes, sure, .toString
is nonsense…
try
{ awaymessage.append(String.format("%.1f %%", gAirIndoorRating.state)) }
or
{ awaymessage.append(String.format("%.1f %%", (gAirIndoorRating.state as Number))) }
instead…
jwiseman
(Mr. Wiseman (OH 4 on Pi4))
August 28, 2023, 9:44pm
5
Both syntax scenarios failed with this error.
failed: f != org.openhab.core.library.types.DecimalType
Best, Jay
jwiseman
(Mr. Wiseman (OH 4 on Pi4))
August 29, 2023, 3:26pm
6
Here’s the final solution:
{ awaymessage.append(“\n - Average Rating is “) }
{awaymessage.append(String.format(”%.1f %%”, (gAirIndoorRating.state as DecimalType).floatValue))}
Best, Jay
1 Like
Jepp, always struggling with types
system
(system)
Closed
October 10, 2023, 9:06am
8
This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.