I don't think the developers have interest of doing that. If you watch the forum all that mathers is lua and dzvents. Almost like lot's of domoticz users hate PHP.
Not so difficult to loop the scripts.
In the pass2php file there's code that gets executed every x seconds, every minute, every 2 minutes, every 4 hours, Just like you want.
To be sure the scripts are called, and there wouldn't be the need for a device update I also call the pass2php script from cron.
In crontab:
Code: Select all
* * * * * /var/www/html/secure/cron.sh >/dev/null 2>&1
cron.sh:
Code: Select all
#!/bin/bash
DOMOTICZ=`curl -s --connect-timeout 2 --max-time 5 "http://127.0.0.1:8080/json.htm?type=devices&rid=1"`
STATUS=`echo $DOMOTICZ | jq -r '.status'`
if [ "$STATUS" == "OK" ] ; then
lastcron=0
lastcron=`curl -s --connect-timeout 2 --max-time 15 http://127.0.0.1/secure/cache.php?fetch=cron5`
now=`date +%s`
since=$(($now-$lastcron))
if [ $since -lt 60 ]; then
curl -s --connect-timeout 2 --max-time 15 "http://127.0.0.1/secure/pass2php.php" > /dev/null 2>/dev/null &
sleep 9.99
curl -s --connect-timeout 2 --max-time 15 "http://127.0.0.1/secure/pass2php.php" > /dev/null 2>/dev/null &
sleep 9.99
curl -s --connect-timeout 2 --max-time 15 "http://127.0.0.1/secure/pass2php.php" > /dev/null 2>/dev/null &
sleep 9.99
curl -s --connect-timeout 2 --max-time 15 "http://127.0.0.1/secure/pass2php.php" > /dev/null 2>/dev/null &
sleep 9.99
curl -s --connect-timeout 2 --max-time 15 "http://127.0.0.1/secure/pass2php.php" > /dev/null 2>/dev/null &
sleep 9.99
curl -s --connect-timeout 2 --max-time 15 "http://127.0.0.1/secure/pass2php.php" > /dev/null 2>/dev/null &
else
shutdown -r now
fi
else
sleep 5
DOMOTICZ=`curl -s --connect-timeout 2 --max-time 5 "http://127.0.0.1:8080/json.htm?type=devices&rid=1"`
STATUS2=`echo $DOMOTICZ | jq -r '.status'`
if [ "$STATUS2" == "OK" ] ; then
exit
else
sleep 5
DOMOTICZ=`curl -s --connect-timeout 2 --max-time 5 "http://127.0.0.1:8080/json.htm?type=devices&rid=1"`
STATUS3=`echo $DOMOTICZ | jq -r '.status'`
if [ "$STATUS3" == "OK" ] ; then
exit
else
shutdown -r now
fi
fi
fi
This script also restarts the domoticz server in case something went wrong.
And this in pass2php.php:
Code: Select all
if(apcu_fetch('cron5')<time-9){
apcu_store('cron5',time);
if(apcu_fetch('cron604800')<time-604790){
apcu_store('cron604800',time);
include('/var/www/html/secure/_cron604800.php');
}
if(apcu_fetch('cron120')<time-118){
apcu_store('cron120',time);
include('/var/www/html/secure/_cron120.php');
include('/var/www/html/secure/gcal/gcal.php');
if(apcu_fetch('cron28800')<time-27790){
apcu_store('cron28800',time);
include('/var/www/html/secure/_cron28800.php');
}
if(apcu_fetch('savecache')<time-3600){
apcu_store('savecache',time);
include('/var/www/html/secure/savecache.php');
}
}
if(apcu_fetch('cron60')<time-58){
apcu_store('cron60',time);
include('/var/www/html/secure/_cron60.php');
include('/var/www/html/secure/_rolluiken.php');
}
include('/var/www/html/secure/_cron5.php');
include('/var/www/html/secure/_verwarming.php');
}
ben53252642 wrote: ↑Wednesday 31 January 2018 12:51
I'd love to have all my scripts integrated directly into the Domoticz DB, native PHP integration would mean I can get rid of most of my bash scripts running in screen sessions.
I don't share that opinion. I like to have as much separated as possible. Let domoticz do it's core business, wich is in my case handle all Z-wave devices.
All the rest I like to take out of it and run it separately.