Pass2PHP

Moderator: leecollings

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 »

ropske wrote:
Trigun wrote: Tuesday 19 May 2020 12:46
ropske wrote:Sorry i'm here again :(

i want to copy the file: script_device_pass2php.lua to the scripts/lua directory in domoticz, but it fails:

2020-05-19 12_41_37-Window.jpg

anyone knows why?

thank you!

Running domoticz on a VM on proxmox
Yes, there is a permission issue. Just set your permissions to 777 -R on the scripts folder. The “-R” will help you to set the permissions recursively. Hope this helps


Sent from my iPhone using Tapatalk
Correct mate, its working.
I'm just gonna write down everything i've done :D
Just in case i need to reinstall it again lol

Is there any reason why the scripts folder has not the correct rights? or has it allways been like this?

@Egrerius, you backup your complete VM to a nas then?
That’s exactly how I did it as well. And by writing it down you understand everything much better. At least for me it was the case.

You can take a snapshot of your vm and possibly send it to your NAS. Personally I have a cron job running that copies all necessary info to my Nas via Rsync. And before I install something new I make a snapshot.

Glad to know you got it all working!


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

Re: Pass2PHP

Post by Egregius »

ropske wrote: Tuesday 19 May 2020 13:14 Is there any reason why the scripts folder has not the correct rights? or has it allways been like this?

@Egrerius, you backup your complete VM to a nas then?
Depends on the user that owns the folder and the user you use to connect to SFTP.

I have 2 backups. My Synology NAS is mostly sleeping, unless we need it for something. In the task scheduler of the Synology I've set a backup script that is executed directly after startup. The script backups lots of stuff from different webservers, domoticz, some raspberry's etc.

Here's the relevant part of the script:

Code: Select all

#!/bin/sh
NOW=$(date +"%Y-%m-%d")
BPATH=/volume1/homes/guy/backup
RUNLOG=/volume1/homes/guy/log/$NOW.txt
EXCLUDED=/volume1/homes/guy/backup/excludedfiles.txt

NAME="domoticz"
echo  ------------------- START $NAME -- $(date) | tee -a $RUNLOG
SOURCE="[email protected]:/domoticz/"
DESTINATION="$BPATH/$NAME/$NOW"
mkdir -p "$DESTINATION"
rsync -aP --exclude-from $EXCLUDED -e "ssh -i /root/.ssh/home" --stats --delete-after --links --ignore-errors --link-dest="../__prev/" "$SOURCE" "$DESTINATION" | tee -a $RUNLOG
rm -f "$BPATH/$NAME/__prev"
ln -s "$BPATH/$NAME/$NOW" "$BPATH/$NAME/__prev"
echo  ------------------- END  $NAME -- $(date) | tee -a $RUNLOG

NAME="apache"
echo  ------------------- START $NAME -- $(date) | tee -a $RUNLOG
SOURCE="[email protected]:/var/www/"
DESTINATION="$BPATH/$NAME/$NOW"
LAST=$(ssh [email protected] -i /root/.ssh/home "find /var/www/ -type f ! -name '*.cache' -printf '%T@\n' | sort -n | tail -1 | cut -f1- -d\" \"")
PREV=$(cat "$BPATH/timestamp_$NAME.txt")
echo $LAST>"$BPATH/timestamp_$NAME.txt"
if [ "$LAST" != "$PREV" ]
then
	mkdir -p "$DESTINATION"
	rsync -aP --exclude-from $EXCLUDED -e "ssh -i /root/.ssh/home" --stats --delete-after --links --ignore-errors --link-dest="../__prev/" "$SOURCE" "$DESTINATION" | tee -a $RUNLOG
	rm -f "$BPATH/$NAME/__prev"
	ln -s "$BPATH/$NAME/$NOW" "$BPATH/$NAME/__prev"
else
	echo Nothing to do | tee -a $RUNLOG
fi
echo  ------------------- END  $NAME -- $(date) | tee -a $RUNLOG

exit 0
First part "domoticz" is executed every time and copies the whole domoticz folder. The second part is only executed if I have changed a file in my www folder. Both sections make use of the --link-dest option of rsync to have a versioned backup.
With this I have a file backup with a version for every time the nas starts.

Besides that the nas is scheduled to start every Friday night. Several minutes later I have my backup schedule in Proxmox to backup all VM's.

Might sound overkill but I'm rather safe than sorry. 100% up-time is crucial here because truly everything is handled by Domoticz. If domoticz is down I can't open the garage door, don't have music or tv, can't control rollers, heating, cooling. It's a real nightmare when it's down. Fortunately that has not happened often.
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 was wondering why my cron.sh was not working / running (i added it in crontab)

then i executed cron.sh
and this is the result:

