Pass2PHP

Moderator: leecollings

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

Re: Pass2PHP

Post by Egregius »

The code provided in Github is the code that I use.
You should remove stuff that you don't need, like the smappee stuff in cron5 (smappee is a power usage monitor).
The username/password is set in secure/settings.php
Keep in mind that you should secure the secure folder in your webserver so that it only can be accessed from local network.
In Apache this can be done by adding this to the virtual host file:

Code: Select all

<Directory /var/www/html/secure>
	order deny,allow
	allow from 127.0.0.1
	allow from 192.168.2.20
	Deny from All
	AllowOverride None
</Directory>
gimic
Posts: 50
Joined: Thursday 04 January 2018 8:43
Target OS: Linux
Domoticz version: 3.66
Location: Roeselare, Wvl, BE
Contact:

Re: Pass2PHP

Post by gimic »

For the moment it is a test environment, i'ts not open for the internet.

The username/password found in secure/settings.php is 'username1' and 'password1' ? i get acces denied with those credentials. I'm yet to understand everything that is in your files, so i don't know what i can delete and what not.

Tnx for you help
User avatar
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

Post by sincze »

gimic wrote: Thursday 04 January 2018 11: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?
Remove the smappee stuff. If you don't have one you can clear the code ;-)
btw my lg function looks like this, don't know if your looks the same

Code: Select all

function lg($msg){file_get_contents(domoticz.'json.htm?type=command&param=addlogmessage&message='.urlencode('--->> '.$msg));}
Look out for ''domoticz' global variable here. Change it to http://127.0.0.1:8080/

Now just in your cron 60 for example request the idx of your relais.

Code: Select all

$idx=idx('Relais x');
lg($idx.' is the idx');
I can see your log but I'm missing the part where it actually does a switch.

Code: Select all

User: Admin initiated a switch command (84/Relais /On)
The apcu.php is not working for me, apc.php is working, Had to modify the defaults password to enable it.. ;-) in the apc.php file line 42.
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.
gimic
Posts: 50
Joined: Thursday 04 January 2018 8:43
Target OS: Linux
Domoticz version: 3.66
Location: Roeselare, Wvl, BE
Contact:

Re: Pass2PHP

Post by gimic »

For the moment it works! ;-)

got mixed up with wrong directory structure... was really late last night, copyed all files to /var/www/secure and today and last night i was editing them instead of the other files i had copyed in /var/www/html/secure

Stupid me :-/

Tnx for the help
User avatar
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

Post by sincze »

Can happen no worries. Glad to hear you are on pass2php board.
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.
User avatar
Egregius
Posts: 2582
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: v2024.7
Location: Beitem, BE
Contact:

Re: Pass2PHP

Post by Egregius »

That depends on the settings of your webserver.
Some have their files in /var/www, others have them in /var/www/html

Good that you have it working, now you can let your imagination flow and create everything you'd like :D
User avatar
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

Post by sincze »

Sweet. I removed the monitoring by 'monit' of domoticz and only used your script. Pass2PHP has been performing nicely..

Modified the LG function a bit so it can write to domoticz log or to separate file. Works with some variables declared within settings.php. 'logfile' & 'domoticz'.

Code: Select all

function lg($msg)   // Can be used to write loglines to separate file or to internal domoticz log. Check settings.php for value.
{
	if(logwrite)
	{
		$fp=fopen(logfile,"a+"); 		// chmod 0777 pass2php.log
		$time=microtime(true);
		$dFormat="Y-m-d H:i:s";
		$mSecs=$time-floor($time);
		$mSecs=substr(number_format($mSecs,3),1);
		fwrite($fp,sprintf("%s%s %s\n",date($dFormat),$mSecs,$msg));
		fclose($fp);		
	}
	else
	{
		file_get_contents(domoticz.'json.htm?type=command&param=addlogmessage&message='.urlencode('--->> '.$msg));		
	}
}
I'm cleaning up the files now and if I have something interesting I'll put it in here. Like a battery level tester.

Code: Select all

function battery_level()
{

	$json = json_decode(file_get_contents(domoticz.'json.htm?type=devices&order=name'));
	$threshold = 65;
	$hst = "";

	foreach  ($json->result as $r) {
    	    if ($r->BatteryLevel > 0 && $r->BatteryLevel<$threshold) {
        	        $hst = $hst . $r->Name.": ".$r->BatteryLevel."%\n";
        	}
	}

	if ($hst) {
    	    $hst = "Batt Low: ".$hst;
    	    lg('Battery level:'. $hst);
	}
	else lg('Battery levels okay!');
}
I was able to suppress a warning message in my apache log by changing:

Code: Select all

PHP Warning:  fsockopen(): unable to connect to 192.168.2.41:8080 (Connection timed out) in 
THe '@' was added to suppress webserver log messages that the host is down.

Code: Select all

function pingDomain($domain,$port){$file=@fsockopen($domain,$port,$errno,$errstr,1);$status=0;if(!$file)$status=-1;else{fclose($file);$status=1;}return $status;}
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.
User avatar
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

Post by sincze »

The original idea of Pass2PHP is to use devicenames without spaces.
If the following functions are modified you can use names like 'Room Setpoint', "TH7_Temp Buiten'. as well. :D

Code: Select all

function idx($name)
{
    if (strpos($name, " ") !== false) $name=str_replace(" ","_",$name);
    return apcu_fetch('i'.$name);
}

function setidx($name,$value)
{
    if (strpos($name, " ") !== false) $name=str_replace(" ","_",$name);
    apcu_store('i'.$name,$value);
}

function setstatus($name,$value)
{
    if (strpos($name, " ") !== false) $name=str_replace(" ","_",$name);
    apcu_store($name,$value);apcu_store('T'.$name,time());
    //lg('Set Status: '.$name.' with value: '.$value);
}

function settimestamp($name)
{
    if (strpos($name, " ") !== false) $name=str_replace(" ","_",$name);
    apcu_store('T'.$name,time());
}
function status($name)
{
    if (strpos($name, " ") !== false) $name=str_replace(" ","_",$name);
    return apcu_fetch($name);
}

function timestamp($name)
{
    if (strpos($name, " ") !== false) $name=str_replace(" ","_",$name);
    return apcu_fetch('T'.$name);
}
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.
User avatar
Egregius
Posts: 2582
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: v2024.7
Location: Beitem, BE
Contact:

Re: Pass2PHP

Post by Egregius »

Trying HTTP data push with pass2php.
Responsetimes even faster! Needs some time to see if it's stable...

Code: Select all

2018-01-10 11:35:24.310  (ZWAVE) Light/Switch (pirkeuken)
2018-01-10 11:35:24.312  > pirkeuken = On
2018-01-10 11:35:24.312  >  (SWITCH) |  => keuken => On
2018-01-10 11:35:24.312  User: Admin initiated a switch command (11/keuken/On)
2018-01-10 11:35:24.312  OpenZWave: Domoticz has send a Switch command! NodeID: 4 (0x04)
User avatar
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

Post by sincze »

Egregius wrote: Wednesday 10 January 2018 11:37 Trying HTTP data push with pass2php.
Responsetimes even faster! Needs some time to see if it's stable...

Code: Select all

2018-01-10 11:35:24.310  (ZWAVE) Light/Switch (pirkeuken)
2018-01-10 11:35:24.312  > pirkeuken = On
2018-01-10 11:35:24.312  >  (SWITCH) |  => keuken => On
2018-01-10 11:35:24.312  User: Admin initiated a switch command (11/keuken/On)
2018-01-10 11:35:24.312  OpenZWave: Domoticz has send a Switch command! NodeID: 4 (0x04)
Do we need to change things?? to achieve this :D
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.
User avatar
Egregius
Posts: 2582
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: v2024.7
Location: Beitem, BE
Contact:

Re: Pass2PHP

Post by Egregius »

Yes, somethings...
But it's no good. It crashes after a while with a error in the domoticz log:
2018-01-10 12:56:58.757 Error: HttpLink: Error sending data to http with POST!
And then the whole domoticz process and event system hangs.
Will try now to only use it for the motion sensors.
User avatar
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

Post by sincze »

This strange thing happens sometimes:
I open the Door but pass2php reports door closed.
I close the door.. and pass2php reports door open..

Code: Select all

2018-01-12 12:33:50.666 telegram sent to Phone: Voordeur is Geopend
2018-01-12 12:33:52.114 Voordeur: Closed
2018-01-12 12:33:55.371 De voordeur is weer gesloten
2018-01-12 12:34:52.143 Voordeur: Open
2018-01-12 12:35:52.595 Voordeur: Open
The cache reports door open however it is still Closed.
Door Closed.JPG
Door Closed.JPG (19.15 KiB) Viewed 2028 times
Voordeur log.JPG
Voordeur log.JPG (34.16 KiB) Viewed 2028 times
Any ideas??
I have to force a cache refresh ;-) and it is in sync again.

Code: Select all

function force_cache()
{
    $domoticz=json_decode(file_get_contents(domoticz.'json.htm?type=devices&used=true'),true);
    if($domoticz){
        foreach($domoticz['result'] as $dom){
            $name=$dom['Name'];
            if(isset($dom['SwitchType']))$switchtype=$dom['SwitchType'];else $switchtype='none';
            settimestamp($name,strtotime($dom['LastUpdate']));
            setidx($name,$dom['idx']);
            if($dom['Type']=='Temp')setstatus($name,str_replace(' C','',$dom['Data']));
            elseif($dom['TypeImg']=='current')setstatus($name,str_replace(' Watt','',$dom['Data']));
            //elseif($name=='luifel')setstatus($name,str_replace('%','',$dom['Level']));
            elseif($switchtype=='Dimmer'){
                if($dom['Data']=='Off')setstatus($name,'Off');
                else setstatus($name,filter_var($dom['Data'],FILTER_SANITIZE_NUMBER_INT));
            }
            //else setstatus($name,$dom['Data']);
                else { 
                setstatus($name,$dom['Data']);
                lg('Performing setstatus: '.$name.' and data: '.$dom['Data']);
                }   
            }
    lg('End of function force update!');
    }
}
mmm and after an hour I opened the door again... Same thing..

Code: Select all

2018-01-12 14:20:54.578 telegram sent to Phone: Voordeur is Geopend
2018-01-12 14:20:59.086 De voordeur is weer gesloten
2018-01-12 14:21:09.130 Voordeur: Closed
2018-01-12 14:22:09.303 Voordeur: Closed
2018-01-12 14:23:12.035 Voordeur: Open
2018-01-12 14:24:13.058 Voordeur: Open
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.
User avatar
Egregius
Posts: 2582
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: v2024.7
Location: Beitem, BE
Contact:

Re: Pass2PHP

Post by Egregius »

Must be that domoticz is sending those values, no?
I've never seen that on any of my 7 door sensors.
User avatar
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

Post by sincze »

Egregius wrote: Friday 12 January 2018 23:26 Must be that domoticz is sending those values, no?
I've never seen that on any of my 7 door sensors.
it was only 1 doorsensor. (voordeur). I changed the PHP files but the debug-entries did not show up in the logfile. So I thought.. opcache... I searched for "voordeur"

Root cause: several in opcache "Deur Voordeur.php files. Cleared that with a reboot. And it has been running ever since.

hehehe well sometimes it takes a while to figure things out.
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.
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 »

sincze wrote: Saturday 23 December 2017 22:52
Egregius wrote:Yes it does ;)

Same here, everything is done in PHP.
Now at about 300KB code (when just counting the crons and device scripts).
Just added 8 roller shutters, about 400 lines just for the winter programming. The summer programming will even be more...

Next project: water- and gasmeter read out and put it directly to my consumption site (should post that code also in the near future on Github).
Nice I also have summer program for the screens and thermostat code. Data is dumped directly in Influxdb and I have grafana for the nice graphs. As everything is automated I don't have any visual feedback on a tablet or so. Just regular domoticz

Just copied your sw function and modified it so I can use it with the traditional pass2php. The sw( array) is so cool and cleans up a lot of code :) lines. Now looking for more improvements I can copy

Sent from my SM-G925F using Tapatalk

Hi, can you show us some screenshots of how it looks with grafana?
Can you also give me some code/examples please? :D
User avatar
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

Post by sincze »

Egregius wrote: Friday 12 January 2018 23:26 Must be that domoticz is sending those values, no?
I've never seen that on any of my 7 door sensors.
I still have the issue with only 1 door 'Deur Voordeur'. After cache refresh it is okay.
After opening and closing the door we again have an issue.

Deur Voordeur.php

Code: Select all

