-
Platform information:
- Hardware: Synoology Diskstatio DS218play, Realtek RTD1296
- OS: DSM 6.2-23739 Update 2 (Custom Linux)
- Java Runtime Environment: Java8, 1.8.0_181
- openHAB version: 2.3.0 Release Build
-
Issue of the topic: Problem with string format
I have a Item with following definition:
Number ProxyAussen_Temp1 "Labor / Keller [%1.1f°C]" <temperature> (Temperaturen, EG_Aussen, UnterG)
The format ([%1.1f°C] works well in my sitemap and app.
I send the same item with Telegram on my handy (at given times or for testing by a trigger).
Here is my problem with the format. In the Telegram rule i want to format it as the same like in the sitemap (Number with one digit).
First i thougt the format is defined in the item defination. In the telegram rule i have to convert into a string. At the same time the string gets its format. Actually i have a workaround:
/* Temperatur senden */
rule "Telegram_Test1"
when
Time cron "0 0 18 * * ?" or Time cron "0 0 6 * * ?" or Item MySwitch3 changed to ON
then
sendTelegram("Benedikt", "Aussentemperatur Labor beträgt %.4s °C", ProxyAussen_Temp1.state.toString) // ergibt "21.6 °C", String auf 4 Zeichen beschränkt
end
I get the right format only if temperature is over 10 °C, if its under 10 there will be 2 digits after the comma.
For me there are two questions:
- Can i convert the item “Number ProyAussen_Temp1” into a String including the format?
- Is there a other method instead of “.state.toString” (i tryed “.state.floatValue” but i did not work)?