stijn@debian:/var/www/html/secure$ sudo sh cron.sh
cron.sh: 15: [: unexpected operator
cron.sh: 62: [: unexpected operator
cron.sh: 68: [: unexpected operator

this is my crontab:

Code: Select all

#!/bin/bash

: '
crontab -e
# m h  dom mon dow   command
* * * * * /var/www/html/secure/cron.sh >/dev/null 2>&1
'

DOMOTICZ=`curl -s --connect-timeout 2 --max-time 5 "http://127.0.0.1:8080/json.htm?type=devices&rid=1"`
STATUS=`echo $DOMOTICZ | jq -r '.status'`
if [ "$STATUS" == "OK" ] ; then
    NOW=$(date +"%Y-%m-%d %H:%M:%S")
    MINUTE=$(date +"%M")
    CRON=""
    if [ $(($MINUTE%2)) -eq 0 ] ; then
        CRON="$CRON&cron120"
    fi
    if [ $(($MINUTE%3)) -eq 0 ] ; then
        CRON="$CRON&cron180"
    fi
    if [ $(($MINUTE%4)) -eq 0 ] ; then
        CRON="$CRON&cron240"
    fi
    if [ $(($MINUTE%5)) -eq 0 ] ; then
        CRON="$CRON&cron300"
    fi
    if [ $MINUTE -eq 0 ] ; then
        CRON="$CRON&cron3600"
    fi
	#0
	curl -s --connect-timeout 2 --max-time 30 "http://127.0.0.1/secure/cron.php?cron10&verwarming&rolluiken&cron60$CRON" >/dev/null 2>&1 &
	sleep 8.859
	#10
	curl -s --connect-timeout 2 --max-time 30 "http://127.0.0.1/secure/cron.php?cron10&verwarming&rolluiken" >/dev/null 2>&1 &
	sleep 9.998
	#20
	curl -s --connect-timeout 2 --max-time 30 "http://127.0.0.1/secure/cron.php?cron10&verwarming&rolluiken" >/dev/null 2>&1 &
	sleep 9.998
	#30
	curl -s --connect-timeout 2 --max-time 30 "http://127.0.0.1/secure/cron.php?cron10&verwarming&rolluiken" >/dev/null 2>&1 &
	sleep 9.998
	#40
	curl -s --connect-timeout 2 --max-time 30 "http://127.0.0.1/secure/cron.php?cron10&verwarming&rolluiken" >/dev/null 2>&1 &
	sleep 9.998
	#50
	curl -s --connect-timeout 2 --max-time 30 "http://127.0.0.1/secure/cron.php?cron10&verwarming&rolluiken"
	if [ $? -gt 0 ] ; then
		service apache2 restart
	fi
else
	sleep 20
	DOMOTICZ=`curl -s --connect-timeout 2 --max-time 5 "http://127.0.0.1:8080/json.htm?type=devices&rid=1"`
	STATUS2=`echo $DOMOTICZ | jq -r '.status'`
	if [ "$STATUS2" == "OK" ] ; then
		exit
	else
		sleep 20
		DOMOTICZ=`curl -s --connect-timeout 2 --max-time 5 "http://127.0.0.1:8080/json.htm?type=devices&rid=1"`
		STATUS3=`echo $DOMOTICZ | jq -r '.status'`
		if [ "$STATUS3" == "OK" ] ; then
			exit
		else
			shutdown -r now
		fi
	fi
fi
User avatar
Egregius
Posts: 2592
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: v2024.7
Location: Beitem, BE
Contact:

Re: Pass2PHP

Post by Egregius »

Did you install jq?
Is that an exact copy of my cron.sh?
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 »

jq is installed

Code: Select all

#!/bin/bash
DOMOTICZ=`curl -s --connect-timeout 2 --max-time 5 "http://127.0.0.1:8080/json.htm?type=devices&rid=1"`
STATUS=`echo $DOMOTICZ | jq -r '.status'`
if [ "$STATUS" == "OK" ] ; then
    NOW=$(date +"%Y-%m-%d %H:%M:%S")
    MINUTE=$(date +"%M")
    CRON=""
    if [ $(($MINUTE%2)) -eq 0 ] ; then
        CRON="$CRON&cron120"
    fi
    if [ $(($MINUTE%3)) -eq 0 ] ; then
        CRON="$CRON&cron180"
    fi
    if [ $(($MINUTE%4)) -eq 0 ] ; then
        CRON="$CRON&cron240"
    fi
    if [ $(($MINUTE%5)) -eq 0 ] ; then
        CRON="$CRON&cron300"
    fi
    if [ $MINUTE -eq 0 ] ; then
        CRON="$CRON&cron3600"
    fi
    DEBUG=''
    #DEBUG='XDEBUG_PROFILE'
	echo $NOW   $MINUTE $CRON >> /run/cronlog
	echo OK
	#0
	curl -s --connect-timeout 2 --max-time 30 "http://127.0.0.1/secure/cron.php?cron60&rolluiken&cron10$CRON&$DEBUG" >/dev/null 2>&1 &
	sleep 8.859
	#10
	curl -s --connect-timeout 2 --max-time 30 "http://127.0.0.1/secure/cron.php?cron10&rolluiken&$DEBUG" >/dev/null 2>&1 &
	sleep 9.998
	#20
	curl -s --connect-timeout 2 --max-time 30 "http://127.0.0.1/secure/cron.php?cron10&rolluiken&$DEBUG" >/dev/null 2>&1 &
	sleep 9.998
	#30
	curl -s --connect-timeout 2 --max-time 30 "http://127.0.0.1/secure/cron.php?cron10&rolluiken&$DEBUG" >/dev/null 2>&1 &
	sleep 9.998
	#40
	curl -s --connect-timeout 2 --max-time 30 "http://127.0.0.1/secure/cron.php?cron10&rolluiken&$DEBUG" >/dev/null 2>&1 &
	sleep 9.998
	#50
	curl -s --connect-timeout 2 --max-time 30 "http://127.0.0.1/secure/cron.php?cron10&rolluiken&$DEBUG"
	if [ $? -gt 0 ] ; then
		/usr/sbin/service apache2 restart
	fi
else
	sleep 20
	DOMOTICZ=`curl -s --connect-timeout 2 --max-time 5 "http://127.0.0.1:8080/json.htm?type=devices&rid=1"`
	STATUS2=`echo $DOMOTICZ | jq -r '.status'`
	if [ "$STATUS2" == "OK" ] ; then
		exit
	else
		sleep 20
		DOMOTICZ=`curl -s --connect-timeout 2 --max-time 5 "http://127.0.0.1:8080/json.htm?type=devices&rid=1"`
		STATUS3=`echo $DOMOTICZ | jq -r '.status'`
		if [ "$STATUS3" == "OK" ] ; then
			exit
		else
			/usr/sbin/service domoticz stop
			/usr/sbin/service domoticz start
			#shutdown -r now
		fi
	fi
fi

ps cax | grep httpd
if [ $? -eq 0 ] ; then
	/usr/sbin/service apache2 stop
	/usr/sbin/service apache2 start
fi
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 »

not an exact copy of yours. i included the "rolluiken" again
and deleted the last things

i also tried with your cron.sh, but same errors
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 »

this is the result:

stijn@debian:/var/www/html/secure$ sudo sh cron.sh
cron.sh: 15: [: OK: unexpected operator
cron.sh: 62: [: OK: unexpected operator
cron.sh: 68: [: OK: unexpected operator

so the OK comes from jq i guess (from reading the status of domoticz)
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 »

ok, i found the problem:

DEBUG=''
#DEBUG='XDEBUG_PROFILE'


when i delete this, everything is working fine
i dont know why in has/gives an error for this
kispalsz
Posts: 31
Joined: Friday 13 October 2017 19:56
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Pass2PHP

Post by kispalsz »

I tried to make it work based on the descriptions, Trigun 12-8-2019 TXT.
My system is Domoticz 2020.2 stable branch.
HW: Raspbery Pi 3+. with Raspbian Buster.
I Use Zwave hardware with AEON Gen5 Stick, and Zigbee hardware with DeConz stick.

When I copy the script_device_pass2php.lua file that contains the PIR switch to the Domoticz / scripts / lua folder, the PIR switch works for one switch, but then the system slows down completely. When I remove the script_device_pass2php.lua file it is in all OK.

This is script_device_pass2php.lua

Code: Select all

for d,s in pairs(devicechanged)
do
os.execute('curl -X POST -d "d='..d.."&s="..s..'" http://127.0.0.1/secure/pass2php.php &')
end
commandArray={}
Top command before copy script_device_pass2php.lua

Code: Select all

top - 21:25:58 up 21:54,  1 user,  load average: 0.38, 0.58, 0.76
Tasks: 121 total,   1 running, 120 sleeping,   0 stopped,   0 zombie
%Cpu(s):  5.3 us,  5.3 sy,  0.0 ni, 89.5 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
MiB Mem :    926.1 total,    106.6 free,    187.6 used,    631.8 buff/cache
MiB Swap:    100.0 total,     99.5 free,      0.5 used.    641.9 avail Mem

  PID USER      PR  NI    VIRT    RES    SHR S  %CPU  %MEM     TIME+ COMMAND
  650 root      20   0  349212  67328  19808 S  23.5   7.1  70:59.10 domoticz
11011 root      20   0   10328   3044   2512 R  11.8   0.3   0:00.04 top
    1 root      20   0   34836   8236   6432 S   0.0   0.9   1:06.73 systemd
    2 root      20   0       0      0      0 S   0.0   0.0   0:00.16 kthreadd
    3 root       0 -20       0      0      0 I   0.0   0.0   0:00.00 rcu_gp
    4 root       0 -20       0      0      0 I   0.0   0.0   0:00.00 rcu_par_gp
    8 root       0 -20       0      0      0 I   0.0   0.0   0:00.00 mm_percpu_wq
    9 root      20   0       0      0      0 S   0.0   0.0   0:06.58 ksoftirqd/0
   10 root      20   0       0      0      0 I   0.0   0.0   0:44.18 rcu_sched
   11 root      20   0       0      0      0 I   0.0   0.0   0:00.00 rcu_bh
   12 root      rt   0       0      0      0 S   0.0   0.0   0:00.58 migration/0
   13 root      20   0       0      0      0 S   0.0   0.0   0:00.00 cpuhp/0
   14 root      20   0       0      0      0 S   0.0   0.0   0:00.00 cpuhp/1
   15 root      rt   0       0      0      0 S   0.0   0.0   0:00.51 migration/1
   16 root      20   0       0      0      0 S   0.0   0.0   0:02.53 ksoftirqd/1
   19 root      20   0       0      0      0 S   0.0   0.0   0:00.00 cpuhp/2
   20 root      rt   0       0      0      0 S   0.0   0.0   0:00.49 migration/2

Top command after copy script_device_pass2php.lua

Code: Select all

top - 21:14:06 up 21:42,  1 user,  load average: 2.39, 1.46, 0.89
Tasks: 134 total,   1 running, 133 sleeping,   0 stopped,   0 zombie
%Cpu(s):  7.8 us,  6.3 sy,  0.0 ni, 55.6 id, 30.0 wa,  0.0 hi,  0.3 si,  0.0 st
MiB Mem :    926.1 total,    102.2 free,    194.0 used,    629.8 buff/cache
MiB Swap:    100.0 total,     99.5 free,      0.5 used.    635.6 avail Mem

  PID USER      PR  NI    VIRT    RES    SHR S  %CPU  %MEM     TIME+ COMMAND
  650 root      20   0  349212  67324  19808 S  19.9   7.1  70:18.35 domoticz
  330 pi        20   0  126484  35600  26404 S   4.0   3.8  35:22.09 deCONZ
 1732 root      20   0   20512   7684   6912 S   1.0   0.8   0:00.03 curl
 1758 root      20   0   20512   7544   6772 S   1.0   0.8   0:00.03 curl
 1768 root      20   0   20512   7608   6836 S   1.0   0.8   0:00.03 curl
  372 root      20   0    8336   3188   2480 S   0.7   0.3   5:31.85 deCONZ-WIFI2.sh
  373 root      20   0    7808   2596   2344 S   0.7   0.3   1:52.61 deCONZ-update2.
  626 mysql     20   0  728176  69148  16032 S   0.7   7.3   1:28.44 mysqld
 1525 root      20   0   10328   3084   2552 R   0.7   0.3   0:00.10 top
   16 root      20   0       0      0      0 S   0.3   0.0   0:02.52 ksoftirqd/1
   25 root      rt   0       0      0      0 S   0.3   0.0   0:00.47 migration/3
  383 root      20   0   27656   1356   1228 S   0.3   0.1   1:26.59 rngd
 1770 root      20   0   20512   7516   6744 S   0.3   0.8   0:00.01 curl
 1771 www-data  20   0  247036  11188   7584 S   0.3   1.2   0:00.01 php-fpm7.3
15496 www-data  20   0   50740   3924   2492 S   0.3   0.4   0:03.12 nginx
16215 root      20   0       0      0      0 I   0.3   0.0   0:00.55 kworker/u8:1-events_unbound
    1 root      20   0   34836   8236   6432 S   0.0   0.9   1:06.26 systemd
    2 root      20   0       0      0      0 S   0.0   0.0   0:00.16 kthreadd
    3 root       0 -20       0      0      0 I   0.0   0.0   0:00.00 rcu_gp
    4 root       0 -20       0      0      0 I   0.0   0.0   0:00.00 rcu_par_gp
Why does the load increase like this?


My fstab:

Code: Select all

root@domoticz:~# cat /etc/fstab
proc            /proc           proc    defaults          0       0
PARTUUID=738a4d67-01  /boot           vfat    defaults,noatime          0       2
PARTUUID=738a4d67-02  /               ext4    defaults,noatime,commit=1800  0       1

#/run, /var/run, /run/lock, /var/run/lock will be automatically created by default - tmpfs
tmpfs /tmp tmpfs defaults,noatime,nosuid,nodev,noexec,mode=0755,size=100M 0 0
tmpfs /var/tmp tmpfs defaults,noatime,nosuid,nodev,noexec,mode=0755,size=100M 0 0
tmpfs /var/log tmpfs defaults,noatime,nosuid,nodev,noexec,mode=0755 0 0
tmpfs /var/log/nginx tmpfs defaults,noatime,nosuid,nodev,noexec,mode=0755 0 0

#tmpfs /var/www/html tmpfs defaults,noatime,nosuid,nodev,noexec,mode=0755,size=50M 0 0
tmpfs /var/lib/upsd tmpfs defaults,noatime,nosuid,nodev,noexec,mode=0755,size=4K 0 0
# a swapfile is not a swap partition, no line here
#   use  dphys-swapfile swap[on|off]  for that

I use /var/www/html folder

Code: Select all

root@domoticz:~# ls -la /var/www /var/www/html /var/www/html/secure
/var/www:
total 16
drwxr-xr-x  3 root root 4096 Jun 27 21:22 .
drwxr-xr-x 12 root root 4096 Apr 14 19:14 ..
-rw-r--r--  1 root root  596 Jun 27 21:22 config.php
drwxr-xr-x  3 root root 4096 Jun 28 17:31 html

/var/www/html:
total 12
drwxr-xr-x 3 root root 4096 Jun 28 17:31 .
drwxr-xr-x 3 root root 4096 Jun 27 21:22 ..
lrwxrwxrwx 1 root root   21 Jun 28 17:30 phpmyadmin -> /usr/share/phpmyadmin
drwxr-xr-x 3 root root 4096 Jun 28 18:11 secure

/var/www/html/secure:
total 96
drwxr-xr-x 3 root root  4096 Jun 28 18:11 .
drwxr-xr-x 3 root root  4096 Jun 28 17:31 ..
-rwxrwxrwx 1 root root 25766 Jun 27 12:45 _cron60.php
-rwxrwxrwx 1 root root  2667 Jun 27 12:45 cron.php
-rwxrwxrwx 1 root root  3309 Jun 27 12:45 cron.sh
-rwxrwxrwx 1 root root  3215 Jun 28 17:33 _fetchdomoticz.php
-rwxrwxrwx 1 root root 40491 Jun 27 12:45 functions.php
drwxr-xr-x 2 root root  4096 Jun 28 21:09 pass2php
-rwxrwxrwx 1 root root  1223 Jun 27 12:45 pass2php.php


root@domoticz:~# cat /var/spool/cron/crontabs/root
# DO NOT EDIT THIS FILE - edit the master and reinstall.
# (/tmp/crontab.7zbnHk/crontab installed on Sat Jun 27 20:07:44 2020)
# (Cron version -- $Id: crontab.c,v 2.13 1994/01/17 03:20:37 vixie Exp $)
# Edit this file to introduce tasks to be run by cron.
#
# Each task to run has to be defined through a single line
# indicating with different fields when the task will be run
# and what command to run for the task
#
# To define the time you can provide concrete values for
# minute (m), hour (h), day of month (dom), month (mon),
# and day of week (dow) or use '*' in these fields (for 'any').
#
# Notice that tasks will be started based on the cron's system
# daemon's notion of time and timezones.
#
# Output of the crontab jobs (including errors) is sent through
# email to the user the crontab file belongs to (unless redirected).
#
# For example, you can run a backup of all your user accounts
# at 5 a.m every week with:
# 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/
#
# For more information see the manual pages of crontab(5) and cron(8)
#
# m h  dom mon dow   command
* * * * * /usr/bin/nice -n20 /var/www/html/secure/cron.sh >/dev/null 2>&1




root@domoticz:~# ls -la  /var/www/html/secure/pass2php/

/var/www/html/secure/pass2php/:
total 12
drwxr-xr-x 2 root root 4096 Jun 28 21:09 .
drwxr-xr-x 3 root root 4096 Jun 28 18:11 ..
-rw-r--r-- 1 root root 2240 Jun 28 21:09 E-H-Mozgas1-Sensor.php
I use ony one pass2php file for my PIR sensor E-H-Mozgas1-Sensor and for my Test wallswitch E-I-Kapcsolo-Bal

Code: Select all

root@domoticz:~# cat /var/www/html/secure/pass2php/E-H-Mozgas1-Sensor.php
<?php
/**
 * Pass2PHP
 * php version 7.3.3-1
 *
 * @category Home_Automation
 * @package  Pass2PHP
 * @author   Guy Verschuere <[email protected]>
 * @license  GNU GPLv3
 * @link     https://egregius.be
 **/
if ($d['E-H-Mozgas1-Sensor']['s']=='On') {
    sw('E-I-Kapcsolo-Bal', 'On');
}  root@domoticz:~#
What I couldn't install from the description:
php-mycrypt

I added _cron60 but
"and your _cron60 or _cron 120 files etc
make sure to add the $d=fetchdata(); function to the _cron files"
What is this?

I skip domoticz log things.

My config.php

Code: Select all

root@domoticz:~# cat /var/www/config.php
<?php
/**
 * Pass2PHP
 * php version 7.3.4-2
 *
 * Example config file
 * Can be placed in /var/www/config.php
 *
 * @category Home_Automation
 * @package  Pass2PHP
 * @author   Guy Verschuere <[email protected]>
 * @license  GNU GPLv3
 * @link     https://egregius.be
 **/
error_reporting(E_ALL);
ini_set("display_errors", "on");
date_default_timezone_set('Europe/Brussels');
if (!defined('TIME')) {
    define('TIME', $_SERVER['REQUEST_TIME']);
}
$log=false;
$page=basename($_SERVER['PHP_SELF']);

$dbname='domotica';
$dbuser='domotica';
$dbpass='domotica';
php version:

Code: Select all

$domoticzurl='http://127.0.0.1:8080';root@domoticz:~# php -v
PHP 7.3.14-1~deb10u1 (cli) (built: Feb 16 2020 15:07:23) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.14, Copyright (c) 1998-2018 Zend Technologies
    with Zend OPcache v7.3.14-1~deb10u1, Copyright (c) 1999-2018, by Zend Technologies
root@domoticz:~# php -m
[PHP Modules]
apc
apcu
calendar
Core
ctype
curl
date
dom
exif
fileinfo
filter
ftp
gd
gettext
hash
iconv
imap
json
libxml
mbstring
mysqli
mysqlnd
openssl
pcntl
pcre
PDO
pdo_mysql
Phar
posix
readline
Reflection
session
shmop
SimpleXML
sockets
sodium
SPL
standard
sysvmsg
sysvsem
sysvshm
tokenizer
wddx
xml
xmlreader
xmlrpc
xmlwriter
xsl
Zend OPcache
zlib

[Zend Modules]
Zend OPcache

root@domoticz:~#
php _fetchdomoticz.php output without loaded pass2php lua script:

Code: Select all

root@domoticz:/var/www/html/secure# time php _fetchdomoticz.php
9 E-K-Huto-Switch = On
 E-K-Huto-kWh Meter = 9.600 kWh
 E-K-Huto-Watt = 86.6
16 E-F-Bojler-Switch = On
 E-F-Bojler-kWh Meter = 27.370 kWh
 E-F-Bojler-Watt = 1435
23 E-F-HMV-Switch = Off
 E-F-HMV-kWh Meter = 0.000 kWh
 E-F-HMV-Watt = 0
30 E-H-Klima-Switch = Off
33 E-I-Munkaallomas-Switch = On
 E-I-Munkaallomas-kWh Meter = 4.810 kWh
 E-I-Munkaallomas-Watt = 70.9
 E-H-Klima-kWh Meter = 0.000 kWh
 E-H-Klima-Watt = 0
58 E-I-Kapcsolo-Bal = Off
59 E-I-Kapcsolo-Jobb = On
60 E-N-Iranyfeny-Switch = On
 E-N-Iranyfeny-kWh Meter = 0.120 kWh
 E-N-Iranyfeny-Watt = 0
65 E-N-Klima-Switch = Off
 E-N-Klima-kWh Meter = 0.000 kWh
 E-N-Klima-Watt = 0
73 E-K-Kapcsolo1-Jobb = On
74 E-K-Kapcsolo1-Bal = Off
81 E-K-Forralo-Switch = On
 E-K-Forralo-kWh Meter = 0.420 kWh
 E-K-Forralo-Watt = 0
88 E-K-Teafozo-Switch = On
 E-K-Teafozo-kWh Meter = 0.000 kWh
 E-K-Teafozo-Watt = 0
96 E-K-Redony-Switch = Set Level: 58 %
114 E-GY-Klima-Switch = On
 E-GY-Klima-kWh Meter = 0.490 kWh
 E-GY-Klima-Watt = 6.7
123 E-K-Radiator-Valve Opening = 80
125 E-K-Radiator-Heat = 10.5
 E-K-Radiator-Air Temperature = 27.9
148 E-F-Radiator-Valve Opening = 0
150 E-F-Radiator-Heat = 10.0
 E-F-Radiator-Air Temperature = 26.7
157 E-H-Radiator-Valve Opening = 0
159 E-H-Radiator-Heat = 10.0
 E-H-Radiator-Air Temperature = 27.8
170 E-I-Radiator-Valve Opening = 0
172 E-I-Radiator-Heat = 10.0
 E-I-Radiator-Air Temperature = 28
183 E-GY-Radiator-Valve Opening = 0
185 E-GY-Radiator-Heat = 10.0
 E-GY-Radiator-Air Temperature = 28.1
196 E-N-Radiator-Bal-Valve Opening = 0
197 Thermostat Mode = Heat
198 E-N-Radiator-Bal-Heat = 10.0
 E-N-Radiator-Bal-Air Temperature = 27.8
209 E-N-Radiator-Jobb-Valve Opening = 0
211 E-N-Radiator-Jobb-Heat = 10.0
 E-N-Radiator-Jobb-Air Temperature = 27.5
222 E-K-Mozgas1-Sensor = Off
224 E-K-Mozgas1-Illuminance = 19 Lux
229 E-I-Mozgas1-Sensor = Off
231 E-I-Mozgas1-Illuminance = 16 Lux
233 E-I-Mozgas2-Sensor = On
235 E-I-Mozgas2-Illuminance = 17 Lux
237 E-N-Mozgas1-Sensor = Off
239 E-N-Mozgas1-Illuminance = 10 Lux
241 Battery - E-K-Radiator = 60 %
242 Battery - E-F-Radiator = 50 %
243 Battery - E-H-Radiator = 55 %
244 Battery - E-I-Radiator = 30 %
245 Battery - E-GY-Radiator = 55 %
246 Battery - E-N-Radiator-Bal = 60 %
247 Battery - E-N-Radiator-Jobb = 55 %
248 Battery - E-K-Mozgas1 = 100 %
249 Battery - E-I-Mozgas1 = 70 %
250 Battery - E-I-Mozgas2 = 100 %
251 Battery - E-N-Mozgas1 = 100 %
267 E-H-Iranyfeny-Switch = Off
 E-H-Iranyfeny-Watt = 0
 E-H-Iranyfeny-kWh Meter = 0.100 kWh
274 Battery - E-K-Vizbetores1 = 100 %
275 E-H-Mozgas1-Sensor = Off
277 E-H-Mozgas1-Illuminance = 9 Lux

real    0m0.378s
user    0m0.153s
sys     0m0.065s
root@domoticz:/var/www/html/secure#
php _fetchdomoticz.php output with loaded pass2php lua script:

Code: Select all

root@domoticz:/var/www/html/secure# time php _fetchdomoticz.php
9 E-K-Huto-Switch = On
 E-K-Huto-kWh Meter = 9.600 kWh
 E-K-Huto-Watt = 86.6
16 E-F-Bojler-Switch = On
 E-F-Bojler-kWh Meter = 27.460 kWh
 E-F-Bojler-Watt = 0
23 E-F-HMV-Switch = Off
 E-F-HMV-kWh Meter = 0.000 kWh
 E-F-HMV-Watt = 0
30 E-H-Klima-Switch = Off
33 E-I-Munkaallomas-Switch = On
 E-I-Munkaallomas-kWh Meter = 4.820 kWh
 E-I-Munkaallomas-Watt = 70.9
 E-H-Klima-kWh Meter = 0.000 kWh
 E-H-Klima-Watt = 0
58 E-I-Kapcsolo-Bal = Off
59 E-I-Kapcsolo-Jobb = On
60 E-N-Iranyfeny-Switch = On
 E-N-Iranyfeny-kWh Meter = 0.120 kWh
 E-N-Iranyfeny-Watt = 0
65 E-N-Klima-Switch = Off
 E-N-Klima-kWh Meter = 0.000 kWh
 E-N-Klima-Watt = 0
73 E-K-Kapcsolo1-Jobb = On
74 E-K-Kapcsolo1-Bal = Off
81 E-K-Forralo-Switch = On
 E-K-Forralo-kWh Meter = 0.420 kWh
 E-K-Forralo-Watt = 0
88 E-K-Teafozo-Switch = On
 E-K-Teafozo-kWh Meter = 0.000 kWh
 E-K-Teafozo-Watt = 0
96 E-K-Redony-Switch = Set Level: 58 %
114 E-GY-Klima-Switch = On
 E-GY-Klima-kWh Meter = 0.490 kWh
 E-GY-Klima-Watt = 6.8
123 E-K-Radiator-Valve Opening = 80
125 E-K-Radiator-Heat = 10.5
 E-K-Radiator-Air Temperature = 27.9
148 E-F-Radiator-Valve Opening = 0
150 E-F-Radiator-Heat = 10.0
 E-F-Radiator-Air Temperature = 26.7
157 E-H-Radiator-Valve Opening = 0
159 E-H-Radiator-Heat = 10.0
 E-H-Radiator-Air Temperature = 27.8
170 E-I-Radiator-Valve Opening = 0
172 E-I-Radiator-Heat = 10.0
 E-I-Radiator-Air Temperature = 28
183 E-GY-Radiator-Valve Opening = 0
185 E-GY-Radiator-Heat = 10.0
 E-GY-Radiator-Air Temperature = 28.1
196 E-N-Radiator-Bal-Valve Opening = 0
197 Thermostat Mode = Heat
198 E-N-Radiator-Bal-Heat = 10.0
 E-N-Radiator-Bal-Air Temperature = 27.7
209 E-N-Radiator-Jobb-Valve Opening = 0
211 E-N-Radiator-Jobb-Heat = 10.0
 E-N-Radiator-Jobb-Air Temperature = 27.5
222 E-K-Mozgas1-Sensor = Off
224 E-K-Mozgas1-Illuminance = 19 Lux
229 E-I-Mozgas1-Sensor = On
231 E-I-Mozgas1-Illuminance = 16 Lux
233 E-I-Mozgas2-Sensor = On
235 E-I-Mozgas2-Illuminance = 17 Lux
237 E-N-Mozgas1-Sensor = Off
239 E-N-Mozgas1-Illuminance = 10 Lux
241 Battery - E-K-Radiator = 60 %
242 Battery - E-F-Radiator = 50 %
243 Battery - E-H-Radiator = 55 %
244 Battery - E-I-Radiator = 30 %
245 Battery - E-GY-Radiator = 55 %
246 Battery - E-N-Radiator-Bal = 60 %
247 Battery - E-N-Radiator-Jobb = 55 %
248 Battery - E-K-Mozgas1 = 100 %
249 Battery - E-I-Mozgas1 = 70 %
250 Battery - E-I-Mozgas2 = 100 %
251 Battery - E-N-Mozgas1 = 100 %
267 E-H-Iranyfeny-Switch = Off
 E-H-Iranyfeny-Watt = 0
 E-H-Iranyfeny-kWh Meter = 0.100 kWh
274 Battery - E-K-Vizbetores1 = 100 %
275 E-H-Mozgas1-Sensor = Off
277 E-H-Mozgas1-Illuminance = 9 Lux

real    0m2.938s
user    0m0.138s
sys     0m0.053s
iotop by high iowait

Code: Select all

Total DISK READ:         0.00 B/s | Total DISK WRITE:        12.32 K/s
Current DISK READ:       0.00 B/s | Current DISK WRITE:      43.11 K/s
  TID  PRIO  USER     DISK READ  DISK WRITE  SWAPIN     IO>    COMMAND
  702 be/4 mysql       0.00 B/s    0.00 B/s  0.00 % 99.99 % mysqld
22936 be/4 mysql       0.00 B/s    0.00 B/s  0.00 % 91.22 % mysqld
   87 be/3 root        0.00 B/s    3.08 K/s  0.00 %  4.10 % [jbd2/mmcblk0p2-]
  729 be/4 mysql       0.00 B/s    3.08 K/s  0.00 %  0.00 % mysqld
  716 be/4 root        0.00 B/s    3.08 K/s  0.00 %  0.00 % domoticz
User avatar
Egregius
Posts: 2592
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: v2024.7
Location: Beitem, BE
Contact:

Re: Pass2PHP

Post by Egregius »

That's a lot of information but I'm not really sure I understand the question.
My load average is truly idle:

Code: Select all

top - 07:16:12 up 6 days, 20:28,  1 user,  load average: 0.00, 0.02, 0.00
Tasks: 118 total,   1 running, 117 sleeping,   0 stopped,   0 zombie
%Cpu(s):  0.1 us,  0.2 sy,  0.1 ni, 99.5 id,  0.0 wa,  0.0 hi,  0.1 si,  0.0 st
MiB Mem :   1994.6 total,    110.2 free,    568.4 used,   1316.0 buff/cache
MiB Swap:    256.0 total,    249.0 free,      7.0 used.    996.3 avail Mem

  PID USER      PR  NI    VIRT    RES    SHR S  %CPU  %MEM     TIME+ COMMAND
  742 root      20   0 1708368 138924  18568 S   0.3   6.8  23:33.13 domoticz
  926 mysql     20   0 2570924 130152   8528 S   0.3   6.4  14:37.81 mysqld
    1 root      20   0  170748  10456   7748 S   0.0   0.5   1:19.43 systemd
It's not because there's only one file in the pass2php folder that only that device is sent to php. All device updates are sent to php by the lua script. How much request that are depends on your number of devices and power readings.

I don't think you need the mcrypt extension as it's deprecated in PHP 7.
Also, the fetchdomoticz script is to load all devices in the MySQL table, it runs independent from the lua script.
kispalsz
Posts: 31
Joined: Friday 13 October 2017 19:56
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Pass2PHP

Post by kispalsz »

I use Raspbery pi 3b +
Your machine is an Intel Nuc with an SSD.

Is it possible that the floorplan version with php 7.3 and with mysql ( mariadb) can no longer run on an RPI3? Too little RPI CPU / IO?

I tried to do it all over again. Without SQL. From the descriptions in the forum, I have snapped together code that does not use sql. But it's not too fast either.

With LUA script Test:

Code: Select all

commandArray = {}
if (devicechanged['E-H-Mozgas1-Sensor'] == 'On' ) then
 
    os.execute('curl -s "http://192.168.42.36:8080/json.htm?type=command&param=switchlight&idx=59&switchcmd=On" &')
    
end
return commandArray
With only device switch LUA script: 265 msec 2020-06-29 16:20:14.192 -> 2020-06-29 16:20:14.457

Code: Select all

2020-06-29 16:20:14.188  Status: OpenZWave: Alarm received (Home Security: Motion Detected at Unknown Location), NodeID: 38 (0x26)
2020-06-29 16:20:14.192  (AEON) Light/Switch (E-H-Mozgas1-Sensor)
2020-06-29 16:20:14.206  (AEON) General/Alarm (Alarm Type: Home Security 7 (0x07))
2020-06-29 16:20:14.219  (AEON) Light/Switch (Home Security)
2020-06-29 16:20:14.256  (AEON) Light/Switch (E-H-Mozgas1-Sensor)
2020-06-29 16:20:14.330  (AEON) Lux (E-H-Mozgas1-Illuminance)
2020-06-29 16:20:14.457  Status: User: Admin initiated a switch command (59/E-I-Kapcsolo-Jobb/On)
2020-06-29 16:20:14.458  OpenZWave: Domoticz has send a Switch command! NodeID: 10 (0x0a)
2020-06-29 16:20:14.463  (AEON) Light/Switch (E-I-Kapcsolo-Jobb)

With old, (?working?) pass2php.php solution: 298 ms! 2020-06-29 16:41:45.071 -> 2020-06-29 16:41:45.369
I don't understand if there is a motion detection, why run an Off detection first (2020-06-29 16:41:45.238 Status: => E-H-Mozgas1-Sensor = Off) , and then an On.(2020-06-29 16:41:45.366 Status: => E-H-Mozgas1-Sensor = On)

Code: Select all

2020-06-29 16:41:45.067  Status: OpenZWave: Alarm received (Home Security: Motion Detected at Unknown Location), NodeID: 38 (0x26)
2020-06-29 16:41:45.071  (AEON) Light/Switch (E-H-Mozgas1-Sensor)
2020-06-29 16:41:45.086  (AEON) General/Alarm (Alarm Type: Home Security 7 (0x07))
2020-06-29 16:41:45.099  (AEON) Light/Switch (Home Security)
2020-06-29 16:41:45.135  (AEON) Light/Switch (E-H-Mozgas1-Sensor)
2020-06-29 16:41:45.185  Status: LUA: Start of script device
2020-06-29 16:41:45.187  Status: LUA: End of script device
2020-06-29 16:41:45.202  Status: LUA: Curl ended
2020-06-29 16:41:45.238  Status: => E-H-Mozgas1-Sensor = Off
2020-06-29 16:41:45.318  Status: LUA: Start of script device
2020-06-29 16:41:45.320  Status: LUA: End of script device
2020-06-29 16:41:45.335  Status: LUA: Curl ended
2020-06-29 16:41:45.366  Status: => E-H-Mozgas1-Sensor = On
2020-06-29 16:41:45.367  Status: => Switching on..
2020-06-29 16:41:45.369  Status: User: Admin initiated a switch command (59/E-I-Kapcsolo-Jobb/On)
2020-06-29 16:41:45.369  OpenZWave: Domoticz has send a Switch command! NodeID: 10 (0x0a)
2020-06-29 16:41:45.376  (AEON) Light/Switch (E-I-Kapcsolo-Jobb)

Lua script is domoicz/script folder

Code: Select all

function os.capture(cmd, raw)
  local f = assert(io.popen(cmd, 'r'))
  local s = assert(f:read('*a'))
  f:close()
  if raw then return s end
  s = string.gsub(s, '^%s+', '')
  s = string.gsub(s, '%s+$', '')
  s = string.gsub(s, '[\n\r]+', ' ')
  return s
end

print("Start of script device");
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
print("End of script device");

 os.execute('curl -s --data "c='..c..'&s='..s..'&i='..i..'&t='..t..'" http://127.0.0.1/secure/pass2php.php &')

print("Curl ended");

commandArray={}
return commandArray
pass2php.php file:

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']);
//lg('4. Egregius Start of Pass2PHP');
foreach($c as $device=>$status){
 // lg($device.' = '.$status);
    if(@include '/var/www/html/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 '/var/www/html/secure/pass2php/__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;
}
function double($idx,$action,$comment='',$wait=2000000){
    sw($idx,$action,$comment);
    usleep($wait);
    sw($idx,$action,$comment.' repeat',0);
    global $actions;$actions=$actions+2;
}
function sl($idx,$level,$info=''){
    lg('SETLEVEL '.$idx.' '.$level.' '.$info);
    file_get_contents('http://127.0.0.1:8080/json.htm?type=command&param=switchlight&idx='.$idx.'&switchcmd=Set%20Level&level='.$level);
}
function ud($idx,$nvalue,$svalue,$info=""){
    if(!in_array($idx, array(395,532,534)))lg("UPDATE ".$idx." ".$nvalue." ".$svalue." ".$info);
    file_get_contents('http://127.0.0.1:8080/json.htm?type=command&param=udevice&idx='.$idx.'&nvalue='.$nvalue.'&svalue='.$svalue);
    global $actions;$actions=$actions+1;
}
function telegram($msg,$silent=true,$to=1){
    $telegrambot='123456789:ABCD-xCRhO-RBfUqICiJs8q9A_3YIr9irxI';
    $telegramchatid=123456789;
    $telegramchatid2=234567890;
    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;}

}
function lg($msg){file_get_contents('http://127.0.0.1:8080/json.htm?type=command&param=addlogmessage&message='.urlencode('=> '.$msg));}
function ios($msg){
    $appledevice='1234567890/ZHxYptWlD4zoKvGC1VYH805kSRqROHYVNSUzmWV';
    $appleid='[email protected]';
    $applepass='applepass';
    require_once('findmyiphone.php');
    $fmi=new FindMyiPhone(appleid,applepass);
    $fmi->playSound(appledevice,$msg);
    sms($msg);
}
function sms($msg){
    exit;
    $smsuser='clickatelluser';
    $smspassword='clickatellpass';
    $smsapi=1234567;
    $smstofrom=32123456789;
    file_get_contents('http://api.clickatell.com/http/sendmsg?user='.$smsuser.'&password='.$smspassword.'&api_id='.$smsapi.'&to='.$smstofrom.'&text='.urlencode($msg).'&from='.$smstofrom.'');
}
function RefreshZwave($node){
    $last=apcu_fetch('refresh'.$node);
    apcu_store('refresh'.$node,time);
    if($last<time-3600){
        $devices=json_decode(file_get_contents('http://127.0.0.1:8080/json.htm?type=openzwavenodes&idx=3',false),true);
        foreach($devices['result'] as $devozw)
            if($devozw['NodeID']==$node){
                $device=$devozw['Description'].' '.$devozw['Name'];
                break;
            }
        lg(' > Refreshing node '.$node.' '.$device);
        for($k=1;$k<=5;$k++){
            $result=file_get_contents('http://127.0.0.1:8080/ozwcp/refreshpost.html',false,stream_context_create(array('http'=>array('header'=>'Content-Type: application/x-www-form-urlencoded\r\n','method'=>'POST','content'=>http_build_query(array('fun'=>'racp','node'=>$node)),),)));
            if($result==='OK')break;
            sleep(1);
        }
        /*if(apcu_fetch('timedeadnodes')<time-298){apcu_store('timedeadnodes',time);foreach($devices as $node=>$data){if($node=="result"){foreach($data as $index=>$eltsNode){if($eltsNode["State"]=="Dead"&&!in_array($eltsNode['NodeID'],array(57))){telegram('Node '.$eltsNode['NodeID'].' '.$eltsNode['Description'].' ('.$eltsNode['Name'].') marked as dead, reviving '.ZwaveCommand($eltsNode['NodeID'],'HasNodeFailed'));ControllerBusy(10);ZwaveCommand(1,'Cancel');}}}}}*/
    }
}
function Zwavecancelaction(){file_get_contents('http://127.0.0.1:8080/ozwcp/admpost.html',false,stream_context_create(array('http'=>array('header'=>'Content-Type: application/x-www-form-urlencoded\r\n','method'=>'POST','content'=>http_build_query(array('fun'=>'cancel')),),)));}
function ZwaveCommand($node,$command){$cm=array('AssignReturnRoute'=>'assrr','DeleteAllReturnRoutes'=>'delarr','NodeNeighbourUpdate'=>'reqnnu','RefreshNodeInformation'=>'refreshnode','RequestNetworkUpdate'=>'reqnu','HasNodeFailed'=>'hnf','Cancel'=>'cancel');$cm=$cm[$command];for($k=1;$k<=5;$k++){$result=file_get_contents('http://127.0.0.1:8080/ozwcp/admpost.html',false,stream_context_create(array('http'=>array('header'=>'Content-Type: application/x-www-form-urlencoded\r\n','method'=>'POST','content'=>http_build_query(array('fun'=>$cm,'node'=>'node'.$node)),),)));if($result=='OK')break;sleep(1);}return $result;}
function ControllerBusy($retries){for($k=1;$k<=$retries;$k++){$result=file_get_contents('http://127.0.0.1:8080/ozwcp/poll.xml');$p=xml_parser_create();xml_parse_into_struct($p,$result,$vals,$index);xml_parser_free($p);foreach($vals as $val){if($val['tag']=='ADMIN'){$result=$val['attributes']['ACTIVE'];break;}}if($result=='false')break;if($k==$retries){ZwaveCommand(1,'Cancel');break;}sleep(1);}}
function convertToHours($time){if($time<600)return substr(strftime('%M:%S',$time),1);elseif($time>=600&&$time<3600)return strftime('%M:%S',$time);else return strftime('%k:%M:%S',$time);}
function ex($x){
    $return=array();
    $pieces=explode('#',$x);
    foreach($pieces as $piece){
        $keyval=explode('|',$piece);
        if(count($keyval)>1)$return[$keyval[0]]=$keyval[1];
        else $return[$keyval[0]]='';
    }
    return $return;
}
roo

My pass2php folder: E-H-Mozgas1-Sensor.php

Code: Select all

<?php
lg($device.' = '.$status);
if ($status=="On") {
    lg("Switching on..");
   sw(59,'On');
}
User avatar
Egregius
Posts: 2592
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: v2024.7
Location: Beitem, BE
Contact:

Re: Pass2PHP

Post by Egregius »

It can perfectly run on a RPi 3. Without a doubt.
Your timings aren't as good as they should be. Should be less than 100 msec.
Do you have other lua/dzvents/blockly running?
What are the response times from those?
kispalsz
Posts: 31
Joined: Friday 13 October 2017 19:56
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Pass2PHP

Post by kispalsz »

I didn't have another LUA script. I used DzVents scripts. I have now disabled the DZVentst scripts (not deleted) and disabled the full DzVents feature in the settings.

This is what my scripts folder looks like now:

Response time: 2020-06-30 09:20:48.618 --> 2020-06-30 09:20:48.755 137 ms

Code: Select all

2020-06-30 09:20:48.614  Status: OpenZWave: Alarm received (Home Security: Motion Detected at Unknown Location), NodeID: 38 (0x26)
2020-06-30 09:20:48.618  (AEON) Light/Switch (E-H-Mozgas1-Sensor)
2020-06-30 09:20:48.627  Status: LUA: Start of script device
2020-06-30 09:20:48.632  Status: LUA: End of script device
2020-06-30 09:20:48.632  (AEON) General/Alarm (Alarm Type: Home Security 7 (0x07))
2020-06-30 09:20:48.651  (AEON) Light/Switch (Home Security)
2020-06-30 09:20:48.651  Status: LUA: Curl ended
2020-06-30 09:20:48.660  (AEON) Light/Switch (E-H-Mozgas1-Sensor)
2020-06-30 09:20:48.670  Status: LUA: Start of script device
2020-06-30 09:20:48.670  (AEON) Lux (E-H-Mozgas1-Illuminance)
2020-06-30 09:20:48.672  Status: LUA: End of script device
2020-06-30 09:20:48.695  Status: LUA: Curl ended
2020-06-30 09:20:48.703  Status: LUA: Start of script device
2020-06-30 09:20:48.705  Status: LUA: End of script device
2020-06-30 09:20:48.713  Status: => E-H-Mozgas1-Sensor = Off
2020-06-30 09:20:48.728  Status: LUA: Curl ended
2020-06-30 09:20:48.751  Status: => E-H-Mozgas1-Sensor = On
2020-06-30 09:20:48.752  Status: => Switching on..
2020-06-30 09:20:48.755  Status: User: Admin initiated a switch command (59/E-I-Kapcsolo-Jobb/On)
2020-06-30 09:20:48.757  OpenZWave: Domoticz has send a Switch command! NodeID: 10 (0x0a)

But with disabled Dzvents and disabled Pass2PHP, only with one GUI LUA test script:
Response time: 2020-06-30 09:38:43.390 --> 2020-06-30 09:38:43.532 142 ms

Code: Select all

2020-06-30 09:38:43.386  Status: OpenZWave: Alarm received (Home Security: Motion Detected at Unknown Location), NodeID: 38 (0x26)
2020-06-30 09:38:43.390  (AEON) Light/Switch (E-H-Mozgas1-Sensor)
2020-06-30 09:38:43.401  (AEON) General/Alarm (Alarm Type: Home Security 7 (0x07))
2020-06-30 09:38:43.411  (AEON) Light/Switch (Home Security)
2020-06-30 09:38:43.424  (AEON) Light/Switch (E-H-Mozgas1-Sensor)
2020-06-30 09:38:43.451  (AEON) Lux (E-H-Mozgas1-Illuminance)
2020-06-30 09:38:43.531  Status: User: Admin initiated a switch command (59/E-I-Kapcsolo-Jobb/On)
2020-06-30 09:38:43.532  OpenZWave: Domoticz has send a Switch command! NodeID: 10 (0x0a)
2020-06-30 09:38:43.535  (AEON) Light/Switch (E-I-Kapcsolo-Jobb)


You once wrote that maybe a combination of PI3 and Synology the responstime is 43ms. What is Syno like?
What was the best response time you were able to achieve with only RPI 3?

Why is there an OFF first?: (This appears when the sensor has already been detected.)
"2020-06-30 09:20:48.713 Status: => E-H-Mozgas1-Sensor = Off"
User avatar
Egregius
Posts: 2592
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: v2024.7
Location: Beitem, BE
Contact:

Re: Pass2PHP

Post by Egregius »

If you remove some of the lg() lines it'll be a bit faster.
Don't remember how fast it was during my installation on RPi, it might be somewhere in this topic.
Isn't 137 msec fast enough?

It's domoticz that sents the device statusses. If domoticz sends off and then on pass2php can't do anything about it.

One thing's for sure. The more scripting types you activate the slower it'll be. Is you only use 1 it'll be the fastest.
kispalsz
Posts: 31
Joined: Friday 13 October 2017 19:56
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Pass2PHP

Post by kispalsz »

Thanks!
With pass2php Without call the lg() function, response time, with disabled DzVents function, and disabled DzVents scripts, with disabled mysd server.: 2020-06-30 11:45:31.750 --> 2020-06-30 11:45:31.862 112ms

Code: Select all

2020-06-30 11:45:31.748  Status: OpenZWave: Alarm received (Home Security: Motion Detected at Unknown Location), NodeID: 38 (0x26)
2020-06-30 11:45:31.750  (AEON) Light/Switch (E-H-Mozgas1-Sensor)
2020-06-30 11:45:31.755  (AEON) General/Alarm (Alarm Type: Home Security 7 (0x07))
2020-06-30 11:45:31.767  (AEON) Light/Switch (Home Security)
2020-06-30 11:45:31.812  (AEON) Light/Switch (E-H-Mozgas1-Sensor)
2020-06-30 11:45:31.862  Status: User: Admin initiated a switch command (59/E-I-Kapcsolo-Jobb/On)
2020-06-30 11:45:31.863  OpenZWave: Domoticz has send a Switch command! NodeID: 10 (0x0a)
With enabled DzVents function, disabled Dzvents script, and disabled mysql, response time:
2020-06-30 12:01:18.543 --> 2020-06-30 12:01:18.636 92 ms

Code: Select all

2020-06-30 12:01:18.533  Status: OpenZWave: Alarm received (Home Security: Motion Detected at Unknown Location), NodeID: 38 (0x26)
2020-06-30 12:01:18.543  (AEON) Light/Switch (E-H-Mozgas1-Sensor)
2020-06-30 12:01:18.552  (AEON) General/Alarm (Alarm Type: Home Security 7 (0x07))
2020-06-30 12:01:18.572  (AEON) Light/Switch (Home Security)
2020-06-30 12:01:18.587  (AEON) Light/Switch (E-H-Mozgas1-Sensor)
2020-06-30 12:01:18.636  Status: User: Admin initiated a switch command (59/E-I-Kapcsolo-Jobb/On)
2020-06-30 12:01:18.637  OpenZWave: Domoticz has send a Switch command! NodeID: 10 (0x0a)
I think this system works with a response time of around 100 ms, regardless of whether DzVents is turned on or not. ( with disabled Dzvents scripts).

Do you see Domoticz sending an OFF command first and then an ON?
According to these:
Ther first trigger: 2020-06-30 12:01:18.543 (AEON) Light/Switch (E-H-Mozgas1-Sensor) --> Off
The second trigger: 2020-06-30 12:01:18.587 (AEON) Light/Switch (E-H-Mozgas1-Sensor) --> On

With trigger "Status: OpenZWave: Alarm received : response time: 2020-06-30 12:13:45.101 --> 2020-06-30 12:13:45.187
This is only: 86 ms ( with enabled DzVents functoin) but second time 146 ms

Code: Select all

2020-06-30 12:13:45.101  Status: OpenZWave: Alarm received (Home Security: Motion Detected at Unknown Location), NodeID: 38 (0x26)
2020-06-30 12:13:45.105  (AEON) Light/Switch (E-H-Mozgas1-Sensor)
2020-06-30 12:13:45.121  (AEON) General/Alarm (E-H-Mozgas1-Alarm)
2020-06-30 12:13:45.128  (AEON) Light/Switch (Home Security)
2020-06-30 12:13:45.147  (AEON) Light/Switch (E-H-Mozgas1-Sensor)
2020-06-30 12:13:45.187  Status: User: Admin initiated a switch command (59/E-I-Kapcsolo-Jobb/On)
Maybe to try the Synogy solution, run pass2php on it. I have a Synology DS218J device.
It may be due to the many devices, but the performance of the PI is not uniform. Sometimes my console also slows down.
User avatar
Egregius
Posts: 2592
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: v2024.7
Location: Beitem, BE
Contact:

Re: Pass2PHP

Post by Egregius »

I would think that it is your sensor that sends the Off before the On. Not logical, that's sure. They all kind of act different.

Code: Select all

2020-06-30 12:51:01.790 (Xiaomi) Light/Switch (deurgarage)
2020-06-30 12:51:02.648 (ZWAVE) Light/Switch (pirkeuken)
2020-06-30 12:51:03.257 (ZWAVE) Light/Switch (pirgarage Sensor)
2020-06-30 12:51:03.258 (ZWAVE) General/Alarm (pirgarage Alarm Type: Home Security 7 (0x07))
2020-06-30 12:51:03.260 (ZWAVE) Light/Switch (pirgarage)
2020-06-30 12:51:03.257 Status: OpenZWave: Alarm received (Home Security: Motion Detected at Unknown Location), NodeID: 121 (0x79)
pirkeuken is a Fibaro Motion Eye: sends only the On status and Off after 30 sec.
pirgarage is a Everspring Outdoor Motion Detector and sends multiple things. In my usage not a problem because the light is already on by the Xiaomi door contact.

I'm also wondering, how fast does dzvents respond with a simple if motion switch light script?

I don't think the number of devices makes a big difference in speed. I have 293 used devices out of 615 total in domoticz, so I think that's already quite a installation.
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 »

I've heard rumors that the more dzvents scripts you have, the slower the system gets. and since domoticz is kicking of the scripts based on the type of script and you are using an additional scripting method(PHP) the system might get slower.
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,

quick question, Still have trouble using the php timing script.
I see two things happening.

- I have a script in the _cron60 for a motion sensor that states that when motion is detected the light goes off after 1 minute, when motion is detected in the mean time the 1-minute-counter should start over. this last bit is not working. the light is first going off and then(with new motion) going on again.But since domoticz is sending the "Off" command it cannot directly send over the "On" command and therefor takes a while for the light to turn On again.
the script is as following:

Code: Select all

if ($d['Bijkeuken']['s']=='On'&&$d['PIR_Bijkeuken']['s']=='Off'&&$d['Auto']['s']=='Off'&&past('Bijkeuken')>60) {
	sw('Bijkeuken', 'Off');
}
- the second thing is that I have a script that does different things based on time. so when motion is detected at, for example 6am the light should be 30%, when motion is detected at 8pm the light should 80% and when motion is detected at 3pm the light should be 0%
the script is as following:

Code: Select all

<?php
if ($status=='On') {
	if (TIME<=strtotime('7:00')) {
		sl('Overloop', 30);
} elseif (TIME<=strtotime('8:00') || TIME>=strtotime('19:00')) {
		sl('Overloop', 30);
} else {
		sl('Overloop', 100);
	}
}
In regards to the strtotime function, I've read that you need to have your timezone entered somewhere for it to work correctly. might this be the case it doesn't work?

thnx in advance!
User avatar
Egregius
Posts: 2592
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: v2024.7
Location: Beitem, BE
Contact:

Re: Pass2PHP

Post by Egregius »

Do you have your timezone set in your php.ini?

in /etc/php/7.3/fpm

Code: Select all

[Date]
; Defines the default timezone used by the date functions
; http://php.net/date.timezone
date.timezone = 'Europe/Brussels'
Do you have a switch called 'Auto'? I use the dummy switch Auto to set almost everything to auto or manual.
You can test without the auto and use the past on the PIR. Then the light will only go out when the PIR is off for more than 60 seconds.

Code: Select all

if ($d['Bijkeuken']['s']=='On'&&$d['PIR_Bijkeuken']['s']=='Off'&&past('PIR_Bijkeuken')>60) {
	sw('Bijkeuken', 'Off');
}
User avatar
Egregius
Posts: 2592
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: v2024.7
Location: Beitem, BE
Contact:

Re: Pass2PHP

Post by Egregius »

Trigun wrote: Tuesday 30 June 2020 13:27 I've heard rumors that the more dzvents scripts you have, the slower the system gets. and since domoticz is kicking of the scripts based on the type of script and you are using an additional scripting method(PHP) the system might get slower.
Indeed, they're executed sequentially. For example: first all blocklies, then all dzvents, then all python, then all lua scripts.
Don't know the exact order and I don't care about it either. Everything can be done easily in PHP so I don't need any other scripts.
I can also believe that dzvents gets slower the more scripts you add. That's because all scripts are executed on every device update and you filter the device in the script itself. For Pass2PHP that's not the case. You can have thousands of scripts without any delay.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest