Hello,
“simple” problem, but don’t found aworking solution
I get the average temperatur for last 24 hours from my influxdb:
TempAvgToday = Garden_Temperature.averageSince(now.minusHours(24), "influxdb")
Result is i.e. 12.469565645672
Calculating with this is OK, but I also need to send the variable with a push-message inside the rule like:
sendPushoverMessage(pushoverBuilder("Temperature-info:" +
"\nDurchschnittstemperatur 24h : " + TempAvgToday + " Grad" +
.withSound("cashregister").withApiKey("aasi5xxxx1d26"))
And here I will send only with 2 decimal numbers like:
12.46
But how? Value must not be roundet mathematically correct, “cutting” is also enough.
I test some hints, i.e. this:
val dummy = (TempAvgToday).floatValue() * 100
dummy = Math::round(dummy)
TempAvgToday = dummy / 100
But here I get: 12.460000000000
I know in sitemap I can use the openHAB formatting with: .%2f
But in a rule and push-message ?
rossko57
(Rossko57)
July 9, 2019, 11:22am
2
I think you can use the same formatter in a rule
String::format("%.2f", TempAvgToday)
Thanks Rossko, I try:
sendPushoverMessage(pushoverBuilder("Rasen-Bewaesserung-Infos:" + String::format("%.2f", TempAvgToday))
.withSound("cashregister").withApiKey("aasi5mxxxxxxxxxxxxxxxxxx1d26"))
But get:
[ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule ‘automatic irrigation, calculate irrigation time …’: f != org.eclipse.smarthome.core.library.types.DecimalType
(or must I also activate these lines again, with this lines it seems to work. Unclear why …:
// dummy = (TempAvgToday).floatValue() * 10
// dummy = Math::round(dummy)
// TempAvgToday = dummy / 10
rossko57
(Rossko57)
July 9, 2019, 12:32pm
4
I think you’d need to massage TempAvgToday into a Number type or something.
(TempAvgToday as DecimalType)
maybe
Thanks, but not working …
Had tried (from my side more “try and error”, maybe this is totally wrong) :
TempAvgToday = Garden_Temperature.averageSince(now.minusHours(12), “influxdb”) as DecimalType
Just need to change from 12.469565645672 to 12.46
Really so hard in oH ?
rlkoshak
(Rich Koshak)
July 9, 2019, 6:06pm
6
DecimalType is the wrong type. (TempAvgToday as Number)
. The averageSince method returns a number.
How did you declare TempAvgToday? I don’t see the var
definition.
Yes, sorry,.
TempAvgToday is declared as Number
rlkoshak
(Rich Koshak)
July 9, 2019, 7:12pm
8
then DecimalType is definitely the wrong type. Use Number.
I’ve not done much with String::format directly, it may require primitives. If as Number
doesn’t work try TempAvgToday.floatValue.