Hey,
I’m setting up a openhab config which reads out several DIY battery powered arduino sensors with RFM69 transceivers, they communicate through MQTT, which is all working as it should.
Because it are battery powered devices, I’m trying to make a rule that checks for last Update of those instances. if the sensors haven’t been updated in the last 30 minutes and if it is between 6am and 11pm, I get an e-mail saying me which devices are not updating anymore. Or at least that’s the purpose, I’m using the same technique as in this rules example: check battery status
[code]
// Check last update if no update for the last half hour, sends a msg
import org.openhab.core.library.types.*
import org.openhab.core.persistence.*
import org.openhab.model.script.actions.*
import org.openhab.core.library.types.DecimalType
import org.openhab.joda.time.*
import org.openhab.binding.mpd.*
import org.openhab.binding.mqtt.*
val String mailTo = “xxx@xxx.xx”
rule “Check every hour for last update of all nodes”
when
Time cron “0 0/30 7-23 * * ?”
then
if (! Update_time.allMembers.filter([now.minusMinutes(30).isAfter((state as DateTimeType).calendar.timeInMillis)]).empty) {
val report = Update_time.allMembers.filter([state]).sortBy([state]).map[
name + “: " + state.format(”%d%%")
].join("\n")
val message = "Last Updates:\n\n" + report + "\n\nRegards,\n\nopenHab"
sendMail(mailTo, "Updates failed", message)
}
end[/code]
The cron job works, but I get the following error:
java.lang.ClassCastException: org.openhab.core.library.types.DateTimeType cannot be cast to java.lang.Boolean
below is the rule that calculates the times of last update, this one works as it should:
when
Item itm_doorbell_uptime_mqtt received update
then
postUpdate(mqtt_doorbell_LastUpdate, new DateTimeType())
end
Anybody that can help with solving my problem, thx.