Pass2PHP

Moderator: leecollings

ropske
Posts: 483
Joined: Tuesday 12 August 2014 5:37
Target OS: Raspberry Pi / ODroid
Domoticz version: V3_8394
Location: Rumbeke,Belgium
Contact:

Re: LUA Pass2php

Post by ropske »

You know other valves that should be better?
I also found some of Honeywell
ropske
Posts: 483
Joined: Tuesday 12 August 2014 5:37
Target OS: Raspberry Pi / ODroid
Domoticz version: V3_8394
Location: Rumbeke,Belgium
Contact:

Re: LUA Pass2php

Post by ropske »

script is running only for living room now (just want to test) ;)

but what i see is, when temperature is almost there, the script is switching off/on the brander
is this normal that this happens?
or am i doing something wrong?
(btw i added some debug lines to see what is happening :)

2017-01-23 23:05:48.762 => Executing device: Living with status: 20.9
2017-01-23 23:05:48.831 => difLiving: -0.1 and bigdif: -0.1
2017-01-23 23:05:48.840 => test: 1
2017-01-23 23:05:48.848 => setting radiator RSetliving with :28.0
2017-01-23 23:05:48.855 => Thermostaat_Living1: 28
2017-01-23 23:05:48.863 => RSetliving: 28.0
2017-01-23 23:05:48.870 => brander: Off timebrander: 197832
2017-01-23 23:05:48.876 => false
2017-01-23 23:05:48.891 => SWITCH 211 On brander6 dif = -0.1, was off for 7:57:12
2017-01-23 23:05:48.900 User: Admin initiated a switch command (211/Brander_Q2/On)

2017-01-23 23:06:24.645 => Executing device: Verbruik vaatwas with status: 0.0
2017-01-23 23:06:24.752 => difLiving: -0.1 and bigdif: -0.1
2017-01-23 23:06:24.759 => test: 1
2017-01-23 23:06:24.785 => setting radiator RSetliving with :28.0
2017-01-23 23:06:24.793 => Thermostaat_Living1: 28
2017-01-23 23:06:24.805 => RSetliving: 28.0
2017-01-23 23:06:24.817 => brander: On timebrander: 197868
2017-01-23 23:06:24.825 => false
2017-01-23 23:06:24.851 => SWITCH 211 Off brander10 dif = -0.1, was on for 7:57:48
2017-01-23 23:06:24.873 User: Admin initiated a switch command (211/Brander_Q2/Off)
User avatar
Egregius
Posts: 2582
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: v2024.7
Location: Beitem, BE
Contact:

Re: LUA Pass2php

Post by Egregius »

Yes, that's by design to avoid overheating.
Could be that you need to change the timings to suit your heating system/home.
ropske
Posts: 483
Joined: Tuesday 12 August 2014 5:37
Target OS: Raspberry Pi / ODroid
Domoticz version: V3_8394
Location: Rumbeke,Belgium
Contact:

Re: LUA Pass2php

Post by ropske »

okay, thanks for quick feedback ;)

i just thought it was me doing something wrong lol :p

will play a little bit with the timers, because i'm affraid by swichting off/on so quickly i will harm my heater

because when i switch my heater manually on, he starts running, but the actual heating only begins after a good 30seconds
User avatar
Egregius
Posts: 2582
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: v2024.7
Location: Beitem, BE
Contact:

Re: LUA Pass2php

Post by Egregius »

You find that quick?

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)); 
ropske
Posts: 483
Joined: Tuesday 12 August 2014 5:37
Target OS: Raspberry Pi / ODroid
Domoticz version: V3_8394
Location: Rumbeke,Belgium
Contact:

Re: LUA Pass2php

Post by ropske »

yeah, there was something wrong with saving the lastupdate time for every device
now it's updating normally, so i will test again tonight, i think it will be much better and normal like your script should work ;)

thanks!
ropske
Posts: 483
Joined: Tuesday 12 August 2014 5:37
Target OS: Raspberry Pi / ODroid
Domoticz version: V3_8394
Location: Rumbeke,Belgium
Contact:

Re: LUA Pass2php

Post by ropske »

all working ok, thank you ;)

