Pass2PHP

Egregius
Posts: 2171
Joined: Thursday 09 April 2015 12:19
Target OS: Raspberry Pi
Domoticz version: BetaRPi2
Location: Beitem, BE
Contact:

Re: Pass2PHP

Postby Egregius » Friday 28 April 2017 14:12

You're latest code block isn't the pass2php file posted in this topic.
Also the other scripts are very old versions.

tuspam
Posts: 36
Joined: Friday 25 December 2015 1:19
Target OS: Raspberry Pi
Domoticz version: beta
Contact:

Re: Pass2PHP

Postby tuspam » Friday 28 April 2017 14:22

Egregius wrote:You're latest code block isn't the pass2php file posted in this topic.
Also the other scripts are very old versions.


I did try according to this instruction:
https://egregius.be/2016/lua-pass2php-v2-0/

There is somewhere step by step instruction for noobs?

Egregius
Posts: 2171
Joined: Thursday 09 April 2015 12:19
Target OS: Raspberry Pi
Domoticz version: BetaRPi2
Location: Beitem, BE
Contact:

Re: Pass2PHP

Postby Egregius » Friday 28 April 2017 14:48

Crap, my site is very outdated :?

This is more recent (but could also use an update) https://github.com/Egregius

tuspam
Posts: 36
Joined: Friday 25 December 2015 1:19
Target OS: Raspberry Pi
Domoticz version: beta
Contact:

Re: Pass2PHP

Postby tuspam » Friday 28 April 2017 15:53

Egregius wrote:Crap, my site is very outdated :?

This is more recent (but could also use an update) https://github.com/Egregius


Ok but readme almost not exist.

Code: Select all

Installation

    Download the repository and unpack it
    Place the lua script script_device_pass2php.lua in the lua folder of your Domoticz scripts folder
    If you're planning on using pass2php with curl in a PHP enabled webserver place the complete secure folder in your html documents root (ex /var/www).
    Update secure/pass2php with your settings.


"Place the lua script script_device_pass2php.lua in the lua folder of your Domoticz scripts folder"
And what next?

Code: Select all

[email protected]:/home/pi/domoticz/scripts/lua# ls
ee5_base64.lua  JSON.lua  script_device_pass2php.lua


Code: Select all

2017-04-28 17:27:11.428 Error: EventSystem: Lua script /home/pi/domoticz/scripts/lua/script_device_pass2php.lua did not return a commandArray


I need edit this line in script_device_pass2php.lua ?
"os.execute('curl -s -d "c='..c..'" http://127.0.0.1/secure/pass2php.php &')"
in my case ?:
"os.execute( '/home/pi/domoticz/scripts/php/pass2php.php &')"

Can You explain "Update secure/pass2php with your settings" - i don't have idea what to do.

Egregius
Posts: 2171
Joined: Thursday 09 April 2015 12:19
Target OS: Raspberry Pi
Domoticz version: BetaRPi2
Location: Beitem, BE
Contact:

Re: Pass2PHP

Postby Egregius » Saturday 29 April 2017 7:08

Using apcu and curl is way faster than just running thru cli.
I can't remember how I did it with CLI. You have to capture the changed device information.
I think in pass2php $_REQUEST['c'] should be replaced by $argv[0]
And in the lua script: os.execute('php /volume1/web/secure/pass2php.php "'..c..'" &')
But without apcu and a webserver you'll also need to use old versions of the whole system.

DarkAllMan
Posts: 10
Joined: Friday 23 December 2016 10:41
Target OS: Linux
Domoticz version:
Contact:

Re: Pass2PHP

Postby DarkAllMan » Tuesday 16 May 2017 9:32

Hi Egregius,

As I understood you have changed your php2lua script completely and I wanted to change my script to your latest version.
However, the tutorial for this new version is nihil. Can you maybe create a tutorial on how to get your latest version working. Maybe it is a good idea to make a more general script version for people to use, because I see the main scripts are full of your custom functions with your custom IP's and devices.

Also make it clear on what the dependencies are. We need CURL & APCU installed?

For now I have checked your scripts and put everything in place, however, my domoticz log is full of the following error:

Code: Select all

Error: EventSystem: Lua script /home/randall/domoticz/scripts/lua/script_device_pass2php.lua did not return a commandArray


So I need some assistance...

It seems return {} is not valid. I changed it to:

Code: Select all

commandArray = {}
c = ''
for k,v in pairs(devicechanged) do c = c..k.."|"..v.."#" end
os.execute('curl -s -d "c='..c..'" http://###.###.###.###/secure/pass2php.php &')
return commandArray


Now I no longer have the log errors!

Egregius
Posts: 2171
Joined: Thursday 09 April 2015 12:19
Target OS: Raspberry Pi
Domoticz version: BetaRPi2
Location: Beitem, BE
Contact:

Re: Pass2PHP

Postby Egregius » Tuesday 16 May 2017 11:28

Hmmm, I wonder where that code came from. It was different on Github than in my own file.
I agree, documentation is far from complete. Most of the stuff is there for examples, there's no real plug and play description.

Trigun
Posts: 117
Joined: Wednesday 30 November 2016 12:58
Target OS: Raspberry Pi
Domoticz version: 3.5877
Contact:

Re: Pass2PHP

Postby Trigun » Tuesday 16 May 2017 11:33

Hi Egregius, is there a chance you can amend the wiki or create a sort of how to with curl and apcu? Would be great! Since this is a great feature!! Thnx a lot!!


Sent from my iPhone using Tapatalk

Egregius
Posts: 2171
Joined: Thursday 09 April 2015 12:19
Target OS: Raspberry Pi
Domoticz version: BetaRPi2
Location: Beitem, BE
Contact:

Re: Pass2PHP

Postby Egregius » Tuesday 16 May 2017 12:11

there's not much to say about apcu. You install it with apt-get install php-apcu.
Once installed variables can be stored with apcu_store('keyname','value') and retrieved with apcu_fetch('keyname').
ACPU is extreme fast, multiple thousands times faster than the built-in uservariables of Domoticz. It takes less than a microsecond to store/retrieve data :)

There's a brief description at https://github.com/Egregius/LUA-Pass2PH ... stallation
Maybe it's better that an outsider makes documentation of the installation process to add to the wiki? I've done it already so many times that I don't think about it.

DarkAllMan
Posts: 10
Joined: Friday 23 December 2016 10:41
Target OS: Linux
Domoticz version:
Contact:

Re: Pass2PHP

Postby DarkAllMan » Thursday 18 May 2017 9:55

Hi Egregius,
I was wondering about the status of an RGB Dimmer.
It seems that when changing the dimvalue the Dimmer Status is changed to 'Set Level' and not a numeric value. Can you confirm this behaviour?
For RGBW(C/W OR CCT) we would like to store multiple values I guess:
Dim Value (0-100)
RGB Color
Kelvin
Saturation

Egregius
Posts: 2171
Joined: Thursday 09 April 2015 12:19
Target OS: Raspberry Pi
Domoticz version: BetaRPi2
Location: Beitem, BE
Contact:

Re: Pass2PHP

Postby Egregius » Thursday 18 May 2017 16:41

I don't have RGB stuff.
What exactly do you wan't to do with it? Auto set colors depending on statusses?
Best thing to do is view the commands being sent in the domotics web ui (in the developer console of a good browser).
With that json command you could create a new function.

DarkAllMan
Posts: 10
Joined: Friday 23 December 2016 10:41
Target OS: Linux
Domoticz version:
Contact:

Re: Pass2PHP

Postby DarkAllMan » Thursday 18 May 2017 21:41

Egregius wrote:I don't have RGB stuff.
What exactly do you wan't to do with it? Auto set colors depending on statusses?
Best thing to do is view the commands being sent in the domotics web ui (in the developer console of a good browser).
With that json command you could create a new function.


What I want is to store multiple values in APCU ( On/Off, Dimmer Level, Color, Kelvin )
Currently when I dim a RGB ligth to 80% for instance, $status will be the value: "Set Level" It's not really usuable...
How do we provide PHP with more information?

Egregius
Posts: 2171
Joined: Thursday 09 April 2015 12:19
Target OS: Raspberry Pi
Domoticz version: BetaRPi2
Location: Beitem, BE
Contact:

Re: Pass2PHP

Postby Egregius » Thursday 18 May 2017 23:45

Is that data available in the devicechanged table in lua?
What does 'show current states' show under setup->more->events?
You could store it in multiple caches or combine them in a array and serialize that.

If it's not available in the devicechanged table, but it is when you call the json of that device that could also be an option.

Egregius
Posts: 2171
Joined: Thursday 09 April 2015 12:19
Target OS: Raspberry Pi
Domoticz version: BetaRPi2
Location: Beitem, BE
Contact:

Re: Pass2PHP

Postby Egregius » Tuesday 23 May 2017 14:12

Updated github at https://github.com/Egregius/LUA-Pass2PHP-for-Domoticz

Biggest changes:
LUA script calls pass2php for each device in the devicechanged table
In pass2php the explodes aren't needed anymore because of that.
Splitted my cron jobs in different files based on frequency.
In cron180.php lots of weather information and garden irrigation based on passed and future rain predections.
In cron28800.php store battery levels in SQL based on ZWCFG.XML file instead of domoticz api.
A intermediate script to handle the IOS messages, no longer 4 seconds delay in script execution

Code: Select all

shell_exec('/var/www/html/secure/ios.sh "Movement in Hall" > /dev/null 2>/dev/null &');


And many more :lol:


Return to “PHP and all others”

Who is online

Users browsing this forum: No registered users and 1 guest