Pass2PHP

Moderator: leecollings

User avatar
Eddiever
Posts: 105
Joined: Thursday 27 April 2017 20:32
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.1
Location: The Netherlands (Hoogeveen)
Contact:

Re: Pass2PHP

Post by Eddiever »

I am giving this pass2php a try. Would love to get faster action. First things first. To install php-acpu as mentioned above (sudo apt-get install php-apcu I got the error message: can't find package php-acpu. Do I need to install php5-acpu insted?
User avatar
Egregius
Posts: 2582
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: v2024.7
Location: Beitem, BE
Contact:

Re: Pass2PHP

Post by Egregius »

I'm not sure. I have the repository for php7 and then it's just called php-apcu.
I guess it's the same but keep in mind that php7 is a lot faster.
User avatar
Egregius
Posts: 2582
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: v2024.7
Location: Beitem, BE
Contact:

Re: Pass2PHP

Post by Egregius »

Updated my sw(itch) function so it supports arrays:

Code: Select all

function sw($name,$action='Toggle',$comment=''){
    if(is_array($name)){
        foreach($name as $i){
            if($i=='media')sw(array('tv','denon','tvled','kristal'),$action);
            elseif($i=='lichtenbeneden')sw(array('pirgarage','pirkeuken','pirliving','pirinkom','eettafel','zithoek','tvled','kristal','bureel','garage','keuken','werkblad','wasbook','kookplaat','inkom','zolderg'),$action);
            elseif($i=='lichtenboven')sw(array('pirhall','lichtbadkamer1','lichtbadkamer2','kamer','tobi','alex','hall','zolder'),$action);
            elseif($i=='slapen')sw(array('pirhall','hall','lichtenbeneden','poortrf','dampkap','GroheRed'),$action);
            elseif($i=='weg')sw(array('slapen','lichtenbeneden','lichtenboven'),$action);
            else{if(apcu_fetch('s'.$i)!=$action)sw($i,$action);}
        }
    }else{
        $msg = 'SWITCH '.$name.' => '.$action;
        if(!empty($comment)) $msg.=' => '.$comment;
        lg($msg);
        if(apcu_exists('i'.$name))file_get_contents('http://192.168.2.2:8080/json.htm?type=command&param=switchlight&idx='.apcu_fetch('i'.$name).'&switchcmd='.$action);
        else{apcu_store('s'.$name,$action);apcu_store('t'.$name,time);}
        usleep(50000);
    }
} 
usage:

Code: Select all

sw('light','Off');//switches a single light off
sw(array('weg'),'Off');//switches all lights defined in group 'weg' off (only if they are not off)
sw(array('light','weg'),'Off');//switches of the single 'light' and the group 'weg'  
Very handy for repeated stuf :)
ropske
Posts: 483
Joined: Tuesday 12 August 2014 5:37
Target OS: Raspberry Pi / ODroid
Domoticz version: V3_8394
Location: Rumbeke,Belgium
Contact:

Re: Pass2PHP

Post by ropske »

Hi,
i upgraded my system a while ago to a pi3
now i want to log my data again to mysql stored on my nas server, so i want to install again mysqli
but i'm getting the error at the end below, some knows why?

pi@raspberrypi:~ $ sudo apt-get install php5-mysqlnd
Pakketlijsten worden ingelezen... Klaar
Boom van vereisten wordt opgebouwd
De statusinformatie wordt gelezen... Klaar
De volgende extra pakketten zullen geïnstalleerd worden:
libapache2-mod-php5 php5-cli php5-common php5-curl php5-readline
Voorgestelde pakketten:
php-pear
De volgende NIEUWE pakketten zullen geïnstalleerd worden:
php5-mysqlnd
De volgende pakketten zullen opgewaardeerd worden:
libapache2-mod-php5 php5-cli php5-common php5-curl php5-readline
5 opgewaardeerd, 1 nieuw geïnstalleerd, 0 te verwijderen en 70 niet opgewaardeerd.
Er moeten 0 B/4659 kB aan archieven opgehaald worden.
Na deze bewerking zal er 413 kB extra schijfruimte gebruikt worden.
Wilt u doorgaan? [J/n] j
Bezig met het inlezen van changelogs... Klaar
dpkg: onherstelbare fatale fout; er wordt gestopt:
bestand met de lijst bestanden van pakket 'dpkg' heeft geen afsluitend regeleinde
E: Sub-process /usr/bin/dpkg returned an error code (2)
User avatar
Egregius
Posts: 2582
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: v2024.7
Location: Beitem, BE
Contact:

Re: Pass2PHP

Post by Egregius »

Are you sure it's php5-mysqlnd you need? Isn't it just php5-mysql?
And why not go for php7.0?
ropske
Posts: 483
Joined: Tuesday 12 August 2014 5:37
Target OS: Raspberry Pi / ODroid
Domoticz version: V3_8394
Location: Rumbeke,Belgium
Contact:

Re: Pass2PHP

Post by ropske »

you know the command for php7 ? :p
ropske
Posts: 483
Joined: Tuesday 12 August 2014 5:37
Target OS: Raspberry Pi / ODroid
Domoticz version: V3_8394
Location: Rumbeke,Belgium
Contact:

Re: Pass2PHP

Post by ropske »

i just tried with this URL https://www.stewright.me/2016/03/turn-r ... eb-server/

but again the same dpkg error:

Bezig met het inlezen van changelogs... Klaar
Extraheren van sjablonen uit pakketten: 100%
Voorconfigureren van pakketten ...
dpkg: onherstelbare fatale fout; er wordt gestopt:
bestand met de lijst bestanden van pakket 'dpkg' heeft geen afsluitend regeleinde
E: Sub-process /usr/bin/dpkg returned an error code (2)
pi@raspberrypi:~ $
User avatar
Egregius
Posts: 2582
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: v2024.7
Location: Beitem, BE
Contact:

Re: Pass2PHP

Post by Egregius »

There's something wrong with your dpkg.
Translate the error and google...
User avatar
Egregius
Posts: 2582
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: v2024.7
Location: Beitem, BE
Contact:

Re: Pass2PHP

Post by Egregius »

Oh, I see you have another topic for that in http://www.domoticz.com/forum/viewtopic ... 28&t=18063

About pass2php, did I share this page already?

secure/cache.php:

Code: Select all

<?php
if(isset($_REQUEST['fetch']))echo apcu_fetch($_REQUEST['fetch']);
elseif(isset($_REQUEST['store'])&&isset($_REQUEST['value']))apcu_store($_REQUEST['store'],$_REQUEST['value']); 
With that file you can easily use the apcu cache from another system.
For example, check if the nas is on:

Code: Select all

#!/bin/bash
NAS=$(curl -s --connect-timeout 2 --max-time 5 'http://192.168.2.2/secure/cache.php?fetch=nas')
if [[ $NAS == 'On' ]];
then
	#do something
fi
Or set a variable:

Code: Select all

#!/bin/bash
curl -s --connect-timeout 2 --max-time 5 'http://192.168.2.2/secure/cache.php?store=nas&value=On
DarkAllMan
Posts: 52
Joined: Friday 23 December 2016 9:41
Target OS: Linux
Domoticz version:
Contact:

Re: Pass2PHP

Post by DarkAllMan »

Hi Egregius,

I have a problem that some of the PHP files are called multiple times at the same time.
For instance, when I change the status of a bulb, and I write to log, I get multiple entries at the same time.
Can you help me identify the issue here?
User avatar
Egregius
Posts: 2582
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: v2024.7
Location: Beitem, BE
Contact:

Re: Pass2PHP

Post by Egregius »

I'm pretty sure that if you would add a 'print' line in the lua script that you'll see that the lua script is called multiple times.
Depending on the code in your script it shouldn't be a big problem.
You could try to catch the issue in php with a timestamp in cache, something like:

Code: Select all

if(apcu_fetch('time_yourdevicename')<time-4){
    apcu_store('time_yourdevicename',time);
    //your code here
}
 
That would make the code only executed if it's more than 4 seconds ago. That would only be true if the second call of that device is at least 20 à 50 msecs ago (time to call the script and store the timestamp).
Snowdude
Posts: 11
Joined: Saturday 24 December 2016 10:34
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Pass2PHP

Post by Snowdude »

I have a script that reacts on a zwave light. I see in my logfiles that when I switch the lamp from domoticz the script get run twice, when I press the physical switch, my script runs once.
User avatar
Egregius
Posts: 2582
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: v2024.7
Location: Beitem, BE
Contact:

Re: Pass2PHP

Post by Egregius »

Script and lofiles please ;)
Snowdude
Posts: 11
Joined: Saturday 24 December 2016 10:34
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Pass2PHP

Post by Snowdude »

Here are my scripts: https://github.com/richarddeweerd/domot ... master/php

Logfile on and off switching of the lap "Overloop" from domoticz:

Code: Select all

2017-07-10 14:34:51.638 User: Admin initiated a switch command (92/Overloop/On)
2017-07-10 14:34:51.638 OpenZWave: Domoticz has send a Switch command! NodeID: 11 (0x0b)
2017-07-10 14:34:51.658 (ZWave) Light/Switch (Overloop)
2017-07-10 14:34:51.831 Notification sent (http) => Success
2017-07-10 14:34:51.832 Overloop = On
2017-07-10 14:34:51.914 (ZWave) Light/Switch (Overloop)
2017-07-10 14:34:52.104 Notification sent (http) => Success
2017-07-10 14:34:52.105 Overloop = On
2017-07-10 14:34:54.207 (ZWave) Usage (Overloop_power)
2017-07-10 14:34:54.251 (ZWave) General/kWh (Overloop_kWh)
2017-07-10 14:34:57.768 User: Admin initiated a switch command (92/Overloop/Off)
2017-07-10 14:34:57.769 OpenZWave: Domoticz has send a Switch command! NodeID: 11 (0x0b)
2017-07-10 14:34:57.799 (ZWave) Usage (Overloop_power)
2017-07-10 14:34:57.833 (ZWave) General/kWh (Overloop_kWh)
2017-07-10 14:34:57.870 (ZWave) Light/Switch (Overloop)
2017-07-10 14:34:57.899 Overloop = Off
2017-07-10 14:34:58.057 (ZWave) Light/Switch (Overloop)
2017-07-10 14:34:58.085 Overloop = Off
2017-07-10 14:34:58.202 (ZWave) Usage (Overloop_power)
2017-07-10 14:34:58.219 (ZWave) General/kWh (Overloop_kWh)
User avatar
Egregius
Posts: 2582
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: v2024.7
Location: Beitem, BE
Contact:

Re: Pass2PHP

Post by Egregius »

There are two lines of your zwave hardware in the log, so it's the switch that probably sends its status after a command.
Either check your node parameters or groups or use the workaround from http://www.domoticz.com/forum/viewtopic ... 92#p140236
Trigun
Posts: 390
Joined: Wednesday 30 November 2016 11:58
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.10717
Contact:

Re: Pass2PHP

Post by Trigun »

Hi egregius, is the script also working on the New version of domoticz?


Sent from my iPhone using Tapatalk
User avatar
Egregius
Posts: 2582
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: v2024.7
Location: Beitem, BE
Contact:

Re: Pass2PHP

Post by Egregius »

Yes, I'm running Domoticz stable 3.8153 without any issue.
Trigun
Posts: 390
Joined: Wednesday 30 November 2016 11:58
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.10717
Contact:

Re: Pass2PHP

Post by Trigun »

Great! Thnx


Sent from my iPhone using Tapatalk
simon_rb
Posts: 612
Joined: Wednesday 07 August 2013 19:09
Target OS: -
Domoticz version:
Location: UK
Contact:

Re: Pass2PHP

Post by simon_rb »

I have read through this thread and there are various ways to set this up. On another topic, Egregius has recommended I use his pass2php and read through this and it looks excellent - really quick. Has anyone on here set this up from scratch recently? Wondered what the up to date method of setting this up..
User avatar
Egregius
Posts: 2582
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: v2024.7
Location: Beitem, BE
Contact:

Re: Pass2PHP

Post by Egregius »

Hi Simon,

The code at github should be pretty recent, will update it in a few minutes with my latest code and scripts.
The installation in the wiki should be a good starting point, not very detailed...
https://github.com/Egregius/LUA-Pass2PH ... stallation
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests