Pass2PHP

User avatar
sincze
Posts: 794
Joined: Monday 02 June 2014 22:46
Target OS: Linux
Domoticz version: 3.8153
Location: Netherlands
Contact:

Re: Pass2PHP

Post by sincze » Sunday 31 December 2017 13:37

Mmm I guess the old issue is back of not allowing spaces in a devicename

This does not work:

Code: Select all

status('YeeLight LED (Color)')
After renaming the device this works to execute the script:

Code: Select all

status('YeeLight_LED_(Color)')
I think we need the old string replace routine back :D somewhere,

Code: Select all

	// FAMOUS STRING REPLACEMENT UTILITY
			if (strpos($device, " ") !== false) $device=str_replace(" ","_",$device);
	// ENDOF FAMOUS STRING REPLACEMENT UTILITY
Have to look at the sw function I guess as the light is not switched on.

Code: Select all

<?php
lg('Executing Holiday.php status of yeelight is: '.status('YeeLight_LED_(Color)').' and idx: '.idx('YeeLight_LED_(Color)'));
if($status=='Off'){
	if(status('YeeLight_LED_(Color)')!='Off')sw('YeeLight_LED_(Color)',0,'Off');
}
else if(status('YeeLight_LED_(Color)')!='On')
	{
		lg('I need to turn the light on I think');
		sw('YeeLight_LED_(Color)',0,'On');
	}
Using Pass2php since 2016-12
LAN: RFLink, P1-Port, OTGW, MySensors
USB: RFXCom, ZWave
WIFI: Mi-light Wifi-Bridge, Sonoff, ESP8266, Xiaomi Gateway
Solar: Omnik Inverter, PVOutput
Video: Kodi clients with Harmony HUB
Sensors: You name it I probably got 1.

User avatar
Egregius
Posts: 2513
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: Beta
Location: Beitem, BE
Contact:

Re: Pass2PHP

Post by Egregius » Sunday 31 December 2017 15:43

Yes, I don't use spaces in my devicenames to avoid issues like this.
You could add the strreplace function but I think it would be needed in multiple places to be sure everything is in sync.
Did you already include the _cron604800 script? That one pulls the data from domoticz to fill apcu with current values, idx's etc.

User avatar
sincze
Posts: 794
Joined: Monday 02 June 2014 22:46
Target OS: Linux
Domoticz version: 3.8153
Location: Netherlands
Contact:

Re: Pass2PHP

Post by sincze » Sunday 31 December 2017 16:53

Egregius wrote:
Sunday 31 December 2017 15:43
Yes, I don't use spaces in my devicenames to avoid issues like this.
You could add the strreplace function but I think it would be needed in multiple places to be sure everything is in sync.
Did you already include the _cron604800 script? That one pulls the data from domoticz to fill apcu with current values, idx's etc.
First lights are working :)
Had to put the string replace in several functions indeed. Will Post the results later. Pieuw still a lot of work
What do you think the performance increase will be?
Using Pass2php since 2016-12
LAN: RFLink, P1-Port, OTGW, MySensors
USB: RFXCom, ZWave
WIFI: Mi-light Wifi-Bridge, Sonoff, ESP8266, Xiaomi Gateway
Solar: Omnik Inverter, PVOutput
Video: Kodi clients with Harmony HUB
Sensors: You name it I probably got 1.

User avatar
Egregius
Posts: 2513
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: Beta
Location: Beitem, BE
Contact:

Re: Pass2PHP

Post by Egregius » Monday 01 January 2018 8:32

Don't know, mine is at 6 msec.

User avatar
sincze
Posts: 794
Joined: Monday 02 June 2014 22:46
Target OS: Linux
Domoticz version: 3.8153
Location: Netherlands
Contact:

Re: Pass2PHP

Post by sincze » Monday 01 January 2018 13:03

Egregius wrote:
Monday 01 January 2018 8:32
Don't know, mine is at 6 msec.
Completed the migration. Some typos that resulted in a fatal error. Had to create tons of additional empty php files to store the values.
Still have to figure out an ideal way for debugging. :lol:

Only 1 or 2 functions still need some work.
So I could do some speed comparison. :D , How did you measure

At the moment I can run Pass2PHP in 2 ways:

