Had a working Zone cleaning Rule under OH2.5 now i upgraded to latest OH3 and this rule does not work anymore beside Clean all:
// ----------------------------------------------------------------------------
rule "zone control - zone selection"
// ----------------------------------------------------------------------------
when
Member of gZoneSwitch received update
then
logInfo("zone.rules", "update received from item: " + triggeringItem)
val zoneSwitch = triggeringItem as SwitchItem
val lastUpdate = now
zoneSwitch.getGroupNames().forEach[groupName |
if (groupName != "gZoneLastSwitch")
{
logDebug("zone.rules", "find related members of " + groupName + " in other group gZoneLastUpdate from triggering item " + triggeringItem.name)
gZoneLastUpdate.members.filter[updateItem | !updateItem.getGroupNames.contains(groupName)].forEach[ updateItem |
logInfo("zone.rules", "posting update to " + updateItem.name)
updateItem.postUpdate(lastUpdate.toString())
]
}
else
{
logDebug("zone.rules", "ignoring group " + groupName)
}
]
end
// ----------------------------------------------------------------------------
rule "zone control - action"
// ----------------------------------------------------------------------------
when
Item zoneAction received command
then
logInfo("zone.rules", "zoneAction command received: " + receivedCommand)
var StringBuilder zoneCmd = new StringBuilder
var StringBuilder roomCmd = new StringBuilder
// use this to get the room numbers
// XiaVac_action_Command.sendCommand("get_room_mapping[]")
if (gAllZones.state == ON)
{
logInfo("zone.rules", "sending cmd to device: app_start")
XiaVac_action_Command.sendCommand("app_start")
return;
}
// sort by timestamp and loop throug items
gZoneLastUpdate.members.sortBy[(state as DateTimeType).getZonedDateTime.toInstant.toEpochMilli].forEach[zoneLastUpdateItem |
logDebug("zone.rules", "--> "+ zoneLastUpdateItem)
// loop until we find the right group...
zoneLastUpdateItem.getGroupNames().forEach[groupName |
logDebug("zone.rules", "----> "+ groupName)
if (groupName != "gZoneLastUpdate")
{
logDebug("zone.rules", "find related members of " + groupName + " in other group gZoneSwitch")
// find the switch item from the same room group
gZoneSwitch.members.filter[zoneSwitchItem |
zoneSwitchItem.getGroupNames.contains(groupName)
&& zoneSwitchItem.getGroupNames.contains("gZoneSwitch")].forEach[ zoneSwitchItem |
logDebug("zone.rules", "found related switch item " + zoneSwitchItem.name + " with state " + zoneSwitchItem.state)
if (zoneSwitchItem.state == ON)
{
var zoneType = transform("MAP", "robo_room_coordinates.map", zoneSwitchItem.name + "#type")
var zoneCoordinates = transform("MAP", "robo_room_coordinates.map", zoneSwitchItem.name + "#coordinates")
logInfo("zone.rules", zoneCoordinates + "-" + zoneSwitchItem.name + " is ON. {zoneType:" + zoneType + "; zoneCoordinates: " + zoneCoordinates + "}")
// not sure if we can assign a new var by reference, so to be safe, just use if..else and duplicate code
if (zoneType == "zone")
{
if (zoneCmd.length == 0)
{
zoneCmd.append("app_zoned_clean[")
}
zoneCmd.append(zoneCoordinates)
}
else if (zoneType == "room")
{
if (roomCmd.length == 0)
{
roomCmd.append("app_segment_clean[" + zoneCoordinates)
}
else
{
roomCmd.append(", " + zoneCoordinates)
}
}
logDebug("zone.rules", roomCmd.toString)
}
]
}
]
]
// if we have rooms AND zones, rooms wins - duplicate code here as well
if (roomCmd.length != 0)
{
val cmd = roomCmd.toString + "]"
logInfo("zone.rules", "sending cmd to device: " + cmd )
XiaVac_action_Command.sendCommand(cmd)
}
else if (zoneCmd.length != 0)
{
val cmd = zoneCmd.toString + "]"
logInfo("zone.rules", "sending cmd to device: " + cmd )
XiaVac_action_Command.sendCommand(cmd)
}
else
{
logInfo("zone.rules", "no zone or room selected. nothing to do.")
}
zoneAction.postUpdate("start")
end
// ----------------------------------------------------------------------------
rule "zone control - init"
// ----------------------------------------------------------------------------
when
System started
then
val lastUpdate = now
gZoneLastUpdate.members.forEach(item |
item.postUpdate(lastUpdate.toString())
)
end
Error in Log:
==> /logs/openhab.log <==
2022-02-16 09:08:17.325 [INFO ] [openhab.core.model.script.zone.rules] - update received from item: zKueche (Type=SwitchItem, State=ON, Label=Küche, Category=kitchen, Groups=[gKueche, gZoneSwitch, gAllZones])
2022-02-16 09:08:17.334 [INFO ] [openhab.core.model.script.zone.rules] - posting update to zEsszimmerLastUpdate
2022-02-16 09:08:17.403 [WARN ] [b.core.model.script.actions.BusEvent] - Cannot convert '2022-02-16T09:08:17.327743+01:00[Europe/Berlin]' to a state type which item 'zEsszimmerLastUpdate' accepts: [DateTimeType, UnDefType].
2022-02-16 09:08:17.408 [INFO ] [openhab.core.model.script.zone.rules] - posting update to zWohnzimmerLastUpdate
2022-02-16 09:08:17.411 [WARN ] [b.core.model.script.actions.BusEvent] - Cannot convert '2022-02-16T09:08:17.327743+01:00[Europe/Berlin]' to a state type which item 'zWohnzimmerLastUpdate' accepts: [DateTimeType, UnDefType].
==> /logs/openhab.log <==
2022-02-16 10:39:32.127 [INFO ] [openhab.core.model.script.zone.rules] - zoneAction command received: start
2022-02-16 10:39:32.130 [ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID 'robo-2' failed: Could not cast NULL to org.openhab.core.library.types.DateTimeType; line 55, column 37, length 21 in robo
Could anyone help me out ?
Thanks