Pass2PHP
Moderator: leecollings
- 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
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?
- Egregius
- Posts: 2582
- Joined: Thursday 09 April 2015 12:19
- Target OS: Linux
- Domoticz version: v2024.7
- Location: Beitem, BE
- Contact:
Re: Pass2PHP
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.
I guess it's the same but keep in mind that php7 is a lot faster.
- Egregius
- Posts: 2582
- Joined: Thursday 09 April 2015 12:19
- Target OS: Linux
- Domoticz version: v2024.7
- Location: Beitem, BE
- Contact:
Re: Pass2PHP
Updated my sw(itch) function so it supports arrays:
usage:
Very handy for repeated stuf
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¶m=switchlight&idx='.apcu_fetch('i'.$name).'&switchcmd='.$action);
else{apcu_store('s'.$name,$action);apcu_store('t'.$name,time);}
usleep(50000);
}
}
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'
-
- Posts: 483
- Joined: Tuesday 12 August 2014 5:37
- Target OS: Raspberry Pi / ODroid
- Domoticz version: V3_8394
- Location: Rumbeke,Belgium
- Contact:
Re: Pass2PHP
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)
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)
- Egregius
- Posts: 2582
- Joined: Thursday 09 April 2015 12:19
- Target OS: Linux
- Domoticz version: v2024.7
- Location: Beitem, BE
- Contact:
Re: Pass2PHP
Are you sure it's php5-mysqlnd you need? Isn't it just php5-mysql?
And why not go for php7.0?
And why not go for php7.0?
-
- Posts: 483
- Joined: Tuesday 12 August 2014 5:37
- Target OS: Raspberry Pi / ODroid
- Domoticz version: V3_8394
- Location: Rumbeke,Belgium
- Contact:
Re: Pass2PHP
you know the command for php7 ? :p
-
- Posts: 483
- Joined: Tuesday 12 August 2014 5:37
- Target OS: Raspberry Pi / ODroid
- Domoticz version: V3_8394
- Location: Rumbeke,Belgium
- Contact:
Re: Pass2PHP
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:~ $
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:~ $
- Egregius
- Posts: 2582
- Joined: Thursday 09 April 2015 12:19
- Target OS: Linux
- Domoticz version: v2024.7
- Location: Beitem, BE
- Contact:
Re: Pass2PHP
There's something wrong with your dpkg.
Translate the error and google...
Translate the error and google...
- Egregius
- Posts: 2582
- Joined: Thursday 09 April 2015 12:19
- Target OS: Linux
- Domoticz version: v2024.7
- Location: Beitem, BE
- Contact:
Re: Pass2PHP
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:
With that file you can easily use the apcu cache from another system.
For example, check if the nas is on:
Or set a variable:
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']);
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
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
-
- Posts: 52
- Joined: Friday 23 December 2016 9:41
- Target OS: Linux
- Domoticz version:
- Contact:
Re: Pass2PHP
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?
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?
- Egregius
- Posts: 2582
- Joined: Thursday 09 April 2015 12:19
- Target OS: Linux
- Domoticz version: v2024.7
- Location: Beitem, BE
- Contact:
Re: Pass2PHP
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:
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).
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
}
-
- Posts: 11
- Joined: Saturday 24 December 2016 10:34
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Pass2PHP
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.
-
- Posts: 11
- Joined: Saturday 24 December 2016 10:34
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Pass2PHP
Here are my scripts: https://github.com/richarddeweerd/domot ... master/php
Logfile on and off switching of the lap "Overloop" from domoticz:
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)
- Egregius
- Posts: 2582
- Joined: Thursday 09 April 2015 12:19
- Target OS: Linux
- Domoticz version: v2024.7
- Location: Beitem, BE
- Contact:
Re: Pass2PHP
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
Either check your node parameters or groups or use the workaround from http://www.domoticz.com/forum/viewtopic ... 92#p140236
-
- Posts: 390
- Joined: Wednesday 30 November 2016 11:58
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 4.10717
- Contact:
Re: Pass2PHP
Hi egregius, is the script also working on the New version of domoticz?
Sent from my iPhone using Tapatalk
Sent from my iPhone using Tapatalk
- Egregius
- Posts: 2582
- Joined: Thursday 09 April 2015 12:19
- Target OS: Linux
- Domoticz version: v2024.7
- Location: Beitem, BE
- Contact:
Re: Pass2PHP
Yes, I'm running Domoticz stable 3.8153 without any issue.
-
- Posts: 390
- Joined: Wednesday 30 November 2016 11:58
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 4.10717
- Contact:
Re: Pass2PHP
Great! Thnx
Sent from my iPhone using Tapatalk
Sent from my iPhone using Tapatalk
-
- Posts: 612
- Joined: Wednesday 07 August 2013 19:09
- Target OS: -
- Domoticz version:
- Location: UK
- Contact:
Re: Pass2PHP
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..
- Egregius
- Posts: 2582
- Joined: Thursday 09 April 2015 12:19
- Target OS: Linux
- Domoticz version: v2024.7
- Location: Beitem, BE
- Contact:
Re: Pass2PHP
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
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
Who is online
Users browsing this forum: No registered users and 1 guest