For the love of my scroll wheel, please use quotes as they are intented. Quote a specific part of a post, don't double quote and don't quote at all when responding to the last message. It makes posts almost unreadable.poudeness wrote:Trigun wrote:sincze wrote:
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
-
- Posts: 390
- Joined: Wednesday 30 November 2016 11:58
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 4.10717
- Contact:
Re: Pass2PHP
You are right, Will take it into account.
I was wondering how the scripts are working if, for example, you have configured the hardware settings of the pir. Will it override?
As I have a few of the NEO coolcam PIRs where the auto off setting is pre configured.
Sent from my iPhone using Tapatalk
I was wondering how the scripts are working if, for example, you have configured the hardware settings of the pir. Will it override?
As I have a few of the NEO coolcam PIRs where the auto off setting is pre configured.
Sent from my iPhone using Tapatalk
-
- Posts: 667
- Joined: Wednesday 08 March 2017 9:42
- Target OS: Linux
- Domoticz version: 3.8993
- Location: Amsterdam
- Contact:
Re: Pass2PHP
Little other question. Is this way faster then for example dzvents?
I was testing and for me it seems slower in action then using dzvents.
Maybe pass2php there are more complex scripting possible?
I was testing and for me it seems slower in action then using dzvents.
Maybe pass2php there are more complex scripting possible?
RPi3 B+, Debain Stretch, Domoticz, Homebridge, Dashticz, RFLink, Milight, Z-Wave, Fibaro, Nanoleaf, Nest, Harmony Hub, Now try to understand pass2php
- Egregius
- Posts: 2582
- Joined: Thursday 09 April 2015 12:19
- Target OS: Linux
- Domoticz version: v2024.7
- Location: Beitem, BE
- Contact:
Re: Pass2PHP
pass2php will only do what you say it must do. If you don't script anything to set the pir to off it won't. If you don't do anything in your pir script when status is off nothing will be done. Normally you shouldn't have to override pir stuff. As long as there is motion they should remain on.
Good question where I also like to know the answer to.
I do know that domoticz handles scripts in a certain order. From testing I learned that file based lua scripts are handled before the database lua scripts. And that those 2 are before the switch on/off actions. Where dzvents comes in I don't know. Never used it and probably never will.
I do know that a switch on/off action takes about 1200msec. That was my first way of pushing statusses to php. Then I did something different and the response time went down to 800msec.
Sometime later the lua script was born and the response times went down to 80-120msec.
Now, with the latest pass2php version on a i3 Intel Nuc I'm down to 1 msec. Is that fast? Yes it is. How fast? Lets do a litle calculation when you walk at a speed of 5km/h and you trigger a PIR. At 1200msec you would be 1,66m far. At 1msec only 0,1cm.
Depending on the above mentioned order it could be that dzvents is faster if you use a mixed scripting environment. It should and can be tested of course.
In my system I only have 1 script in Domoticz and that is the lua pass2php script. Nothing else, dzvents deactived.
I always say: "Only your imagination is the limit"
You can do everything you like in PHP.
- sincze
- Posts: 1300
- Joined: Monday 02 June 2014 22:46
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2024.4
- Location: Netherlands / Breda Area
- Contact:
Re: Pass2PHP
Don't forget the php examples and classes available on the web that you can integrate easily.
I am do deep into this pass2php everything is working like a charm. Unable to rewrite code in lua again. Hahaha
Sent from my ONEPLUS A6003 using Tapatalk
I am do deep into this pass2php everything is working like a charm. Unable to rewrite code in lua again. Hahaha
Sent from my ONEPLUS A6003 using Tapatalk
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.
-
- Posts: 390
- Joined: Wednesday 30 November 2016 11:58
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 4.10717
- Contact:
Re: Pass2PHP
He Guys,
when I do a tail(yes this is my new best friend ) I can see that th "on" script is working. I see the following line:
I was wondering what the "Check=false" line does?
also, How can I check that the _cron60 is working?
Damn guys, you guys did a very nice job with Pass2php. the more I work with it, the more things I see are possible.
for me, getting to know PHP better is key but I gues this is partly experience
thanks!
when I do a tail(yes this is my new best friend ) I can see that th "on" script is working. I see the following line:
Code: Select all
2019-05-06 15:06:33.040 (SWITCH) | => Bijkeuken => On check=false
also, How can I check that the _cron60 is working?
Damn guys, you guys did a very nice job with Pass2php. the more I work with it, the more things I see are possible.
for me, getting to know PHP better is key but I gues this is partly experience
thanks!
- sincze
- Posts: 1300
- Joined: Monday 02 June 2014 22:46
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2024.4
- Location: Netherlands / Breda Area
- Contact:
Re: Pass2PHP
If you add a lg line to _cron60 you should see that fly by every 60 sec in your tail.
Regarding check false.. look at the specific function.
In sw for example it means I believe "just switch on/off. Do not check current state."
If check is true ... It checks if current state is different to requested state.. if different.. then switch.
Learning curve is a big one indeed. Takes some time but now you can build anything as long as you understand the php part. Hahaha
Regarding check false.. look at the specific function.
In sw for example it means I believe "just switch on/off. Do not check current state."
If check is true ... It checks if current state is different to requested state.. if different.. then switch.
Learning curve is a big one indeed. Takes some time but now you can build anything as long as you understand the php part. Hahaha
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.
-
- Posts: 390
- Joined: Wednesday 30 November 2016 11:58
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 4.10717
- Contact:
Re: Pass2PHP
I have to admit all you guys have been a great learningcurve so thanks for your patience to all my noob questions!
but in the end I am able to help others out as well. if you have tips for me to learn it quicker please let me know!
- Egregius
- Posts: 2582
- Joined: Thursday 09 April 2015 12:19
- Target OS: Linux
- Domoticz version: v2024.7
- Location: Beitem, BE
- Contact:
Re: Pass2PHP
Take a look at the sw function in functions.php.
The arguments are:
function sw($name,$action='Toggle',$check=false,$msg='',$usleep=0)
you can call the function by:
Learning PHP is a nice hobby and there's lots of documentation and examples available.
Pass2php is the result of several years of finetuning. Main thing is that you can start simple and add more and more as you learn it.
Use a good text editor like BBEdit, Notepad++ etc. One that has syntax highlighting and preferably like BBEdit where you can double click a ( or { to see where it ends.
I often have two SSH windows open. One with a tail of the domoticz log, one with a tail of the apache errorlog. With those 2 you see instantly what happens.
Besides all that. Create a versioned backup system. That is a backup where you can go back to versions of yesterday, last week, ... If you screw things up you can easily revert.
The arguments are:
function sw($name,$action='Toggle',$check=false,$msg='',$usleep=0)
you can call the function by:
Code: Select all
sw('test');//Toggle switch
sw('test', 'On');//Switch On
sw('test', 'On', true);//Switch On only if it's not on.
sw('test', 'On', false, 'Just because you need to');//Toggle On, always and add 'Just because you need to' to the logline.
sw('test', 'On', false, null, 500000);//Switch On, always and wait half a second before continuing. Handy when switching an array.
sw(array('switch1', 'switch2', 'switch3'), 'Off');//Switch these 3 switches off, always.
sw(array('switch1', 'switch2', 'switch3'), 'Off', false);//Switch these 3 switches off if they aren't off
sw(array('switch1', 'switch2', 'switch3'), 'Off', false, 'because we\'re out');//Switch these 3 switches off if they aren't off and add a message to the logline
sw(array('switch1', 'switch2', 'switch3'), 'Off', false, 'because we\'re out', 500000);//Switch these 3 switches off if they aren't off and add a message to the logline and wait half a second between commands
Pass2php is the result of several years of finetuning. Main thing is that you can start simple and add more and more as you learn it.
Use a good text editor like BBEdit, Notepad++ etc. One that has syntax highlighting and preferably like BBEdit where you can double click a ( or { to see where it ends.
I often have two SSH windows open. One with a tail of the domoticz log, one with a tail of the apache errorlog. With those 2 you see instantly what happens.
Besides all that. Create a versioned backup system. That is a backup where you can go back to versions of yesterday, last week, ... If you screw things up you can easily revert.
-
- Posts: 390
- Joined: Wednesday 30 November 2016 11:58
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 4.10717
- Contact:
Re: Pass2PHP
Great @Egregius! this is really helpfull, thnx!
Now I still have one issue to tackle before i can go crazy , I can't seem to turn the light off automatically.
I have Cron.sh placed in /home/pi/scripts/pass2php
I have cron.php, _cron60.php and functions placed in /var/www/html/secure
I didn't change any of the original files(cron.sh and cron.php)
_cron60 looks like this:
If I run cron.sh manually I do get a few errors in the CLI:
I wanted it to run with the following crontab:
where am I going wrong?
Now I still have one issue to tackle before i can go crazy , I can't seem to turn the light off automatically.
I have Cron.sh placed in /home/pi/scripts/pass2php
I have cron.php, _cron60.php and functions placed in /var/www/html/secure
I didn't change any of the original files(cron.sh and cron.php)
_cron60 looks like this:
Code: Select all
<?php
if ($d['Bijkeuken']['s']=='On'
&& past('Bijkeuken')>60
) {
sw('Bijkeuken', 'Off');
lg('_cron60test');
}
Code: Select all
pi@raspberrypi:~/domoticz/scripts/pass2php $ ./cron.sh
./cron.sh: line 3: jq: command not found
./cron.sh: line 40: jq: command not found
./cron.sh: line 46: jq: command not found
Failed to set wall message, ignoring: Interactive authentication required.
Failed to reboot system via logind: Interactive authentication required.
Failed to open /dev/initctl: Permission denied
Failed to talk to init daemon.
- sincze
- Posts: 1300
- Joined: Monday 02 June 2014 22:46
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2024.4
- Location: Netherlands / Breda Area
- Contact:
Re: Pass2PHP
Mmm Please install jq to remove the error
Saves yourself some time.
Saves yourself some time.
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
What's in your crontab?
sudo crontab -e
I always restart the service after a change.
sudo service cron restart
Also, you must edit the cron.sh file to your own needs.
sudo crontab -e
I always restart the service after a change.
sudo service cron restart
Also, you must edit the cron.sh file to your own needs.
-
- Posts: 390
- Joined: Wednesday 30 November 2016 11:58
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 4.10717
- Contact:
Re: Pass2PHP
When I start the cron.sh file everything works. But nothing happens after 60 seconds which means the crontab is not working. The crontab looks as following
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
Did you see my crontab?
Remove the cron_60 -x from the line.
And if you're on a Pi add >dev/null 2>&1 to have the output killed and save your SD card. The less writes you have the better.
Code: Select all
# m h dom mon dow command
* * * * * /usr/bin/nice -n20 /var/www/html/secure/cron.sh >/dev/null 2>&1
*/2 * * * * /usr/bin/nice -n20 curl -s "http://127.0.0.1/secure/cron.php?cron120" >/dev/null 2>&1
0 * * * * /usr/bin/nice -n20 curl -s "http://127.0.0.1/secure/cron.php?cron3600" >/dev/null 2>&1
0 0 * * * /usr/bin/nice -n20 curl -s "http://127.0.0.1/secure/cleandomoticzdb.php" >/dev/null 2>&1
1 0 * * * /usr/bin/nice -n20 /var/www/_SQLBackup/sqldaily.sh >dev/null 2>&1
And if you're on a Pi add >dev/null 2>&1 to have the output killed and save your SD card. The less writes you have the better.
- Egregius
- Posts: 2582
- Joined: Thursday 09 April 2015 12:19
- Target OS: Linux
- Domoticz version: v2024.7
- Location: Beitem, BE
- Contact:
Re: Pass2PHP
Another small tip to have commands in ssh faster:
Edit .profile in your users root folder and add aliasses for stuff you use frequently:
With that in place you only need to type q to logout, domo to tail the domoticz log file, error to tail the apache error log. etc
Edit .profile in your users root folder and add aliasses for stuff you use frequently:
Code: Select all
alias q="exit"
alias ll="ls -lsha"
alias upd="apt-get update && apt-get upgrade -y && apt-get dist-upgrade -y"
alias reload_profile=". ~/.profile"
alias xxa="service apache2 restart && service php7.3-fpm restart"
alias error="tail -f -s 0.5 -n 50 /var/log/apache2/error.log"
alias domo="tail -f -s 0.5 -n 50 /var/log/domoticz.log"
- sincze
- Posts: 1300
- Joined: Monday 02 June 2014 22:46
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2024.4
- Location: Netherlands / Breda Area
- Contact:
Re: Pass2PHP
Tnx for the tips. I can work with that.
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.
-
- Posts: 390
- Joined: Wednesday 30 November 2016 11:58
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 4.10717
- Contact:
Re: Pass2PHP
Ok, I did so. the line now looks like this: I don't get it, normally it should work but maybe it work different.Egregius wrote: ↑Tuesday 07 May 2019 6:34 Did you see my crontab?Remove the cron_60 -x from the line.Code: Select all
# m h dom mon dow command * * * * * /usr/bin/nice -n20 /var/www/html/secure/cron.sh >/dev/null 2>&1 */2 * * * * /usr/bin/nice -n20 curl -s "http://127.0.0.1/secure/cron.php?cron120" >/dev/null 2>&1 0 * * * * /usr/bin/nice -n20 curl -s "http://127.0.0.1/secure/cron.php?cron3600" >/dev/null 2>&1 0 0 * * * /usr/bin/nice -n20 curl -s "http://127.0.0.1/secure/cleandomoticzdb.php" >/dev/null 2>&1 1 0 * * * /usr/bin/nice -n20 /var/www/_SQLBackup/sqldaily.sh >dev/null 2>&1
And if you're on a Pi add >dev/null 2>&1 to have the output killed and save your SD card. The less writes you have the better.
I tried sudo crontab -e and entered the same line and this seems to work.
strange! is there a difference between the two different crontabs?
also, does the crontab still work after a reboot?
thnx again!
- sincze
- Posts: 1300
- Joined: Monday 02 June 2014 22:46
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2024.4
- Location: Netherlands / Breda Area
- Contact:
Re: Pass2PHP
also, does the crontab still work after a reboot?
Yes it will work after a reboot
Yes it will work after a reboot
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.
Who is online
Users browsing this forum: No registered users and 1 guest