My goal is to execute an python-script when the Battery-charge has reached 70%
My rule was not executed, the error as shown above is seen in the log.
My faulty script:
rule "BYD 70"
when
Item KOSTALPLENTICOREPlus70WithBattery_BatteryCharge received update
then
var BYDBat = (KOSTALPLENTICOREPlus70WithBattery_BatteryCharge.state as Number).floatValue
if ((KOSTALPLENTICOREPlus70WithBattery_BatteryCharge.state as Number).floatValue = 70.0) {
sendTelegram("bot1",
"BYD hat > 70 % Ladung " + BYDBat)
executeCommandLine("python3 /etc/openhab2/scripts/BYDI.py")
logDebug("logtest", "BYDBat = " + BYDBat)
logDebug("logtest", "state = " + KOSTALPLENTICOREPlus70WithBattery_BatteryCharge.state)
}
end
Reason of the error: the if-statement is misleading, to check if the value is equal it needs two “==”:
if ((KOSTALPLENTICOREPlus70WithBattery_BatteryCharge.state as Number).floatValue == 70.0) {
working-code:
rule "BYD 70"
when
Item KOSTALPLENTICOREPlus70WithBattery_BatteryCharge received update
then
var BYDBat = (KOSTALPLENTICOREPlus70WithBattery_BatteryCharge.state as Number).floatValue
if ((KOSTALPLENTICOREPlus70WithBattery_BatteryCharge.state as Number).floatValue == 70.0) {
sendTelegram("bot1",
"BYD hat > 70 % Ladung " + BYDBat)
executeCommandLine("python3 /etc/openhab2/scripts/BYDI.py")
logDebug("logtest", "BYDBat = " + BYDBat)
logDebug("logtest", "state = " + KOSTALPLENTICOREPlus70WithBattery_BatteryCharge.state)
}
end
to debug BYDBat/KOSTALPLENTICOREPlus70WithBattery_BatteryCharge.state debugging needs to be enabled like shown at: https://www.cipv6.de/worp/index.php/2019/10/23/how-do-i-debug-tradfri-on-openhab/
openhab> log:get org.eclipse.smarthome.model.script
DEBUG
openhab> log:set Info org.eclipse.smarthome.model.script
openhab> log:get org.eclipse.smarthome.model.script
INFO
You must be logged in to post a comment.