- the JSON way ( system load average: 0.84, 1.33, 1.44 )

Code: Select all

2018-01-01 11:51:32.728 User: Admin initiated a switch command (1360/Holiday/On)
2018-01-01 11:51:32.789 dzVents: 0. just before cb64json
2018-01-01 11:51:32.791 dzVents: 1. Encoding started at time: 1774.23
2018-01-01 11:51:32.796 dzVents: 2. Encoding finished at time: 1774.24
2018-01-01 11:51:32.811 dzVents: 3. Curl finished at time: 1774.24
2018-01-01 11:51:32.890 User: Admin initiated a switch command (1314/YeeLight LED (Color)/On)
On average 160.

- The Memory way. ( system load average: 1.68, 1.62, 1.49 )

Code: Select all

2018-01-01 12:00:24.740 User: Admin initiated a switch command (1360/Holiday/On)
2018-01-01 12:00:24.874 User: Admin initiated a switch command (1314/YeeLight LED (Color)/On)
On average 134

It's a bit faster indeed. However for some reason a bit more load for the system.


Cache results:

Code: Select all

Hits: 100% 1.586.132 hits / 421 misses
Using Pass2php since 2016-12
LAN: RFLink, P1-Port, OTGW, MySensors
USB: RFXCom, ZWave
WIFI: Mi-light Wifi-Bridge, Sonoff, ESP8266, Xiaomi Gateway
Solar: Omnik Inverter, PVOutput
Video: Kodi clients with Harmony HUB
Sensors: You name it I probably got 1.

User avatar
Egregius
Posts: 2513
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: Beta
Location: Beitem, BE
Contact:

Re: Pass2PHP

Post by Egregius » Monday 01 January 2018 19:41

You only need to create the empty files for devices that you need the status of.
What has dzVents to do with this?
Your load average is very high... Mine is now:

Code: Select all

top - 18:38:48 up 5 days,  8:17,  1 user,  load average: 0.03, 0.07, 0.08
I measure the time between the signal of a pir and the switch command:

Code: Select all

2018-01-01 18:39:12.184  (ZWAVE) Light/Switch (pirinkom)
2018-01-01 18:39:12.190  > pirinkom = On
2018-01-01 18:39:12.190  >  (SWITCH) |  => inkom => On
2018-01-01 18:39:12.190  User: Admin initiated a switch command (141/inkom/On)
2018-01-01 18:39:12.190  OpenZWave: Domoticz has send a Switch command! NodeID: 20 (0x14)

User avatar
sincze
Posts: 794
Joined: Monday 02 June 2014 22:46
Target OS: Linux
Domoticz version: 3.8153
Location: Netherlands
Contact:

Re: Pass2PHP

Post by sincze » Monday 01 January 2018 20:18

Egregius wrote:
Monday 01 January 2018 19:41
You only need to create the empty files for devices that you need the status of.
What has dzVents to do with this?
Your load average is very high... Mine is now:

Code: Select all

top - 18:38:48 up 5 days,  8:17,  1 user,  load average: 0.03, 0.07, 0.08
I measure the time between the signal of a pir and the switch command:

Code: Select all

2018-01-01 18:39:12.184  (ZWAVE) Light/Switch (pirinkom)
2018-01-01 18:39:12.190  > pirinkom = On
2018-01-01 18:39:12.190  >  (SWITCH) |  => inkom => On
2018-01-01 18:39:12.190  User: Admin initiated a switch command (141/inkom/On)
2018-01-01 18:39:12.190  OpenZWave: Domoticz has send a Switch command! NodeID: 20 (0x14)
Check
The dzvents just shows up in the log if I add print instructions to the lua.
Using Pass2php since 2016-12
LAN: RFLink, P1-Port, OTGW, MySensors
USB: RFXCom, ZWave
WIFI: Mi-light Wifi-Bridge, Sonoff, ESP8266, Xiaomi Gateway
Solar: Omnik Inverter, PVOutput
Video: Kodi clients with Harmony HUB
Sensors: You name it I probably got 1.

User avatar
Egregius
Posts: 2513
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: Beta
Location: Beitem, BE
Contact:

Re: Pass2PHP

Post by Egregius » Tuesday 02 January 2018 8:12