<?php
	if ($status=='Open')		// ZWAVE DOORSENSOR NOW
	{
			if (cget('var_dark')=='true')
			{
				if (cget('house_mode')=="Away")
				{
					if (status('Lamp (Voordeur)')!='On') sw('Lamp (Voordeur)','On');
					if (status('Lamp LED Hal')=='Off') rgb('Lamp LED Hal','white',100,351,'Colour White');
					if (status('Lamp LED Trap')=='Off') rgb('Lamp LED Trap','white',100,351,'Colour White');	
					if (status('Lamp (Keukentafel)')!='On') sl('Lamp (Keukentafel)',100);
					if (status('Lamp LED Tafel (Woonkamer)')=='Off') rgb('Lamp LED Tafel (Woonkamer)','white',100,351,'Colour White');	
				}
				else
				{
					if (status('Lamp (Voordeur)')!='On') sw('Lamp (Voordeur)','On');
					if (status('Lamp LED Hal')=='Off') rgb('Lamp LED Hal','white',75,351,'Colour White');
				}	
			}
		telegram('Voordeur is Geopend',false,'GSM');
	}
	else lg('De voordeur is weer gesloten');
?>
This shouldn't be the problem right?
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.
User avatar
Egregius
Posts: 2582
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: v2024.7
Location: Beitem, BE
Contact:

Re: Pass2PHP

Post by Egregius »

Put some prints in the lua script and you'll see that it's domoticz
User avatar
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

Post by sincze »

Egregius wrote: Tuesday 16 January 2018 20:30 Put some prints in the lua script and you'll see that it's domoticz

Code: Select all

for d,s in pairs(devicechanged)
do
print ("d="..d)
print ("s="..s)

os.execute('curl -X POST -d "d='..d.."&s="..s..'" http://127.0.0.1/secure2/pass2php.php &')
end
commandArray={}
return commandArray
Resulted into:

Code: Select all

2018-01-16 21:43:15.324 (ZWave) Light/Switch (Deur Voordeur)
2018-01-16 21:43:15.336 LUA: d=Deur Voordeur
2018-01-16 21:43:17.638 (ZWave) Light/Switch (Deur Voordeur)
2018-01-16 21:43:17.662 LUA: d=Deur Voordeur
But these print instructions are probably not good enough to see what happens.
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.
User avatar
Egregius
Posts: 2582
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: v2024.7
Location: Beitem, BE
Contact:

Re: Pass2PHP

Post by Egregius »

Why is the second print not printed?
Can you combine them in one?
User avatar
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

Post by sincze »

Egregius wrote: Tuesday 16 January 2018 22:09 Why is the second print not printed?
Can you combine them in one?
Ok let me check

Well this does happen now:
2018-01-16 22:11:51.685 telegram sent to GSM: Voordeur is Geopend
2018-01-16 22:11:53.540 Voordeur = Closed
2018-01-16 22:13:07.704 Voordeur = Open
zwave-door.JPG
zwave-door.JPG (62.5 KiB) Viewed 1929 times
Domoticz shows:
domoticz-voordeur.JPG
domoticz-voordeur.JPG (16.48 KiB) Viewed 1928 times

Code: Select all


I changed t he name of the sensor back from "Voordeur" to "Deur Voordeur" and opened and closed it 3 times.

2018-01-16 22:26:44.627 LUA: Printing values d=Deur Voordeurs=Open
2018-01-16 22:26:48.500 (ZWave) Light/Switch (Deur Voordeur)
2018-01-16 22:26:48.515 LUA: Printing values d=Deur Voordeurs=Closed
2018-01-16 22:26:56.410 (ZWave) Light/Switch (Deur Voordeur)
2018-01-16 22:26:56.428 LUA: Printing values d=Deur Voordeurs=Closed
2018-01-16 22:26:58.695 (ZWave) Light/Switch (Deur Voordeur)
2018-01-16 22:26:58.721 LUA: Printing values d=Deur Voordeurs=Open
2018-01-16 22:27:01.239 (ZWave) Light/Switch (Deur Voordeur)
2018-01-16 22:27:01.255 LUA: Printing values d=Deur Voordeurs=Closed
2018-01-16 22:27:07.256 (RFXCom) Lighting 2 (Deur (Hal))
load average: 0.53, 0.82, 0.70
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.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest