Page 29 of 76
Re: Pass2PHP
Posted: Monday 22 January 2018 20:05
by sincze
Hi Egregius
Quick question. What is the idea about the $check=false. I am unable to figure it out
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¶m=switchlight&idx='.$idx.'&switchcmd=Set%20Level&level='.$level);
else{
if(apcu_fetch($name)!=$$level)file_get_contents(domoticz.'json.htm?type=command¶m=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
Re: Pass2PHP
Posted: Monday 22 January 2018 22:37
by Egregius
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.
Re: Pass2PHP
Posted: Monday 29 January 2018 19:56
by ropske
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
Re: Pass2PHP
Posted: Monday 29 January 2018 20:30
by sincze
ropske wrote: ↑Monday 29 January 2018 19: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
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.
Re: Pass2PHP
Posted: Monday 29 January 2018 20:58
by Egregius
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
Re: Pass2PHP
Posted: Tuesday 30 January 2018 9:21
by ropske
Egregius wrote: ↑Monday 29 January 2018 20: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
Can i find this on your GitHub?
Very interested
Re: Pass2PHP
Posted: Tuesday 30 January 2018 9:22
by ropske
sincze wrote: ↑Monday 29 January 2018 20:30
ropske wrote: ↑Monday 29 January 2018 19: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
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!
Re: Pass2PHP
Posted: Tuesday 30 January 2018 9:32
by sincze
it is a time based database on its own. but very fast
Re: Pass2PHP
Posted: Wednesday 31 January 2018 6:37
by Egregius
ropske wrote: ↑Tuesday 30 January 2018 9:21
Egregius wrote: ↑Monday 29 January 2018 20: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
Can i find this on your GitHub?
Very interested
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.
Re: Pass2PHP
Posted: Wednesday 31 January 2018 6:39
by Egregius
sincze wrote: ↑Tuesday 30 January 2018 9:32
it is a time based database on its own. but very fast
MySQL is also very fast. If you have the right indexes and queries.
From one of my tools: 21912 queries executed in 858 milliseconds
Re: Pass2PHP
Posted: Wednesday 31 January 2018 9:22
by ropske
Thanks a lot Egregius,
i think (read: i'm very sure) it will be an interesting (long) evening
Re: Pass2PHP
Posted: Wednesday 31 January 2018 12:51
by ben53252642
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.
Re: Pass2PHP
Posted: Wednesday 31 January 2018 13:04
by sincze
ben53252642 wrote: ↑Wednesday 31 January 2018 12: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).
Re: Pass2PHP
Posted: Wednesday 31 January 2018 14:41
by Egregius
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 12: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.
Re: Pass2PHP
Posted: Wednesday 31 January 2018 14:50
by sincze
Egregius wrote: ↑Wednesday 31 January 2018 14: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
Re: Pass2PHP
Posted: Wednesday 31 January 2018 14:53
by Egregius
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
Re: Pass2PHP
Posted: Sunday 11 February 2018 18:34
by ropske
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
Re: Pass2PHP
Posted: Sunday 11 February 2018 19:40
by Egregius
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.
Re: Pass2PHP
Posted: Sunday 11 February 2018 20:20
by ropske
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?
Re: Pass2PHP
Posted: Sunday 11 February 2018 20:24
by Egregius
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.