Hi!
Since two days I’am trying to convert follwing rule (thank you to the guy who scripted it) to OH3. The rule is generally working, except the time issue (lastBelow6A = Grid_Power.previousState(true).timestamp.time). I tried different approaches out of examples in the forum, but I cannot get it working. I also created a DateTime Item, which stores the Timestamp of the last change for Grid_Power…no luck (thx to @rlkoshak for all the tutorials, but I didn’t manage it…)
Could anybody help me please
val switchOffTimeout = 20 // stop charging if current is below 6A for specified seconds
var long lastBelow6A = 0
if (lastBelow6A == 0) {
// store time when below 6A for 1st time
lastBelow6A = powGrid.previousState(true).timestamp.time
}
val secondsBelow6A = (now.toInstant().toEpochMilli() - lastBelow6A)/1000
if (secondsBelow6A > switchOffTimeout) {
logInfo("Wallbox", "Below 6A for " + secondsBelow6A + "s, switching off.")
GoeCharger_AllowCharging.sendCommand(OFF)
return
end
One of my not working changes:
if (lastBelow6A == 0) {
// store time when below 6A for 1st time
lastBelow6A = (powGrid.previousState(true) as DateTimeType).zonedDateTime.toInstant.toEpochMilli
}
val secondsBelow6A = (now.toInstant().toEpochMilli() - lastBelow6A)/1000
if (secondsBelow6A > switchOffTimeout) {
logInfo("Wallbox", "Below 6A for " + secondsBelow6A + "s, switching off.")
GoeCharger_AllowCharging.sendCommand(OFF)
return
}