Hi,
Just upgraded my setup to OH3 - looks and works great!
didnt have any major issues, just some rules needed changing time formats, sony binding needs manual upgrade, needed to enable basic auth for my remote access via reverse proxy, and some influxdb tables needed to be switched to integer…
however, there is this one error in rule that I can’t figure out
2021-08-07 18:05:35.407 [ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID 'energy-11' failed: The name 'Seconds' cannot be resolved to an item or type; line 127, column 29, length 7 in energy
this is the rule that stopped working
All Lights runtime Living Room stopped"
when
Item All_Lights changed to OFF
then
var DateTimeType prevOnState = All_Lights_LastOnState.state as DateTimeType
var Number execDuration = Seconds::secondsBetween(new DateTime(prevOnState.zonedDateTime.toInstant.toEpochMilli), now ).getSeconds()
postUpdate(All_Lights_Last_Runtime_Sec, execDuration)
var Number dailyTotalSeconds = execDuration + All_Lights_Today_Runtime_Sec.state as Number
postUpdate(All_Lights_Today_Runtime_Sec, dailyTotalSeconds)
var Number dailyTotalMinutes = dailyTotalSeconds / 60
postUpdate(All_Lights_Today_Runtime_Min, dailyTotalMinutes)
end
DateTime simply does not exist any more. Any time you see DateTime in rule, that line needs to change. What it needs to change to is pretty well covered in that link above. in this case look at #4.
Finally got it working, those instructions are not that straight forward for non-developers, so I used the chat below the instructions to steal some ideas
I’m sure you guys are sick of annoying repetitive n00b questions about broken rules after OH3 upgrade, sorry for that
here is the working code for future reference in case someone will bump into it
(it basically calculates time difference between 2 timestamps (one is when Item is ON, second one when item is OFF. and so it accumulates daily usage of an Item)
rule "Daily AC runtime Living Room started"
when
Item ACLiving1 changed to 33
then
postUpdate(ACLiving1_LastOnState, new DateTimeType())
end
rule "Daily AC runtime Living Room stopped"
when
Item ACLiving1 changed to 0
then
var DateTimeType prevOnState = (ACLiving1_LastOnState.state as DateTimeType).getZonedDateTime()
var Number execDuration = Duration.between(prevOnState, ZonedDateTime.now()).toSeconds()
logInfo("test.rules", "execDuration: " + execDuration)
var Number dailyTotalSeconds = execDuration + ACLiving1_Today_Runtime_Sec.state as Number
postUpdate(ACLiving1_Today_Runtime_Sec, dailyTotalSeconds)
var Number dailyTotalMinutes = dailyTotalSeconds / 60
postUpdate(ACLiving1_Today_Runtime_Min, dailyTotalMinutes)
end