Pass2PHP

User avatar
sincze
Posts: 995
Joined: Monday 02 June 2014 22:46
Target OS: Raspberry Pi
Domoticz version: 4.9700
Location: Netherlands
Contact:

Re: Pass2PHP

Post by sincze » Monday 22 January 2018 21:05

Hi Egregius

Quick question. What is the idea about the $check=false. I am unable to figure it out :D

Code: Select all

function sl($name,$level,$type='Dimmer',$check=false){
	$idx=idx($name);

	if($type=='Dimmer'){
		if($level>0&&$level<100)
			$level=$level+1;
	}
	if($idx>0){
		if($check==false)file_get_contents(domoticz.'json.htm?type=command&param=switchlight&idx='.$idx.'&switchcmd=Set%20Level&level='.$level);
		else{
			if(apcu_fetch($name)!=$$level)file_get_contents(domoticz.'json.htm?type=command&param=switchlight&idx='.$idx.'&switchcmd=Set%20Level&level='.$level);
		}
	}else{
		setstatus($name,$level);
	}
}
Currently looking at the idea if I want a dimmer that starts at level 0 and moves incremental up to the requested level (will result into multiple requests but maybe looks nice :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: 2747
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: Beta
Location: Beitem, BE
Contact:

Re: Pass2PHP

Post by Egregius » Monday 22 January 2018 23:37

I use the check option for arrays so I don't send 10 commands when only few need to change.

There's a dimmer wake and sleep script on my github. Search for dimaction in cron60.
The dimaction cache is set with a remote, my floorplan or from Google calendar. A appointment 'wake bedroom' sets the wake mode. Then the dimmer raises 1% every minuge.

ropske
Posts: 315
Joined: Tuesday 12 August 2014 5:37
Target OS: Raspberry Pi
Domoticz version: V3_8394
Location: Rumbeke,Belgium
Contact:

Re: Pass2PHP

Post by ropske » Monday 29 January 2018 20:56

you guys also save your gas and electricity consumption to your mysql database?
Or somewhere else?
Mine is now still saved in domoticz, but i want it somewhere external.
My temperatures are now saved in sql like from Egregius

User avatar
sincze
Posts: 995
Joined: Monday 02 June 2014 22:46
Target OS: Raspberry Pi
Domoticz version: 4.9700
Location: Netherlands
Contact:

Re: Pass2PHP

Post by sincze » Monday 29 January 2018 21:30

ropske wrote:
Monday 29 January 2018 20:56
you guys also save your gas and electricity consumption to your mysql database?
Or somewhere else?
Mine is now still saved in domoticz, but i want it somewhere external.
My temperatures are now saved in sql like from Egregius
Electricity is pushed to influx, just for the graph ;-).
GAS, no :lol:

I keep the values in domoticz ;-) but I have to agree if you want to have nice graphs and comparison over several years you need to store them in a DB.
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: 2747
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: Beta
Location: Beitem, BE
Contact:

Re: Pass2PHP

Post by Egregius » Monday 29 January 2018 21:58

I used already a long time a special page where I just entered my counters manually.
Since Some weeks I have a Pi that with 2 sensors for gas and water. Electricity and solar power is delivered by a Smappee.
Of course all data is stored in a MySQL database :D

ropske
Posts: 315
Joined: Tuesday 12 August 2014 5:37
Target OS: Raspberry Pi
Domoticz version: V3_8394
Location: Rumbeke,Belgium
Contact:

Re: Pass2PHP

Post by ropske » Tuesday 30 January 2018 10:21

Egregius wrote:
Monday 29 January 2018 21:58
I used already a long time a special page where I just entered my counters manually.
Since Some weeks I have a Pi that with 2 sensors for gas and water. Electricity and solar power is delivered by a Smappee.
Of course all data is stored in a MySQL database :D
Can i find this on your GitHub? :D
Very interested :D

ropske
Posts: 315
Joined: Tuesday 12 August 2014 5:37
Target OS: Raspberry Pi
Domoticz version: V3_8394
Location: Rumbeke,Belgium
Contact:

Re: Pass2PHP

Post by ropske » Tuesday 30 January 2018 10:22

sincze wrote:
Monday 29 January 2018 21:30
ropske wrote:
Monday 29 January 2018 20:56
you guys also save your gas and electricity consumption to your mysql database?
Or somewhere else?
Mine is now still saved in domoticz, but i want it somewhere external.
My temperatures are now saved in sql like from Egregius
Electricity is pushed to influx, just for the graph ;-).
GAS, no :lol:

I keep the values in domoticz ;-) but I have to agree if you want to have nice graphs and comparison over several years you need to store them in a DB.
Need to check out the influx 'system'
This also gets the data out of MySQL ? or is it a database system on its own?

Thank you!

User avatar
sincze
Posts: 995
Joined: Monday 02 June 2014 22:46
Target OS: Raspberry Pi
Domoticz version: 4.9700
Location: Netherlands
Contact:

Re: Pass2PHP

Post by sincze » Tuesday 30 January 2018 10:32

it is a time based database on its own. but very fast :D
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: 2747
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: Beta
Location: Beitem, BE
Contact:

Re: Pass2PHP

Post by Egregius » Wednesday 31 January 2018 7:37

ropske wrote:
Tuesday 30 January 2018 10:21
Egregius wrote:
Monday 29 January 2018 21:58
I used already a long time a special page where I just entered my counters manually.
Since Some weeks I have a Pi that with 2 sensors for gas and water. Electricity and solar power is delivered by a Smappee.
Of course all data is stored in a MySQL database :D
Can i find this on your GitHub? :D
Very interested :D
I'll try to add it to Github during the day. Need to check the code if it's good for sharing ;)
It'll come on https://github.com/Egregius/Verbruik-PHP

Edit: it's already online with some text (in Dutch) as explanation. Need to alter the text in the future, now it's just a copy paste of the Redmine wiki I have for the other users that use this tool. We fill it in with 5 families (friends and family), that gives a good result to see if your power consumption is within normal numbers.
Last edited by Egregius on Wednesday 31 January 2018 8:23, edited 1 time in total.

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

Re: Pass2PHP

Post by Egregius » Wednesday 31 January 2018 7:39

sincze wrote:
Tuesday 30 January 2018 10:32
it is a time based database on its own. but very fast :D
MySQL is also very fast. If you have the right indexes and queries.
From one of my tools: 21912 queries executed in 858 milliseconds

ropske
Posts: 315
Joined: Tuesday 12 August 2014 5:37
Target OS: Raspberry Pi
Domoticz version: V3_8394
Location: Rumbeke,Belgium
Contact:

Re: Pass2PHP

Post by ropske » Wednesday 31 January 2018 10:22

Thanks a lot Egregius,

i think (read: i'm very sure) it will be an interesting (long) evening :lol: :lol:

ben53252642
Posts: 536
Joined: Saturday 02 July 2016 5:17
Target OS: Linux
Domoticz version: Beta
Contact:

Re: Pass2PHP

Post by ben53252642 » Wednesday 31 January 2018 13:51

Egregius, do you think it's possible to get PHP integrated as an option in the Domoticz events page?

We would also need the ability to loop the scripts @ x defined time intervals.

I'd love to have all my scripts integrated directly into the Domoticz DB, native PHP integration would mean I can get rid of most of my bash scripts running in screen sessions.

User avatar
sincze
Posts: 995
Joined: Monday 02 June 2014 22:46
Target OS: Raspberry Pi
Domoticz version: 4.9700
Location: Netherlands
Contact:

Re: Pass2PHP

Post by sincze » Wednesday 31 January 2018 14:04

ben53252642 wrote:
Wednesday 31 January 2018 13:51
Egregius, do you think it's possible to get PHP integrated as an option in the Domoticz events page?

We would also need the ability to loop the scripts @ x defined time intervals.

I'd love to have all my scripts integrated directly into the Domoticz DB, native PHP integration would mean I can get rid of most of my bash scripts running in screen sessions.
Interesting question. Sure Egregius will have an answer. As I just use Pass2PHP because it is fast and reliable I am unable to provide an answer. In the beginning I stored everything in Domoticz.db and that would make it slow-down (script running for more than 10 seconds).
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: 2747
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: Beta
Location: Beitem, BE
Contact:

Re: Pass2PHP

Post by Egregius » Wednesday 31 January 2018 15:41

I don't think the developers have interest of doing that. If you watch the forum all that mathers is lua and dzvents. Almost like lot's of domoticz users hate PHP.

Not so difficult to loop the scripts.
In the pass2php file there's code that gets executed every x seconds, every minute, every 2 minutes, every 4 hours, Just like you want.
To be sure the scripts are called, and there wouldn't be the need for a device update I also call the pass2php script from cron.

In crontab:

Code: Select all

* * * * * /var/www/html/secure/cron.sh >/dev/null 2>&1
cron.sh:

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
	lastcron=0
	lastcron=`curl -s --connect-timeout 2 --max-time 15 http://127.0.0.1/secure/cache.php?fetch=cron5`
	now=`date +%s`
	since=$(($now-$lastcron))
	if [ $since -lt 60 ]; then
		curl -s --connect-timeout 2 --max-time 15 "http://127.0.0.1/secure/pass2php.php" > /dev/null 2>/dev/null &
		sleep 9.99
		curl -s --connect-timeout 2 --max-time 15 "http://127.0.0.1/secure/pass2php.php" > /dev/null 2>/dev/null &
		sleep 9.99
		curl -s --connect-timeout 2 --max-time 15 "http://127.0.0.1/secure/pass2php.php" > /dev/null 2>/dev/null &
		sleep 9.99
		curl -s --connect-timeout 2 --max-time 15 "http://127.0.0.1/secure/pass2php.php" > /dev/null 2>/dev/null &
		sleep 9.99
		curl -s --connect-timeout 2 --max-time 15 "http://127.0.0.1/secure/pass2php.php" > /dev/null 2>/dev/null &
		sleep 9.99
		curl -s --connect-timeout 2 --max-time 15 "http://127.0.0.1/secure/pass2php.php" > /dev/null 2>/dev/null &
	else
		shutdown -r now
	fi
else
   sleep 5
   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 5
      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
This script also restarts the domoticz server in case something went wrong.

And this in pass2php.php:

Code: Select all

if(apcu_fetch('cron5')<time-9){
	apcu_store('cron5',time);
	if(apcu_fetch('cron604800')<time-604790){
		apcu_store('cron604800',time);
		include('/var/www/html/secure/_cron604800.php');
	}
	if(apcu_fetch('cron120')<time-118){
		apcu_store('cron120',time);
		include('/var/www/html/secure/_cron120.php');
		include('/var/www/html/secure/gcal/gcal.php');
		if(apcu_fetch('cron28800')<time-27790){
			apcu_store('cron28800',time);
			include('/var/www/html/secure/_cron28800.php');
		}
		if(apcu_fetch('savecache')<time-3600){
			apcu_store('savecache',time);
			include('/var/www/html/secure/savecache.php');
		}
	}
	if(apcu_fetch('cron60')<time-58){
		apcu_store('cron60',time);
		include('/var/www/html/secure/_cron60.php');
		include('/var/www/html/secure/_rolluiken.php');
	}
	include('/var/www/html/secure/_cron5.php');
	include('/var/www/html/secure/_verwarming.php');
}
ben53252642 wrote:
Wednesday 31 January 2018 13:51
I'd love to have all my scripts integrated directly into the Domoticz DB, native PHP integration would mean I can get rid of most of my bash scripts running in screen sessions.
I don't share that opinion. I like to have as much separated as possible. Let domoticz do it's core business, wich is in my case handle all Z-wave devices.
All the rest I like to take out of it and run it separately.
Last edited by Egregius on Wednesday 31 January 2018 15:51, edited 1 time in total.

User avatar
sincze
Posts: 995
Joined: Monday 02 June 2014 22:46
Target OS: Raspberry Pi
Domoticz version: 4.9700
Location: Netherlands
Contact:

Re: Pass2PHP

Post by sincze » Wednesday 31 January 2018 15:50

Egregius wrote:
Wednesday 31 January 2018 15:41
I don't think the developers have interest of doing that. If you watch the forum all that mathers is lua and dzvents. Almost like lot's of domoticz users hate PHP.

Not so difficult to loop the scripts.
In the pass2php file there's code that gets executed every x seconds, every minute, every 2 minutes, every 4 hours, Just like you want.
To be sure the scripts are called, and there wouldn't be the need for a device update I also call the pass2php script from cron.

In crontab:

Code: Select all

* * * * * /var/www/html/secure/cron.sh >/dev/null 2>&1
cron.sh:
A sweet, mine was still in the 1 minute cron mode, more improvements to deploy :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: 2747
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: Beta
Location: Beitem, BE
Contact:

Re: Pass2PHP

Post by Egregius » Wednesday 31 January 2018 15:53

Ha, lol. You could run it as much as your hardware can handle.
I recently lowered it from 5 to 10 seconds. The 5 seconds wasn't really necessary and a bit overkill :D

ropske
Posts: 315
Joined: Tuesday 12 August 2014 5:37
Target OS: Raspberry Pi
Domoticz version: V3_8394
Location: Rumbeke,Belgium
Contact:

Re: Pass2PHP

Post by ropske » Sunday 11 February 2018 19:34

Hi,

if i want to store both data to apcu_store

[Counter] => 36717.778 kWh
[CounterToday] => 14.922 kWh

How do i need todo this?

This is my electricity meter, but the value that is been saved now is the incrementel counter value, so none of both above values.
Thanks :)

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

Re: Pass2PHP

Post by Egregius » Sunday 11 February 2018 20:40

I'm not exactly sure what you mean.
You want both Counter and CounterToday bot none of them?
It all depends on what value is sent by domoticz.
If the value isn't good you could ask domoticz in a cron for a specific device.

ropske
Posts: 315
Joined: Tuesday 12 August 2014 5:37
Target OS: Raspberry Pi
Domoticz version: V3_8394
Location: Rumbeke,Belgium
Contact:

Re: Pass2PHP

Post by ropske » Sunday 11 February 2018 21:20

hi,

yes for example i want to save the [CounterToday] to apcu_store

So the best way is i ask a json from domoticz and decode this and store this data to the apcu?

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

Re: Pass2PHP

Post by Egregius » Sunday 11 February 2018 21:24

CounterToday isn't a device I guess.
So, yes, I would add it to cron60 for example.
Call the json data from domoticz, parse it and store it in cache.

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest