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
on my Raspi4 the last installed influxd-package was no more able to start the service. CPU-load was at 100%, the “systemctl start influxd” routine was running in a loop. As the smarthome generates many data the service took longer to start as expected by the new startup-script influxd-systemd-start.sh .
Fix: in ./usr/lib/influxdb/scripts/influxd-systemd-start.sh:
increase the sleep timer (in my case from 1 to 5):
...
while [ "$result" != "200" ]; do
sleep 5
result=$(curl -k -s -o /dev/null $url -w %{http_code})
...
InfluxDB is an open source time series database built by InfluxData and used in e.g. Openhab for data persistance. For small computers like raspi’s it is a best practice to compress the database regurlarly.
Why not using cron ?
Well, it works.. the only (security)-drawback is to grant /bin/bash to the influx-user:
cat /etc/cron.daily/00influx:
#!/bin/bash
#execute
/home/pi/1_influxrepair.sh
cat /home/pi/1_influxrepair.sh:
#!/bin/bash
service influxdb stop
echo "before su"
su influxdb -c /home/pi/1_subscript.sh
echo "after su"
whoami
service influxdb start
cat /home/pi/1_subscript.sh:
#!/bin/bash
echo "now in sub shell"
whoami
cd /var/lib/influxdb
influx_inspect buildtsi -compact-series-file -datadir ./data -waldir ./wal
exit
echo "exiting sub shell"
You must be logged in to post a comment.