Hi all,
I am working on an automatic e-mail report with various usage infos and statistics for the past week. getting desperate with my weather values. I managed to send my gas and power consumption and tried to do it for weather in the same manner but I always get an error:
2022-06-06 11:32:58.346 [ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID 'mail-1' failed: f != org.openhab.core.library.types.DecimalType in mail
The items for wind and temperature are dimensionless Number items.
I split up the calculation to find the source for the error and I guess it arises during the creation of the e-mail. This is the calculation part:
var Rx = now.minusDays(7)
var ReportWindMax1 = AT_Dachflache_Wind.maximumSince(Rx, "jdbc")
logInfo ("Log Mailreport", "WindMax Woche: " + ReportWindMax1.toString)
var Number ReportWindMax = ReportWindMax1.state as Number
logInfo ("Log Mailreport", "WindMax Woche State: " + ReportWindMax.toString)
var ReportWindAvg1 = AT_Dachflache_Wind.averageSince(Rx, "jdbc")
logInfo ("Log Mailreport", "WindAvg Woche: " + ReportWindAvg1.toString)
var Number ReportWindAvg = ReportWindAvg1 as Number
logInfo ("Log Mailreport", "WindAvg Woche State: " + ReportWindAvg.toString)
var ReportTempMax1 = AT_Dachflache_Temperature.maximumSince(Rx, "jdbc")
logInfo ("Log Mailreport", "TempMax Woche: " + ReportTempMax1.toString)
var ReportTempMax = ReportTempMax1.state as Number
logInfo ("Log Mailreport", "WindAvg Woche: " + ReportTempMax.toString)
var ReportTempLow1 = AT_Dachflache_Temperature.minimumSince(Rx, "jdbc")
logInfo ("Log Mailreport", "TempLow Woche: " + ReportTempLow1.toString)
var ReportTempLow = ReportTempLow1.state as Number
logInfo ("Log Mailreport", "TempLow State: " + ReportTempLow.toString)
var ReportTempAvg1 = AT_Dachflache_Temperature.averageSince(Rx, "jdbc")
logInfo ("Log Mailreport", "TempAvg Woche: " + ReportTempAvg1.toString)
var Number ReportTempAvg = ReportTempAvg1 as Number
logInfo ("Log Mailreport", "TempAvg State: " + ReportTempAvg.toString)
Log result for this part:
2022-06-06 11:32:57.144 [INFO ] [hab.core.model.script.Log Mailreport] - WindMax Woche: JdbcItem [name=AT_Dachflache_Wind, state=28.44, timestamp=2022-06-02T14:09:52.597+02:00[Europe/Berlin]]
2022-06-06 11:32:57.147 [INFO ] [hab.core.model.script.Log Mailreport] - WindMax Woche State: 28.44
2022-06-06 11:32:57.972 [INFO ] [hab.core.model.script.Log Mailreport] - WindAvg Woche: 3.129599539862326
2022-06-06 11:32:57.975 [INFO ] [hab.core.model.script.Log Mailreport] - WindAvg Woche State: 3.129599539862326
2022-06-06 11:32:58.070 [INFO ] [hab.core.model.script.Log Mailreport] - TempMax Woche: JdbcItem [name=AT_Dachflache_Temperature, state=32.9, timestamp=2022-06-05T15:49:02.288+02:00[Europe/Berlin]]
2022-06-06 11:32:58.073 [INFO ] [hab.core.model.script.Log Mailreport] - WindAvg Woche: 32.9
2022-06-06 11:32:58.163 [INFO ] [hab.core.model.script.Log Mailreport] - TempLow Woche: JdbcItem [name=AT_Dachflache_Temperature, state=6.7, timestamp=2022-06-03T04:18:12.971+02:00[Europe/Berlin]]
2022-06-06 11:32:58.166 [INFO ] [hab.core.model.script.Log Mailreport] - TempLow State: 6.7
2022-06-06 11:32:58.284 [INFO ] [hab.core.model.script.Log Mailreport] - TempAvg Woche: 17.45758061814136
2022-06-06 11:32:58.287 [INFO ] [hab.core.model.script.Log Mailreport] - TempAvg State: 17.45758061814136
I use StringBuilder to create the e-mail. Here’s an excerpt for one consumption value (gas usage previous week) and for the maximum wind value:
message.append("Gasverbrauch in der Vorwoche: " + String.format("%.2f", GasMeterVorwoche) +" m³")
logInfo ("Log Mailreport", "Mail creation. Consumption table created successfully.")
message.append("Wind Max: " + String.format("%.2f", ReportWindMax) +" m/s.")
I can see the (German) logInfo for the successful creation of the consumption table but the next message is the error:
2022-06-06 11:32:58.293 [INFO ] [hab.core.model.script.Log Mailreport] - Mailerstellung beginnt: Aufbau des Strings.
2022-06-06 11:32:58.342 [INFO ] [hab.core.model.script.Log Mailreport] - Mailerstellung. Verbrauchstabelle erstelt.
2022-06-06 11:32:58.346 [ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID 'mail-1' failed: f != org.openhab.core.library.types.DecimalType in mail
I tried to change the types in the var definition from “as Number” to “as Decimaltype” back and forth but it doesn’t work. I don’t see any difference in the value types of the consumption values compared to the weather values. Calculation also works. There is just some weird issue with publishing.
Any ideas how to solve the issue?
Thanks, Max