Btw, if you have such a hi load average, it must be clearly visible on top wich process is causing this, not?

User avatar
sincze
Posts: 794
Joined: Monday 02 June 2014 22:46
Target OS: Linux
Domoticz version: 3.8153
Location: Netherlands
Contact:

Re: Pass2PHP

Post by sincze » Tuesday 02 January 2018 11:06

You are right the process on top is domoticz. I'll try to make a screen shot. BTW I used to have a file with all kinds of functions that need to be done regularly (check if lights must be off eg)) . Within the _cron files I would call these functions

In your concept you just write down the actions of the function in the specific cron file.
Any specific speed advantages here??
Using Pass2php since 2016-12
LAN: RFLink, P1-Port, OTGW, MySensors
USB: RFXCom, ZWave
WIFI: Mi-light Wifi-Bridge, Sonoff, ESP8266, Xiaomi Gateway
Solar: Omnik Inverter, PVOutput
Video: Kodi clients with Harmony HUB
Sensors: You name it I probably got 1.

User avatar
Egregius
Posts: 2513
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: Beta
Location: Beitem, BE
Contact:

Re: Pass2PHP

Post by Egregius » Tuesday 02 January 2018 18:02

Do I? I include secure/functions.php which holds (almost) all the functions I wrote.

User avatar
sincze
Posts: 794
Joined: Monday 02 June 2014 22:46
Target OS: Linux
Domoticz version: 3.8153
Location: Netherlands
Contact:

Re: Pass2PHP

Post by sincze » Tuesday 02 January 2018 19:01

Egregius wrote:
Tuesday 02 January 2018 18:02
Do I? I include secure/functions.php which holds (almost) all the functions I wrote.
Example I have the following functions.
  • function pingtest() // THis function checks around 15 nodes
    function thermostat() // Function deals with thermostat settings
    function wtw() // Check the Renovent if it has to do something
    function watermeter() // Update the watermeter
    function speedtest() // Perform an internet speedtest
    function zonwering() // Check what to do with the shutters
    function donker() // Check if it is Dark or dark cloud
    function determine_sunrise_sunset()
    function meterstanden() // Send Telegram message on first of the month with all meter values
    function check_for_alarms() // Check to see if there are some kind of alarms
    function check_timers() // Swithc on / Off specific devices on specific time
    function buienradar()
These can be called from a cron60 for example to do the task OR
I can just put the code of the function in the specific cron file. :lol:
Using Pass2php since 2016-12
LAN: RFLink, P1-Port, OTGW, MySensors
USB: RFXCom, ZWave
WIFI: Mi-light Wifi-Bridge, Sonoff, ESP8266, Xiaomi Gateway
Solar: Omnik Inverter, PVOutput
Video: Kodi clients with Harmony HUB
Sensors: You name it I probably got 1.

User avatar
Egregius
Posts: 2513
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: Beta
Location: Beitem, BE
Contact:

Re: Pass2PHP

Post by Egregius » Tuesday 02 January 2018 21:10

Oh, in that way.
Should be similar to what I do.
I mainly have the switch, setlevel etc functions in a seperate file so I can call them from everywhere.

User avatar
sincze
Posts: 794
Joined: Monday 02 June 2014 22:46
Target OS: Linux
Domoticz version: 3.8153
Location: Netherlands
Contact:

Re: Pass2PHP

Post by sincze » Wednesday 03 January 2018 13:56

For some reason pass2php forgets the status of a device, and it does not update it automatically:
Kodi Keuken.JPG
Kodi Keuken.JPG (19.03 KiB) Viewed 292 times
It is a kodi mediaplayer that is always on. There is a keuken.php file as when it is in sync it does work.

I created a debug line in _cron60.php that gives me:
Amp value is: 0.0 status of Keuken kodi is: status of TV Keuken is: Off Woonkamer is: Video

There is a logrotate script at around 00:05 hours, sometimes this initiates a restart of domoticz. (monit says pid changed for process domoticz)
Could this be a cause resulting in variables being reset or filled with nothing?

I modified the daemon args to secure the log in case of a monit restart as your monitor script already takes care of it. Maybe... 2 monitoring services is not the best idea :lol:

Code: Select all

DAEMON_ARGS="$DAEMON_ARGS -log /var/log/domoticz-$NOW.txt"
Using Pass2php since 2016-12
LAN: RFLink, P1-Port, OTGW, MySensors
USB: RFXCom, ZWave
WIFI: Mi-light Wifi-Bridge, Sonoff, ESP8266, Xiaomi Gateway
Solar: Omnik Inverter, PVOutput
Video: Kodi clients with Harmony HUB
Sensors: You name it I probably got 1.

User avatar
Egregius
Posts: 2513
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: Beta
Location: Beitem, BE
Contact:

Re: Pass2PHP

Post by Egregius » Wednesday 03 January 2018 20:43

The cache is only updated when domoticz triggers the device lua script. Must be that domoticz is sending a empty value upon restart.

But, if it's always on, why have it in domoticz tjen?

User avatar
sincze
Posts: 794
Joined: Monday 02 June 2014 22:46
Target OS: Linux
Domoticz version: 3.8153
Location: Netherlands
Contact:

Re: Pass2PHP

Post by sincze » Wednesday 03 January 2018 21:06

Egregius wrote:
Wednesday 03 January 2018 20:43
The cache is only updated when domoticz triggers the device lua script. Must be that domoticz is sending a empty value upon restart.

But, if it's always on, why have it in domoticz tjen?
Another strange thing

Code: Select all

2018-01-03 20:01:48.902 User: Admin initiated a switch command (660/Deur Voordeur/Off)
2018-01-03 20:01:48.904 RFLink Sending: 10;NewKaku;b8ecb6;a;OFF
2018-01-03 20:01:50.564 --->> De voordeur is weer gesloten
2018-01-03 20:02:02.169 --->> This is _Cron60.php a 1 minute CRON
2018-01-03 20:02:09.940 --->> Amp value is: 0.0 status of keuken kodi is: On status of TV Keuken is: On Kodi Woonkamer is: On
2018-01-03 20:02:09.943 --->> deur jablotron: Closed deur voordeur: Closed deur hal: Closed deur (voordeur): Closed
2018-01-03 20:02:10.165 --->> Amp value is: 0.0 status of keuken kodi is: On status of TV Keuken is: On Kodi Woonkamer is: On
2018-01-03 20:02:10.168 --->> deur jablotron: Closed deur voordeur: Closed deur hal: Closed deur (voordeur): Closed
2018-01-03 20:02:39.977 --->> Amp value is: 0.0 status of keuken kodi is: On status of TV Keuken is: On Kodi Woonkamer is: On
2018-01-03 20:02:39.980 --->> deur jablotron: Closed deur voordeur: Closed deur hal: Closed deur (voordeur): Closed
2018-01-03 20:03:02.298 --->> This is _Cron60.php a 1 minute CRON
2018-01-03 20:03:10.110 --->> Amp value is: 0.0 status of keuken kodi is: On status of TV Keuken is: On Kodi Woonkamer is: On
2018-01-03 20:03:10.114 --->> deur jablotron: Closed deur voordeur: Open deur hal: Closed deur (voordeur): Open
2018-01-03 20:03:40.156 --->> Amp value is: 0.0 status of keuken kodi is: On status of TV Keuken is: On Kodi Woonkamer is: On
2018-01-03 20:03:40.162 --->> deur jablotron: Closed deur voordeur: Open deur hal: Closed deur (voordeur): Open
2018-01-03 20:04:05.863 --->> This is _Cron60.php a 1 minute CRON
For some reason it changes the state of the door Voordeur back to open... but i did not touch the door.
And domoticz shows the door is closed.

KI think this issue was due to the following
Device: Deur (Voordeur) is connected RFXCOM (on ground floor)
Device: Deur Voordeur is connected to RFLINK (on 1st floor)
Pass2php.jpg
Pass2php.jpg (91.21 KiB) Viewed 270 times

In the old situation I would link both devices to each other in domoticz. (sub/slave device).
So the (Voordeur) closes... and rf-link does not notify this.. Domoticz will switch the status of the sub/slave device. However this will not trigger an action hence pass2php does not know the status changed of this device.
I now unlinked both devices and have pass2php only look at (Voordeur). That seems to have solved the issue

Code: Select all

2018-01-03 20:21:14.876 --->> Deur voordeur: Open Deur (Voordeur): Closed
2018-01-03 20:21:14.879 --->> deur jablotron: ClosedClosed
Using Pass2php since 2016-12
LAN: RFLink, P1-Port, OTGW, MySensors
USB: RFXCom, ZWave
WIFI: Mi-light Wifi-Bridge, Sonoff, ESP8266, Xiaomi Gateway
Solar: Omnik Inverter, PVOutput
Video: Kodi clients with Harmony HUB
Sensors: You name it I probably got 1.

gimic
Posts: 5
Joined: Thursday 04 January 2018 9:43
Target OS: Linux
Domoticz version: 3.66
Location: Roeselare, Wvl, BE
Contact:

Re: Pass2PHP

Post by gimic » Thursday 04 January 2018 9:48

Hi,
i'm new to pass2PHP and learning. Last night installed the script, i see that de code is working only i can not switch on a light. In the log of the relay i always see that the state gets set to 'off' even if i use the function sw('Relay1','On')

Any advice or manual concerning your script?

Tnx,
Gimic

User avatar
sincze
Posts: 794
Joined: Monday 02 June 2014 22:46
Target OS: Linux
Domoticz version: 3.8153
Location: Netherlands
Contact:

Re: Pass2PHP

Post by sincze » Thursday 04 January 2018 10:24

gimic wrote:
Thursday 04 January 2018 9:48
Hi,
i'm new to pass2PHP and learning. Last night installed the script, i see that de code is working only i can not switch on a light. In the log of the relay i always see that the state gets set to 'off' even if i use the function sw('Relay1','On')

Any advice or manual concerning your script?

Tnx,
Gimic
I would add some debug lines first to the lua and pass2php to see how far the script is.

First question would be. Did you put a relay.php file in the directory? So pass2php remember its state. Can you share the domoticz log where it all happens?
Using Pass2php since 2016-12
LAN: RFLink, P1-Port, OTGW, MySensors
USB: RFXCom, ZWave
WIFI: Mi-light Wifi-Bridge, Sonoff, ESP8266, Xiaomi Gateway
Solar: Omnik Inverter, PVOutput
Video: Kodi clients with Harmony HUB
Sensors: You name it I probably got 1.

User avatar
Egregius
Posts: 2513
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: Beta
Location: Beitem, BE
Contact:

Re: Pass2PHP

Post by Egregius » Thursday 04 January 2018 11:45

Hi Gimic,

welcome as pass2php user :D

To be able to use sw('Relay1','On') you first need to make sure that the IDX's are stored in cache. This is done by the code in _cron604800.php.
You can check all the cache and it's values with the apcu.php page at https://github.com/Egregius/LUA-Pass2PH ... e/apcu.php

gimic
Posts: 5
Joined: Thursday 04 January 2018 9:43
Target OS: Linux
Domoticz version: 3.66
Location: Roeselare, Wvl, BE
Contact:

Re: Pass2PHP

Post by gimic » Thursday 04 January 2018 12:12

i've copied the github so all your variables are in it. Did not change anything to the code (exept a typo in your pass2php.php script (forgot comma before time())
There are error's in the cron because of unknow variable

[Wed Jan 03 23:17:59.026648 2018] [:error] [pid 4864] [client 127.0.0.1:47335] PHP Notice: Undefined variable: smappeeip in /var/www/html/secure/_cron5.php on line 36

when i acces the apcu.php page http://localhost/secure/apcu.php it demands a username/password. What should i enter here?

gimic
Posts: 5
Joined: Thursday 04 January 2018 9:43
Target OS: Linux
Domoticz version: 3.66
Location: Roeselare, Wvl, BE
Contact:

Re: Pass2PHP

Post by gimic » Thursday 04 January 2018 12:28

Domotics log does not show much, only press button 'Input3' then a line with 'relay1' and again 'Input3'

2018-01-03 23:18:01.139 (Test) Lighting 2 (Input3)
2018-01-03 23:18:01.181 (Test) Lighting 2 (Relay1)
2018-01-03 23:18:01.342 (Test) Lighting 2 (Input3)

First input3 is rising trigger, second input3 is dropping trigger

Log of relay1 in domotics shows timestamp:
2018-01-03 23:18:01 Off

so seems that idx is found?

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest