I have some rules in which i update items with a timestamp.
And they actually work, but in openhab 2 they throw errors in logs so I want them fixed now as they could potentially be broken later down the road.
Item:
Contact AR50ReedSwitch "AR50ReedSwitch [%s]" <lock> { mqtt=">[brokerXXX:state:CLOSED:0], >[brokerXXX:state:OPEN:1], <[brokerXXX:state:MAP(lock.map)" }
Contact AR51ReedSwitch "AR51ReedSwitch [%s]" <lock> { mqtt=">[brokerXXX:state:CLOSED:0], >[brokerXXX:state:OPEN:1], <[brokerXXX:state:MAP(lock.map)" }
DateTime AR5x_LastUpdate " Reedswitch uppdaterad [%1$ta %1$tR]" <clock>
Number AR52BatteryVolt "AR52BatteryVolt [%s V]" <energy> { mqtt="<[brokerXXX:state:default], >[brokerXXX:state:*:${state}]" }
Number AR53BatteryPercentage "AR53BatteryPercentage [%s %%]" <energy> { mqtt="<[brokerXXX:state:default], >[brokerXXX:state:*:${state}]" }
String AR5xBattery_komplett "Batterylevel [%s]" <energy>
Rule:
rule "AR5x when device was last seen and double string"
when
Item AR50ReedSwitch received update or
Item AR51ReedSwitch received update or
Item AR52BatteryVolt received update or
Item AR53BatteryPercentage received update
then
postUpdate(AR5x_LastUpdate, new DateTimeType())
AR5xBattery_komplett.postUpdate("" + String::format("%s %%", (AR52BatteryVolt.state as DecimalType).floatValue()) + "V / " + String::format("%s %%", (AR53BatteryPercentage.state as DecimalType).floatValue()) + " %")
end
Errors thrown are:
ipt.engine.ScriptExecutionThread] - Rule ‘AR5x when device was last seen and double string’: org.eclipse.smarthome.core.library.types.DecimalType
Other rule that throw errors:
Rule:
rule "Sunrise/Sunset changed"
when
Item Sunrise_Time changed
or Item Sunset_Time changed
then
var DateTime sunrise = new DateTime((Sunrise_Time.state as DateTimeType).calendar.timeInMillis)
var DateTime sunset = new DateTime((Sunset_Time.state as DateTimeType).calendar.timeInMillis
Sunrise_Sunset.postUpdate(String::format("%02d:%02d / %02d:%02d", sunrise.getHourOfDay(), sunrise.getMinuteOfHour(), sunset.getHourOfDay(), sunset.getMinuteOfHour()))
end
and item:
DateTime Sunrise_Time "Sunrise [%1$tH:%1$tM]" {channel="astro:sun:local:rise#start" }
DateTime Sunset_Time "Sunset [%1$tH:%1$tM]" {channel="astro:sun:local:set#start" }
String Sunrise_Sunset "Sunrise / Sunset [%s]" <sun>
Error:
[el.core.internal.ModelRepositoryImpl] - Configuration model ‘sunrise_sunset.rules’ has errors, therefore ignoring it: [8,5]: missing ‘)’ at ‘Sunrise_Sunset’
I tried looking in eclipse designer but i really do not have a clue what I’m doing.
Used ctrl+space and saw that datetimetype is not valid (?). But what should it be substituted for in that case?
I’m confused to say the least and hope someone could help me.