Pass2PHP
Moderator: leecollings
- Egregius
- Posts: 2582
- Joined: Thursday 09 April 2015 12:19
- Target OS: Linux
- Domoticz version: v2024.7
- Location: Beitem, BE
- Contact:
Re: Pass2PHP
Yes, maybe just the previous model.
-
- Posts: 50
- Joined: Thursday 04 January 2018 8:43
- Target OS: Linux
- Domoticz version: 3.66
- Location: Roeselare, Wvl, BE
- Contact:
Re: Pass2PHP
The old xiaomi works with the round sensor types. The new one does not i think. I am happy with my 6 xiaomi temperature sensors and the old gw. It was cheap
My response time is 80ms on a thin cliënt with atom cpu and 2gig ram.
My response time is 80ms on a thin cliënt with atom cpu and 2gig ram.
-
- Posts: 483
- Joined: Tuesday 12 August 2014 5:37
- Target OS: Raspberry Pi / ODroid
- Domoticz version: V3_8394
- Location: Rumbeke,Belgium
- Contact:
Re: Pass2PHP
@Egrerius: is your 'telegram' function still working?
the 'alert' function is not working for someway for me. i need to check why.
But i used the 'old' telegram function from your previous pass2php (what worked before for me) and now its not working anymore.
when i use this directly in a webbrowers: https://api.telegram.org/bot'.$telegram ... ='.$silent
with the needed data, i receive a telegram message.
u got any idea?
thank you
the 'alert' function is not working for someway for me. i need to check why.
But i used the 'old' telegram function from your previous pass2php (what worked before for me) and now its not working anymore.
Code: Select all
function telegram2($msg,$silent=true,$to=1){
for($x=1;$x<=100;$x++){
$result=json_decode(file_get_contents('https://api.telegram.org/bot'.$telegrambot.'/sendMessage?chat_id='.$telegramchatid.'&text='.urlencode($msg).'&disable_notification='.$silent));
if(isset($result->ok))
if($result->ok===true){lg('telegram sent to 1: '.$msg);break;}
else lg('telegram sent failed');sleep($x*3);
global $actions;$actions=$actions+1;
}
if($to>=2)
for($x=1;$x<=100;$x++){
$result=json_decode(file_get_contents('https://api.telegram.org/bot'.$telegrambot.'/sendMessage?chat_id='.$telegramchatid2.'&text='.urlencode($msg).'&disable_notification='.$silent));
if(isset($result->ok))
if($result->ok===true){lg('telegram sent to 2: '.$msg);break;}
else lg('telegram sent failed');sleep($x*3);
global $actions;$actions=$actions+1;
}
elseif($to==3){ios($msg);global $actions;$actions=$actions+1;}
}
when i use this directly in a webbrowers: https://api.telegram.org/bot'.$telegram ... ='.$silent
with the needed data, i receive a telegram message.
u got any idea?
thank you
- Egregius
- Posts: 2582
- Joined: Thursday 09 April 2015 12:19
- Target OS: Linux
- Domoticz version: v2024.7
- Location: Beitem, BE
- Contact:
Re: Pass2PHP
I pipe my telegram messages to a shell script so it doesn't hold up the rest of the script.
The alert function is to send a telegram, but only when a ttl is passed. So you can execute the alert function every minute, but the message will only be send once in the ttl. This uses a seperate sql table.
Code: Select all
function telegram($msg,$silent=true,$to=1)
{
if ($silent==true) $silent='true';
else $silent='false';
shell_exec('/var/www/html/secure/telegram.sh "'.$msg.'" "'.$silent.'" "'.$to.'" > /dev/null 2>/dev/null &');
lg('Telegram sent: '.$msg);
}
Code: Select all
CREATE TABLE `alerts` (
`n` varchar(50) NOT NULL,
`t` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
ALTER TABLE `alerts`
ADD PRIMARY KEY (`n`);
-
- 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 Egrerius,
well if i use the "alert" function, it is writing data in the mysql data base, so that part works.
but the telegram itself is not working.
Even when i execute the telegram.sh itself with data, i don't receive a telegram message.
give me this response:
so executed i think?
i think its something in my telegram.php
something with the curl
i found this on the internet to check if the curl is working:
if should work, it should make the file google_homepage.txt
but it does not make it.
also when i use this code:
it says disabled
then i looked up in /etc/php/7.3/php.ini and there was a ; before: extension=curl so i removed that one and restarted apache2 server
when i check again with the code
it still says Disabled
well if i use the "alert" function, it is writing data in the mysql data base, so that part works.
but the telegram itself is not working.
Even when i execute the telegram.sh itself with data, i don't receive a telegram message.
Code: Select all
./telegram.sh testmetalles false 1 > /dev/null 2>/dev/null &
Code: Select all
[1] 31353
i think its something in my telegram.php
something with the curl
i found this on the internet to check if the curl is working:
Code: Select all
<?php
$ch = curl_init("http://www.google.com/");
$fp = fopen("google_homepage.txt", "w");
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_exec($ch);
curl_close($ch);
fclose($fp);
?>
but it does not make it.
also when i use this code:
Code: Select all
<?php
echo 'Curl: ', function_exists('curl_version') ? 'Enabled' : 'Disabled';
then i looked up in /etc/php/7.3/php.ini and there was a ; before: extension=curl so i removed that one and restarted apache2 server
when i check again with the code
Code: Select all
<?php
echo 'Curl: ', function_exists('curl_version') ? 'Enabled' : 'Disabled';
-
- Posts: 483
- Joined: Tuesday 12 August 2014 5:37
- Target OS: Raspberry Pi / ODroid
- Domoticz version: V3_8394
- Location: Rumbeke,Belgium
- Contact:
Re: Pass2PHP
if i want to install curl, i get this:
stijn@debian:~$ sudo apt-get install php-curl
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
php7.3-curl
The following NEW packages will be installed:
php-curl php7.3-curl
0 upgraded, 2 newly installed, 0 to remove and 1 not upgraded.
Need to get 36.7 kB of archives.
After this operation, 147 kB of additional disk space will be used.
Do you want to continue? [Y/n] y
Err:1 http://security.debian.org/debian-security buster/updates/main amd64 php7.3-curl amd64 7.3.14-1~deb10u1
404 Not Found [IP: 2a04:4e42:9::204 80]
Get:2 http://ftp.be.debian.org/debian buster/main amd64 php-curl all 2:7.3+69 [5,992 B]
Fetched 5,992 B in 0s (14.3 kB/s)
E: Failed to fetch http://security.debian.org/debian-secur ... _amd64.deb 404 Not Found [IP: 2a04:4e42:9::204 80]
E: Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?
stijn@debian:~$
stijn@debian:~$ sudo apt-get install php-curl
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
php7.3-curl
The following NEW packages will be installed:
php-curl php7.3-curl
0 upgraded, 2 newly installed, 0 to remove and 1 not upgraded.
Need to get 36.7 kB of archives.
After this operation, 147 kB of additional disk space will be used.
Do you want to continue? [Y/n] y
Err:1 http://security.debian.org/debian-security buster/updates/main amd64 php7.3-curl amd64 7.3.14-1~deb10u1
404 Not Found [IP: 2a04:4e42:9::204 80]
Get:2 http://ftp.be.debian.org/debian buster/main amd64 php-curl all 2:7.3+69 [5,992 B]
Fetched 5,992 B in 0s (14.3 kB/s)
E: Failed to fetch http://security.debian.org/debian-secur ... _amd64.deb 404 Not Found [IP: 2a04:4e42:9::204 80]
E: Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?
stijn@debian:~$
-
- Posts: 483
- Joined: Tuesday 12 August 2014 5:37
- Target OS: Raspberry Pi / ODroid
- Domoticz version: V3_8394
- Location: Rumbeke,Belgium
- Contact:
Re: Pass2PHP
ok, its working lol
i did like what i said: sudo apt-get update
and after that i did: sudo apt-get install php-curl
then restart apache2server: sudo service apache2 restart
and now the code:
shows enabled
and telegram is sending messages, thanks anyway
i did like what i said: sudo apt-get update
and after that i did: sudo apt-get install php-curl
then restart apache2server: sudo service apache2 restart
and now the code:
Code: Select all
<?php
echo 'Curl: ', function_exists('curl_version') ? 'Enabled' : 'Disabled';
and telegram is sending messages, thanks anyway
-
- Posts: 483
- Joined: Tuesday 12 August 2014 5:37
- Target OS: Raspberry Pi / ODroid
- Domoticz version: V3_8394
- Location: Rumbeke,Belgium
- Contact:
Re: Pass2PHP
So the alert function only send a telegram message if message was more than 5minutes? (300seconds)
how can i change it so it sends a telegram message to user 1 and user 2?
its normal due the alert function, it only sends a message to user1
if i should use this: in the alert function and then a loop to send it to both users?
how can i change it so it sends a telegram message to user 1 and user 2?
Code: Select all
<?php
if ($status=='On') {
$msg='Rook gedecteerd in badkamer!';
alert($device, $msg, 300, false, 1, false);
alert($device, $msg, 300, false, 2, false);
if i should use this:
Code: Select all
if(is_array($to))
- Egregius
- Posts: 2582
- Joined: Thursday 09 April 2015 12:19
- Target OS: Linux
- Domoticz version: v2024.7
- Location: Beitem, BE
- Contact:
Re: Pass2PHP
alert($device, $msg, 300, false, 2, false);
should do it normally. The 5th paramater is the send to one.
should do it normally. The 5th paramater is the send to one.
-
- Posts: 483
- Joined: Tuesday 12 August 2014 5:37
- Target OS: Raspberry Pi / ODroid
- Domoticz version: V3_8394
- Location: Rumbeke,Belgium
- Contact:
Re: Pass2PHP
hmm, i think i'm reading it wrong then
i thought this code:
i thought it means:
when the last timestamp of the 'alert' update is less then $tt, it will not send again.
But if i send it to user1 then the alert timestamp is update and if i send it directly again to user2; then it wont send i think because last timestamp update is less then $ttl ?
i thought this code:
Code: Select all
if ($last < TIME-$ttl) {
if ($ios) {
shell_exec('./ios.sh "'.$msg.'" >/dev/null 2>/dev/null &');
}
$time=TIME;
$db->query("INSERT INTO alerts (n,t) VALUES ('$name','$time') ON DUPLICATE KEY UPDATE t='$time';");
telegram($msg, $silent, $to);
lg('alert='.$last);
}
when the last timestamp of the 'alert' update is less then $tt, it will not send again.
But if i send it to user1 then the alert timestamp is update and if i send it directly again to user2; then it wont send i think because last timestamp update is less then $ttl ?
- Egregius
- Posts: 2582
- Joined: Thursday 09 April 2015 12:19
- Target OS: Linux
- Domoticz version: v2024.7
- Location: Beitem, BE
- Contact:
Re: Pass2PHP
You don't have to send it twice. If you use alert('name', 'message', 3600, false, 2) the telegram will be send to both id's in one call.
- 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: Pass2PHP
Hi @Egregius.
To speed up Pass2PHP (and I know you already did some extensive research in the past).
Was PHP preloading ever considered ??
https://www.php.net/manual/en/opcache.preloading.php
I've also done experiments with NGINX + Cache but enabling that gave me some mixed results.
_cron5.php did not appear anymore in my Domoticz log.. after disabling the cache it started working again.
Ofcourse by default Opcache is enabled.
But I was wondering if we could squeeze some more juice out of the system. tnx
Sándor
To speed up Pass2PHP (and I know you already did some extensive research in the past).
Was PHP preloading ever considered ??
https://www.php.net/manual/en/opcache.preloading.php
I've also done experiments with NGINX + Cache but enabling that gave me some mixed results.
_cron5.php did not appear anymore in my Domoticz log.. after disabling the cache it started working again.
Ofcourse by default Opcache is enabled.
But I was wondering if we could squeeze some more juice out of the system. tnx
Sándor
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.
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.
- Egregius
- Posts: 2582
- Joined: Thursday 09 April 2015 12:19
- Target OS: Linux
- Domoticz version: v2024.7
- Location: Beitem, BE
- Contact:
Re: Pass2PHP
Don't think preloading will make a big difference. Only your first 193 misses will benefit from it. It's not that you restart php-fpm every hour or so.
Don't know if I ever tried nginx for this. Because I'm used to use Apache2 on all other servers I manage I also went for that. I already know the virtual hosts files quite good. Doing it all in nginx would require to learn that all again.
And then for what? To squeze 1 msec out of it? Don't think the webserver will make a lot of difference in this usecase. Maybe if you have a gigantic household with thousands of users...
Don't know if I ever tried nginx for this. Because I'm used to use Apache2 on all other servers I manage I also went for that. I already know the virtual hosts files quite good. Doing it all in nginx would require to learn that all again.
And then for what? To squeze 1 msec out of it? Don't think the webserver will make a lot of difference in this usecase. Maybe if you have a gigantic household with thousands of users...
- Egregius
- Posts: 2582
- Joined: Thursday 09 April 2015 12:19
- Target OS: Linux
- Domoticz version: v2024.7
- Location: Beitem, BE
- Contact:
Re: Pass2PHP
Maybe I need to reconsider my last post...
Busy moving from Proxmox VM to LXC Containe, from Apache to nginx and from php7.4-fpm to php8.0-fpm
Will cost some work to finish it all...
First things I saw on my floorplan: the XHR requests take now 5msec and before 7-10msec.
From lua to php seems to be a little slower. I'm now at 26msec, but a lot is still at default values. Still room for improvement I guess.
Busy moving from Proxmox VM to LXC Containe, from Apache to nginx and from php7.4-fpm to php8.0-fpm
Will cost some work to finish it all...
First things I saw on my floorplan: the XHR requests take now 5msec and before 7-10msec.
From lua to php seems to be a little slower. I'm now at 26msec, but a lot is still at default values. Still room for improvement I guess.
- Egregius
- Posts: 2582
- Joined: Thursday 09 April 2015 12:19
- Target OS: Linux
- Domoticz version: v2024.7
- Location: Beitem, BE
- Contact:
Re: Pass2PHP
Starts to look good
Used php7.4-fpm, 8.0 is still release candidate and there's no APCu support yet.
So, now running in LXC container with nginx, mariadb with sql file from tmpfs and domoticz on tmpfs.
Code: Select all
2020-11-14 09:51:30.161 (ZWAVE) Light/Switch (pirkeuken)
2020-11-14 09:51:30.175 OpenZWave: Domoticz has send a Switch command! NodeID: 4 (0x04)
So, now running in LXC container with nginx, mariadb with sql file from tmpfs and domoticz on tmpfs.
- Egregius
- Posts: 2582
- Joined: Thursday 09 April 2015 12:19
- Target OS: Linux
- Domoticz version: v2024.7
- Location: Beitem, BE
- Contact:
Re: Pass2PHP
Is there by any chance someone using PHP to connect to the Ring Doorbell API?
I have a Python script running but would rather have it in PHP
I have a Python script running but would rather have it in PHP
- Egregius
- Posts: 2582
- Joined: Thursday 09 April 2015 12:19
- Target OS: Linux
- Domoticz version: v2024.7
- Location: Beitem, BE
- Contact:
Re: Pass2PHP
Made some more progress on the response times
Now at 10 msec
Changes:
Nginx instead of Apache2
php8.0-fpm instead of php7.4-fpm
wget instead of curl in the lua script (biggest change).
cron.sh now simply gets cron.php. Cron120, 180 etc is handled in the php file.
Code: Select all
2020-11-19 15:33:19.983 (Xiaomi) Light/Switch (deurgarage)
2020-11-19 15:33:19.993 (STORE) => deurgarage => Open (Pass2PHP)
2020-11-19 15:33:19.993 (SWITCH) =>garageled=>On (functions.php:994)
2020-11-19 15:33:19.993 Status: User: Admin initiated a switch command (2062/garageled/On)
2020-11-19 15:33:19.993 OpenZWave: Domoticz has send a Switch command! NodeID: 102 (0x66)
Changes:
Nginx instead of Apache2
php8.0-fpm instead of php7.4-fpm
wget instead of curl in the lua script (biggest change).
cron.sh now simply gets cron.php. Cron120, 180 etc is handled in the php file.
-
- Posts: 483
- Joined: Tuesday 12 August 2014 5:37
- Target OS: Raspberry Pi / ODroid
- Domoticz version: V3_8394
- Location: Rumbeke,Belgium
- Contact:
Re: Pass2PHP
nice work guys
about the ring doorbell, i also have one, but still not managed to get it working in php
Something else, you dont had problems with Zwave before (i made a topic some months ago about it and you responded to it you did not had the same issues like me)
But i noticed a lot of other people have the same issue like me.
Domoticz telling a zwave device is switched off, but zwave control panel says its switched on and the real condition is also on, so something wrong with domoticz received the real value.
Just wondering what kind of Domoticz you have and what version of Openzwave you have 1.4 or 1.6?
I noticed a lot of the people who are having the same zwave problems have all version 1.6
thank you in adavance.
about the ring doorbell, i also have one, but still not managed to get it working in php
Something else, you dont had problems with Zwave before (i made a topic some months ago about it and you responded to it you did not had the same issues like me)
But i noticed a lot of other people have the same issue like me.
Domoticz telling a zwave device is switched off, but zwave control panel says its switched on and the real condition is also on, so something wrong with domoticz received the real value.
Just wondering what kind of Domoticz you have and what version of Openzwave you have 1.4 or 1.6?
I noticed a lot of the people who are having the same zwave problems have all version 1.6
thank you in adavance.
- Egregius
- Posts: 2582
- Joined: Thursday 09 April 2015 12:19
- Target OS: Linux
- Domoticz version: v2024.7
- Location: Beitem, BE
- Contact:
Re: Pass2PHP
My Ring doorbell is working with IFTTT but that sucks, sometimes the alerts arrive hours later, even with a premium IFTTT account. I've put a Python script to poll the Ring alerts every 3 seconds. That's running on a server with another ip and another ring account because I got locked for some reason. It's running good now, but still like to handle it in PHP just because I know that better.
The only problem I have at the moment with Zwave is for the Qubino ZMNHBA2 Flush 2 Relays that don't report their correct status. Everything else works as it should. I'm running Domoticz 2020.2 Build 12485 with openzwave 1.6-1392-gb0afd4c6. The Qubino's also have the right status in the OZW control panel, but not in Domoticz. I'm using a kind of refresh script to have the right status but it's not ideal.
Oh, wait. I disabled that again because it did to much on the zwave network and caused delays.
It was something like this: if ($d['pirkeuken']['s']=='On') RefreshZwave(4);
The only problem I have at the moment with Zwave is for the Qubino ZMNHBA2 Flush 2 Relays that don't report their correct status. Everything else works as it should. I'm running Domoticz 2020.2 Build 12485 with openzwave 1.6-1392-gb0afd4c6. The Qubino's also have the right status in the OZW control panel, but not in Domoticz. I'm using a kind of refresh script to have the right status but it's not ideal.
Oh, wait. I disabled that again because it did to much on the zwave network and caused delays.
It was something like this: if ($d['pirkeuken']['s']=='On') RefreshZwave(4);
- Egregius
- Posts: 2582
- Joined: Thursday 09 April 2015 12:19
- Target OS: Linux
- Domoticz version: v2024.7
- Location: Beitem, BE
- Contact:
Re: Pass2PHP
I played with that yesterday. Saw to much strange things that I stopped it. It was like it wanted to parse all included files at once resulting in a lot of errors for constants and functions already assigned.sincze wrote: ↑Friday 13 November 2020 8:53 Was PHP preloading ever considered ??
https://www.php.net/manual/en/opcache.preloading.php
It's only beneficial for the first execution of a file. Because functions.php is included everywhere and it's the biggest file that one is instantly cached. So I still believe it's not a big advantage.
Who is online
Users browsing this forum: No registered users and 0 guests