still, got a question:

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){
if i understand this, i think that ''setpointliving'' is a kind of a manual override?
is this some kind of a button or is this a selector switch where you have manual/automatic?
ropske
Posts: 483
Joined: Tuesday 12 August 2014 5:37
Target OS: Raspberry Pi / ODroid
Domoticz version: V3_8394
Location: Rumbeke,Belgium
Contact:

Re: LUA Pass2php

Post by ropske »

if setpointliving = 2 => means probably manual override?
and when manual override is activated for around 3hours, then reset this?

am i correct?
you are using a selector switch for manual override?
User avatar
Egregius
Posts: 2582
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: v2024.7
Location: Beitem, BE
Contact:

Re: LUA Pass2php

Post by Egregius »

Totally correct.
Variable is set when choosed on my floorplan.
ropske
Posts: 483
Joined: Tuesday 12 August 2014 5:37
Target OS: Raspberry Pi / ODroid
Domoticz version: V3_8394
Location: Rumbeke,Belgium
Contact:

Re: LUA Pass2php

Post by ropske »

Thank you.

One 'strange ' thing:
my __verwarming.php is also running on a 10sec cron

but i added a debug line in it, it shows up sometimes after 20-30 seconds

before it was every 10seconds
i have added some more code in it than before

i will probably need to buy the new raspberry pi3 :p
now running at the b+ model
User avatar
Egregius
Posts: 2582
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: v2024.7
Location: Beitem, BE
Contact:

Re: LUA Pass2php

Post by Egregius »

Depends on how you trigger Domoticz to launch the event system.
If you 'update' a switch every 10 seconds it'll run every 10 sec.

But it shouldn't be an issue if it's sometimes executed after a longer time. Each temperature update will cause the event system to launch so it'll be executed.

If you really want it every 10 second you could do something with a bash script and cron.

I'm using this to be sure it's executed at maximum every two minutes:

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&param=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&param=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&param=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');
dutchdevil83
Posts: 130
Joined: Monday 31 October 2016 19:34
Target OS: Raspberry Pi / ODroid
Domoticz version: latest
Location: Netherlands
Contact:

Re: LUA Pass2php

Post by dutchdevil83 »

Hi i`m trying to get your script working but i am a newbie on php. I will run this on a raspberry pi can someone tell me which packages i need to install? Because i see you`re also using acpu? I don`t think this is standard installed on a pi? I have follow version running of php:

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
next question is there somewhere a "empty scratch file" so i can only have to fill mine own setup and don`t need to clear out egregius devices which are already filled in?
Hardware
1x Raspberry Pi
1x Razberry Z-Wave
1x RFXtrx433E
1x Toon
1x GoodWe Solarpanels
2x FGSD-002 Smoke Detector
1x FGBS-001 Binaire Sensor (RFID lezer)
7x FGMS-001 Motion Sensor
3x ZW089 Verzonken Deursensor
7x NC Wallplug
&lots of KaKu stuff
User avatar
Egregius
Posts: 2582
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: v2024.7
Location: Beitem, BE
Contact:

Re: LUA Pass2php

Post by Egregius »

you also need php7-apcu and php7-cli or apache2/nginx. I find a curl to a webserver is faster than running in php-cli.

No, there's no 'empty' version of the latest online. Latest stuff is on github, or as a base the minimal script on my site.
dutchdevil83
Posts: 130
Joined: Monday 31 October 2016 19:34
Target OS: Raspberry Pi / ODroid
Domoticz version: latest
Location: Netherlands
Contact:

Re: LUA Pass2php

Post by dutchdevil83 »

I really have no clue where to start.... I have php installed and running. Have looked at your examples over and over and follow the wiki on your github but nothing is happening when i pull a switch.... Here is the code i have edited so far:

script_device_passphp.lua:

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
Pass2php.php:

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&param=switchlight&idx='.$idx.'&switchcmd=Toggle');
	else file_get_contents('http://127.0.0.1:8080/json.htm?type=command&param=switchlight&idx='.$idx.'&switchcmd='.$action);
	global $actions;$actions=$actions+1;
}
a file TEST.php in the pass2php folder (switch is a dummy switch in domoticz named "TEST", other is a lamp named "Verlichting Dressoir":

Code: Select all

<?php
if($s['TEST']=='On')sw($i['Verlichting Dressoir'],'On');
In your wiki you describe the functions but in the examples your are using "ACPU_fetch" :?: What to use?
Hardware
1x Raspberry Pi
1x Razberry Z-Wave
1x RFXtrx433E
1x Toon
1x GoodWe Solarpanels
2x FGSD-002 Smoke Detector
1x FGBS-001 Binaire Sensor (RFID lezer)
7x FGMS-001 Motion Sensor
3x ZW089 Verzonken Deursensor
7x NC Wallplug
&lots of KaKu stuff
User avatar
sincze
Posts: 1299
Joined: Monday 02 June 2014 22:46
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.4
Location: Netherlands / Breda Area
Contact:

Re: LUA Pass2php

Post by sincze »

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:

Code: Select all

lg('4. Egregius Start of Pass2PHP');
does a line show up in domoticz log?? to indicate the pass2php was called ??

Add some debug lines to your lua as well:

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
Does the 1,2,3 show up in your domoticz log?
Pass2php
LAN: RFLink, P1, OTGW, MySensors
USB: RFXCom, ZWave, Sonoff 3
MQTT: ZIgbee2MQTT,
ZWAVE: Zwave-JS-UI
WIFI: Mi-light, Tasmota, Xiaomi Shelly
Solar: Omnik, PVOutput
Video: Kodi, Harmony HUB, Chromecast
Sensors: You name it I got 1.
User avatar
Egregius
Posts: 2582
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: v2024.7
Location: Beitem, BE
Contact:

Re: LUA Pass2php

Post by Egregius »

If you send all 4 lua tables you don't need apcu because all information is in the arrays created in the pass2php file
I store all information in apcu cache, with that pass2php is down to 19 msecs and my floorplan went from 30 to less than 1 millisecond.
dutchdevil83
Posts: 130
Joined: Monday 31 October 2016 19:34
Target OS: Raspberry Pi / ODroid
Domoticz version: latest
Location: Netherlands
Contact:

Re: LUA Pass2php

Post by dutchdevil83 »

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:

Code: Select all

lg('4. Egregius Start of Pass2PHP');
does a line show up in domoticz log?? to indicate the pass2php was called ??

Add some debug lines to your lua as well:

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
Does the 1,2,3 show up in your domoticz log?
Hi, thanks for your reply. When adding the debug lines this shows up in the log:

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
I think this is good right...
Hardware
1x Raspberry Pi
1x Razberry Z-Wave
1x RFXtrx433E
1x Toon
1x GoodWe Solarpanels
2x FGSD-002 Smoke Detector
1x FGBS-001 Binaire Sensor (RFID lezer)
7x FGMS-001 Motion Sensor
3x ZW089 Verzonken Deursensor
7x NC Wallplug
&lots of KaKu stuff
User avatar
Egregius
Posts: 2582
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: v2024.7
Location: Beitem, BE
Contact:

Re: LUA Pass2php

Post by Egregius »

Look's good, the php script is called.
You can remove those print and lg commands, but we'll add others now:

replace:

Code: Select all

foreach($c as $device=>$status){
with:

Code: Select all

foreach($c as $device=>$status){
  lg($device.' = '.$status);
Then you should see a line for each deviceupdate like
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!)
dutchdevil83
Posts: 130
Joined: Monday 31 October 2016 19:34
Target OS: Raspberry Pi / ODroid
Domoticz version: latest
Location: Netherlands
Contact:

Re: LUA Pass2php

Post by dutchdevil83 »

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:

Code: Select all

foreach($c as $device=>$status){ 
with:

Code: Select all

foreach($c as $device=>$status){
  lg($device.' = '.$status); 
Then you should see a line for each deviceupdate like
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!)
OK now is see a lot of devices and there information. When i press the switch "TEST" is see this:

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 => =
Hardware
1x Raspberry Pi
1x Razberry Z-Wave
1x RFXtrx433E
1x Toon
1x GoodWe Solarpanels
2x FGSD-002 Smoke Detector
1x FGBS-001 Binaire Sensor (RFID lezer)
7x FGMS-001 Motion Sensor
3x ZW089 Verzonken Deursensor
7x NC Wallplug
&lots of KaKu stuff
User avatar
Egregius
Posts: 2582
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: v2024.7
Location: Beitem, BE
Contact:

Re: LUA Pass2php

Post by Egregius »

OK that's good. Remove the lg line again, or place // before it to place it as a comment, could be usefull later.
Then in pass2php/TEST.php add this:

Code: Select all

<?php
lg($device.' = '.$status)
Then we know that the path and filename is good.
Last edited by Egregius on Monday 30 January 2017 10:30, edited 1 time in total.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest