if (((Battery_SOC.state as DecimalType) >= spp_GridSupportSocLevelMax)
2017-05-21 23:26:51.974 [ERROR] [o.o.c.s.ScriptExecutionThread ] - Error during the execution of rule 'SP PRO GO: STOP MinSoc grid support anytime at SocLevelMax': Could not invoke method: org.openhab.model.script.lib.NumberExtensions.operator_greaterEqualsThan(org.openhab.core.types.Type,java.lang.Number) on instance: null
changing the rule to:
if (((Battery_SOC.state as DecimalType) >= (spp_GridSupportSocLevelMax as DecimalType))
2017-05-21 23:35:36.616 [ERROR] [o.o.c.s.ScriptExecutionThread ] - Error during the execution of rule 'SP PRO GO: STOP MinSoc grid support anytime at SocLevelMax': Cannot cast org.openhab.core.library.items.NumberItem to org.openhab.core.library.types.DecimalType
var Number batSoc = Battery_SOC.state as DecimalType
var Number lvlMin = spp_GridSupportSocLevelMin as DecimalType
if (batSoc <= lvlMin)
and also get:
2017-05-22 00:30:18.995 [ERROR] [o.o.c.s.ScriptExecutionThread ] - Error during the execution of rule 'SP PRO GO: START MinSoc grid support anytime at SocLevelMin': Cannot cast org.openhab.core.library.items.NumberItem to org.openhab.core.library.types.DecimalType
I need the comparison for the DecimalType (Battery_SOC) â not the change it to in()
You should test if your state is an instance of DecimalType:
if(!(Battery_SOC.state instanceof DecimalType)) //if not instance of DecimalType
Battery_SOC.postUpdate(0) // Set to 0, as Battery_SOC is undef or null
...
if ( (Battery_SOC.state) <= 30)
if ( (Battery_SOC.state as Number) <= 30)
if ( (Battery_SOC.state as DecimalType) <= 30)
works for me too â and is not the issueâŠ
It is the SetPoint value in GridSupportSocLevelMin it does not like
interestingâŠ
here the complete rule for reference:
// ----- 170521 MaxG: START MinSoc grid support anytime at SocLevelMin
rule "SP PRO GO: START MinSoc grid support anytime at SocLevelMin"
when
Item Battery_SOC received update
then
logInfo("GridSupport1on1.rule", "Battery_SOC.state = {}", Battery_SOC.state)
logInfo("GridSupport1on2.rule", "spp_GridSupportSocLevelMin.state = {}", spp_GridSupportSocLevelMin.state)
logInfo("GridSupport1on3.rule", "spp_GridSupportManual.state = {}", spp_GridSupportManual.state)
// testing
if (!(Battery_SOC.state instanceof Decimaltype)
logInfo("GridSupport1on0.rule", "Battery_SOC is NOT a DecimalType")
if (((Battery_SOC.state as Number) <= spp_GridSupportSocLevelMin) && (spp_GridSupportManual.state == OFF)) {
logInfo("GridSupport1on4.rule", "evaluating Battery_SOC <= spp_GridSupportSocLevelMin")
if (spp_GridSupportAllowed.state == OFF) {
// set MinSoc flag ON
sendCommand(spp_GridSupportMinSoc, ON)
// switch grid support on
sendCommand(spp_GridSupportAllowed, ON)
postUpdate(spp_GridSupportAllowed, ON)
logInfo("GridSupport1on.rule", "GridSupportAllowed and MinSoc is now ON because of SOC <= SocLevelMin")
}
}
end
Youâre right: It is not a DecimalType!
What do I need to do to make this comparison work?
Which cast to what?
Also, refer to all error messages I have listed, which tell me what the problem is; but I do not know how to fix it.
It is a simple casting issue (I think)âŠ
The rule worked with comapring the BAttery_SOC with a literal number, but not when using the SetPoint value.
Also, where would I find the reference doc for the instanceof, casting types?
Are there isNumber, isInt, etc. functions?
Is there a Reference Manual?
// testing
if (!(Battery_SOC.state instanceof Decimaltype)
logInfo("GridSupport1on0.rule", "Battery_SOC is NOT a DecimalType")
if (!(spp_GridSupportSocLevelMin.state instanceof Decimaltype)
logInfo("GridSupport1on0.rule", "spp_GridSupportSocLevelMin is NOT a DecimalType")
both come back as not DecimalType.
What are they then?
2017-05-22 09:20:49.254 [INFO ] [.m.script.GridSupport1on1.rule] - Battery_SOC.state = 53.00
2017-05-22 09:20:51.809 [INFO ] [.m.script.GridSupport1on2.rule] - spp_GridSupportSocLevelMin.state = 60
2017-05-22 09:20:52.831 [INFO ] [.m.script.GridSupport1on3.rule] - spp_GridSupportManual.state = OFF
2017-05-22 09:20:54.405 [INFO ] [.m.script.GridSupport1on0.rule] - Battery_SOC is NOT a DecimalType
2017-05-22 09:20:55.983 [INFO ] [.m.script.GridSupport1on0.rule] - spp_GridSupportSocLevelMin is NOT a DecimalType
2017-05-22 09:20:57.568 [ERROR] [o.o.c.s.ScriptExecutionThread ] - Error during the execution of rule 'SP PRO GO: START MinSoc grid support anytime at SocLevelMin': Could not invoke method: org.openhab.model.script.lib.NumberExtensions.operator_lessEqualsThan(org.openhab.core.types.Type,java.lang.Number) on instance: null
There is a difference between Decimaltype and DecimalType.
The if() bracketing is wrong too.
Bear in mind your âsetpoint itemsâ are not items of type setpoint. You have just chosen to display/update some items on your sitemap using the âsetpointâ gizmo. Somewhere, somehow you will have defined the real types of those Items (I expect as Number types)
I think there is a catch-22 with setpoints. If your item starts off as undefined, the setpoint gizmo cannot alter it (how would you do âmore of undefinedâ). The item needs to be initialized first somehow
Oops⊠typo fixed â as a result both are now saying IS DecimalType
However, still get the error of:
2017-05-22 10:28:34.746 [INFO ] [.m.script.GridSupport1on1.rule] - Battery_SOC.state = 68.75
2017-05-22 10:28:34.772 [INFO ] [.m.script.GridSupport1on2.rule] - spp_GridSupportSocLevelMin.state = 73
2017-05-22 10:28:34.785 [INFO ] [.m.script.GridSupport1on3.rule] - spp_GridSupportManual.state = OFF
2017-05-22 10:28:34.798 [INFO ] [.m.script.GridSupport1on0.rule] - Battery_SOC IS a DecimalType
2017-05-22 10:28:34.810 [INFO ] [.m.script.GridSupport1on0.rule] - spp_GridSupportSocLevelMin IS a DecimalType
2017-05-22 10:28:34.890 [ERROR] [o.o.c.s.ScriptExecutionThread ] - Error during the execution of rule 'SP PRO GO: START MinSoc grid support anytime at SocLevelMin': The name '<XFeatureCallImplCustom> <= <XFeatureCallImplCustom>' cannot be resolved to an item or type.
With the comparison:
if ( (Battery_SOC <= spp_GridSupportSocLevelMin) && (spp_GridSupportManual.state == OFF) )
The SetPoint value have been initialised with:
rule "Bootstrap any setpoint / level value"
when
System started
then
logInfo("BootStrap.rule", "in Bootstrap rule: Levels...")
// spp_GridSupportSocLevelMin
if (spp_GridSupportSocLevelMin.state == Uninitialized) {
logInfo("BootStrap.rule", "spp_GridSupportSocLevelMin set to 31")
postUpdate(spp_GridSupportSocLevelMin, 31)
}
// spp_GridSupportSocLevelMax
if (spp_GridSupportSocLevelMax.state == Uninitialized) {
logInfo("BootStrap.rule", "spp_GridSupportSocLevelMax set to 40")
postUpdate(spp_GridSupportSocLevelMax, 40)
}
... plus more...
end