Re: LUA Pass2php
Posted: Sunday 15 January 2017 10:59
You know other valves that should be better?
I also found some of Honeywell
I also found some of Honeywell
Code: Select all
if($bigdif<=-0.6&&$brander=="Off"&&$timebrander>20)sw('brander','On', 'brander1 dif = '.$bigdif.', was off for '.convertToHours($timebrander));
elseif($bigdif<=-0.5&&$brander=="Off"&&$timebrander>60)sw('brander','On', 'brander2 dif = '.$bigdif.', was off for '.convertToHours($timebrander));
elseif($bigdif<=-0.4&&$brander=="Off"&&$timebrander>120)sw('brander','On', 'brander3 dif = '.$bigdif.', was off for '.convertToHours($timebrander));
elseif($bigdif<=-0.3&&$brander=="Off"&&$timebrander>180)sw('brander','On', 'brander4 dif = '.$bigdif.', was off for '.convertToHours($timebrander));
elseif($bigdif<=-0.2&&$brander=="Off"&&$timebrander>240)sw('brander','On', 'brander5 dif = '.$bigdif.', was off for '.convertToHours($timebrander));
elseif($bigdif<=-0.1&&$brander=="Off"&&$timebrander>300)sw('brander','On', 'brander6 dif = '.$bigdif.', was off for '.convertToHours($timebrander));
elseif($bigdif<=0 &&$brander=="Off"&&$timebrander>1800)sw('brander','On', 'brander7 dif = '.$bigdif.', was off for '.convertToHours($timebrander));
elseif($bigdif>0 &&$brander=="On" &&$timebrander>30)sw('brander','Off','brander8 dif = '.$bigdif.', was on for '.convertToHours($timebrander));
elseif($bigdif>=0 &&$brander=="On"&&$timebrander>180)sw('brander','Off','brander9 dif = '.$bigdif.', was on for '.convertToHours($timebrander));
elseif($bigdif>=-0.1&&$brander=="On"&&$timebrander>300)sw('brander','Off','brander10 dif = '.$bigdif.', was on for '.convertToHours($timebrander));
elseif($bigdif>=-0.2&&$brander=="On"&&$timebrander>420)sw('brander','Off','brander11 dif = '.$bigdif.', was on for '.convertToHours($timebrander));
elseif($bigdif>=-0.3&&$brander=="On"&&$timebrander>540)sw('brander','Off','brander12 dif = '.$bigdif.', was on for '.convertToHours($timebrander));
elseif($bigdif>=-0.4&&$brander=="On"&&$timebrander>660)sw('brander','Off','brander13 dif = '.$bigdif.', was on for '.convertToHours($timebrander));
elseif($bigdif>=-0.5&&$brander=="On"&&$timebrander>780)sw('brander','Off','brander14 dif = '.$bigdif.', was on for '.convertToHours($timebrander));
elseif($bigdif>=-0.6&&$brander=="On"&&$timebrander>900)sw('brander','Off','brander15 dif = '.$bigdif.', was on for '.convertToHours($timebrander));
Code: Select all
$Setliving=14;
$setpointliving=apcu_fetch('setpointliving');
if($setpointliving!=0&&apcu_fetch('tliving_set')<time-10795){apcu_store('setpointliving',0);$setpointliving=0;}
if($setpointliving!=2){
Code: Select all
#!/bin/bash
LASTCRON=`curl -s --connect-timeout 2 --max-time 5 "http://127.0.0.1/secure/lastcron.php"`
TIME=$(date +"%s")
TIME=$((TIME - 30))
if [ "$LASTCRON" -gt "$TIME" ] ; then
exit
else
DOMOTICZ=`curl -s --connect-timeout 2 --max-time 5 "http://127.0.0.1:8084/json.htm?type=command¶m=udevice&idx=203&nvalue=0&svalue=Off"`
STATUS=`echo $DOMOTICZ | jq -r '.status'`
if [ "$STATUS" == "OK" ] ; then
exit
else
sleep 5
DOMOTICZ=`curl -s --connect-timeout 2 --max-time 5 "http://127.0.0.1:8084/json.htm?type=command¶m=udevice&idx=203&nvalue=0&svalue=Off"`
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:8084/json.htm?type=command¶m=udevice&idx=203&nvalue=0&svalue=Off"`
STATUS3=`echo $DOMOTICZ | jq -r '.status'`
if [ "$STATUS3" == "OK" ] ; then
exit
else
curl -s --connect-timeout 2 --max-time 5 --data-urlencode "text=Domoticz Bad - Restarting" --data "silent=false" http://127.0.0.1/secure/telegram.php
NOW=$(date +"%Y-%m-%d_%H%M%S")
cp /volume1/appstore/domoticz/var/domoticz.log /volume1/files/temp/domoticz-$NOW.txt
sudo /var/packages/domoticz/scripts/start-stop-status stop
sleep 8
sudo kill $(sudo netstat -anp | awk '/ LISTEN / {if($4 ~ ":8084$") { gsub("/.*","",$7); print $7; exit } }')
sleep 8
sudo /var/packages/domoticz/scripts/start-stop-status start
fi
fi
fi
fi
Code: Select all
<?php
echo apcu_fetch('cron10');
Code: Select all
root@raspberrypi:/home/pi# php -v
PHP 7.0.14-1~bpo8+1 (cli) ( NTS )
Copyright (c) 1997-2016 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies
with Zend OPcache v7.0.14-1~bpo8+1, Copyright (c) 1999-2016, by Zend Technologies
Code: Select all
c = ''
s = ''
i = ''
t = ''
for k,v in pairs(devicechanged) do c = c..k.."|"..v.."#" end
for k,v in pairs(otherdevices) do s = s..k.."|"..v.."#" end
for k,v in pairs(otherdevices_idx) do i = i..k.."|"..v.."#" end
for k,v in pairs(otherdevices_lastupdate) do t = t..k.."|"..v.."#" end
--os.execute('/home/pi/domoticz/scripts/lua/pass2php/pass2php.php "'..c..'" "'..s..'" "'..i..'" "'..t..'" &')
os.execute('curl -s --data "c='..c..'&s='..s..'&i='..i..'&t='..t..'" http://127.0.0.1/secure/pass2php.php &')
commandArray={}
return commandArray
Code: Select all
<?php error_reporting(E_ALL);ini_set("display_errors","on");date_default_timezone_set('Europe/Amsterdam');
define('time',$_SERVER['REQUEST_TIME']);$actions=0;
$c=ex($_REQUEST['c']);
foreach($c as $device=>$status){
if(@include 'http://127.0.0.1/secure/pass2php/'.$device.'.php'){
//Filter the 'set level' stuff away for dimmers
if(in_array($device,array('Verlichting Slaapkamer'))){
if($status=='Off')apcu_store('s'.$device,'Off');
else apcu_store('s'.$device,filter_var($status,FILTER_SANITIZE_NUMBER_INT));
}else apcu_store('s'.$device,$status);
apcu_store('t'.$device,time);
$dev=$device;
}
}
if(!isset($dev))die();
include 'http://127.0.0.1/secure/__CRON.php';
function sw($idx,$action='',$info=''){
lg('SWITCH '.$idx.' '.$action.' '.$info);
if(empty($action))file_get_contents('http://127.0.0.1:8080/json.htm?type=command¶m=switchlight&idx='.$idx.'&switchcmd=Toggle');
else file_get_contents('http://127.0.0.1:8080/json.htm?type=command¶m=switchlight&idx='.$idx.'&switchcmd='.$action);
global $actions;$actions=$actions+1;
}
Code: Select all
<?php
if($s['TEST']=='On')sw($i['Verlichting Dressoir'],'On');
Code: Select all
lg('4. Egregius Start of Pass2PHP');
Code: Select all
print('1. script started')
c = ''
s = ''
i = ''
t = ''
for k,v in pairs(devicechanged) do c = c..k.."|"..v.."#" end
for k,v in pairs(otherdevices) do s = s..k.."|"..v.."#" end
for k,v in pairs(otherdevices_idx) do i = i..k.."|"..v.."#" end
for k,v in pairs(otherdevices_lastupdate) do t = t..k.."|"..v.."#" end
--os.execute('/home/pi/domoticz/scripts/lua/pass2php/pass2php.php "'..c..'" "'..s..'" "'..i..'" "'..t..'" &')
print('2. os execute started')
os.execute('curl -s --data "c='..c..'&s='..s..'&i='..i..'&t='..t..'" http://127.0.0.1/secure/pass2php.php &')
print('3. os execute ended')
commandArray={}
return commandArray
Hi, thanks for your reply. When adding the debug lines this shows up in the log:sincze wrote:Do you have the LG function as well in the pass2php?
What happens if you add some debug lines ??
example just below: $c=ex($_REQUEST['c']);
add:does a line show up in domoticz log?? to indicate the pass2php was called ??Code: Select all
lg('4. Egregius Start of Pass2PHP');
Add some debug lines to your lua as well:
Does the 1,2,3 show up in your domoticz log?Code: Select all
print('1. script started') c = '' s = '' i = '' t = '' for k,v in pairs(devicechanged) do c = c..k.."|"..v.."#" end for k,v in pairs(otherdevices) do s = s..k.."|"..v.."#" end for k,v in pairs(otherdevices_idx) do i = i..k.."|"..v.."#" end for k,v in pairs(otherdevices_lastupdate) do t = t..k.."|"..v.."#" end --os.execute('/home/pi/domoticz/scripts/lua/pass2php/pass2php.php "'..c..'" "'..s..'" "'..i..'" "'..t..'" &') print('2. os execute started') os.execute('curl -s --data "c='..c..'&s='..s..'&i='..i..'&t='..t..'" http://127.0.0.1/secure/pass2php.php &') print('3. os execute ended') commandArray={} return commandArray
Code: Select all
2017-01-30 08:56:43.574 LUA: 1. script started
2017-01-30 08:56:43.582 LUA: 2. os execute started
2017-01-30 08:56:43.595 LUA: 3. os execute ended
2017-01-30 08:56:43.683 => 4. Egregius Start of Pass2PHP
Code: Select all
foreach($c as $device=>$status){
Code: Select all
foreach($c as $device=>$status){
lg($device.' = '.$status);
OK now is see a lot of devices and there information. When i press the switch "TEST" is see this:Egregius wrote:Look's good, the php script is called.
You can remove those print and lg commands, but we'll add others now:
replace:with:Code: Select all
foreach($c as $device=>$status){
Then you should see a line for each deviceupdate likeCode: Select all
foreach($c as $device=>$status){ lg($device.' = '.$status);
2017-01-30 08:56:43.683 => TEST = On
TEST should then be the name of the file in the pass2php folder: TEST.php (case sensitive!)
Code: Select all
2017-01-30 09:19:28.925 => 4. Egregius Start of Pass2PHP
2017-01-30 09:19:28.927 => TEST = On
2017-01-30 09:19:28.929 => =
Code: Select all
<?php
lg($device.' = '.$status)