Page 48 of 76
Re: Pass2PHP
Posted: Wednesday 08 May 2019 21:15
by Trigun
Egregius wrote:I'm terrible in writing complete manuals.
$d is the array holding all the information of the system.
So $d['device']['s'] is the status.
t is the timestamp of update.
m is set with the storemode function.
storemode('device', 0); for example.
I use that for dimmers, rollers etc.
0 is mostly automatically, 1 manual. Whatever you want.
That fine, thanks a lot I understanding what you are writing.
I was looking at swithing the light on only when there is movement and when the amount of Lux is below 100. But that can be done with [‘s’]==<100 I guess
Sent from my iPhone using Tapatalk
Re: Pass2PHP
Posted: Thursday 09 May 2019 7:44
by Egregius
Correct.
Example PIR:
Code: Select all
if ($status=="On"&&$d['auto']['s']=='On') {
if ($d['Weg']['s']==0&&$d['inkom']['s']=='Off'&&$d['zon']['s']<100) {
sw('inkom', 'On');
}
}
So, if pir is on and the virtual switch auto is on and we're home and the light of inkom is off and the sun power is less than 100W switch the light on.
A lot of my automation uses the virtual switch auto. That way it's easy to disable all automatic functions when needed, like when painting or cleaning etc.
Re: Pass2PHP
Posted: Thursday 09 May 2019 12:56
by Trigun
Egregius wrote: ↑Thursday 09 May 2019 7:44
Correct.
Example PIR:
Code: Select all
if ($status=="On"&&$d['auto']['s']=='On') {
if ($d['Weg']['s']==0&&$d['inkom']['s']=='Off'&&$d['zon']['s']<100) {
sw('inkom', 'On');
}
}
So, if pir is on and the virtual switch auto is on and we're home and the light of inkom is off and the sun power is less than 100W switch the light on.
A lot of my automation uses the virtual switch auto. That way it's easy to disable all automatic functions when needed, like when painting or cleaning etc.
thats's a smart idea but for the "Bijkeuken" I think this will be sufficient.
Code: Select all
<?php
if($status=='On'&&$d['PIR-Bijkeuken-Lux']['s']<100) {
sw('Bijkeuken','On');
}
Re: Pass2PHP
Posted: Thursday 09 May 2019 13:27
by Egregius
Always include the device that you want to switch, otherwise you'll send unneeded switch commands.
Code: Select all
<?php
if($status=='On'&&$d['Bijkeuken']['s']=='Off'&&$d['PIR-Bijkeuken-Lux']['s']<100) {
sw('Bijkeuken','On');
}
Re: Pass2PHP
Posted: Thursday 09 May 2019 22:05
by Trigun
Egregius wrote: ↑Thursday 09 May 2019 13:27
Always include the device that you want to switch, otherwise you'll send unneeded switch commands.
Code: Select all
<?php
if($status=='On'&&$d['Bijkeuken']['s']=='Off'&&$d['PIR-Bijkeuken-Lux']['s']<100) {
sw('Bijkeuken','On');
}
Great tip! thnx now it goed on at exactly the right moment but is now not going out anymore
so have to look into that
Re: Pass2PHP
Posted: Friday 10 May 2019 7:24
by Egregius
Either your cron isn't running, or there's a fault in it.
Check the code and the logfile.
Split the if statement and ad lg lines to it.
Re: Pass2PHP
Posted: Friday 10 May 2019 7:43
by Egregius
I've put the code that fetches the data into the $d array in a function.
This way you can update the $d array easily:
Re: Pass2PHP
Posted: Friday 10 May 2019 9:26
by Trigun
Egregius wrote: ↑Friday 10 May 2019 7:43
I've put the code that fetches the data into the $d array in a function.
This way you can update the $d array easily:
This is what i've got:
in folder/var/www/html/secure I put _cron60, cron.php, cron.sh
they look like this:
_cron60 for switching the lightBijkeuken and Barageportaal off
Code: Select all
<?php
if ($d['Bijkeuken']['s']=='On'&&$d['PIR-Bijkeuken']['s']=='Off'&&past('PIR-Bijkeuken')>60) {
sw('Bijkeuken', 'Off');
}
if ($d['Garageportaal']['s']=='On'&&$d['PIR-Garageportaal']['s']=='Off'&&past('Garageportaal')>60) {
sw('Garageportaal', 'Off');
}
?>
PIR-Bijkeuken.php
Code: Select all
<?php
if($status=='On'&&$d['PIR-Bijkeuken-Lux']['s']<60) {
sw('Bijkeuken','On');
}
I do still have trouble watching where the lg line are going?
for example: i've put in the _cron60:
lg('_cron60test1');
but never saw any output anywhere, therefore i took it out again
Re: Pass2PHP
Posted: Friday 10 May 2019 11:14
by Egregius
Look at the lg function for the location of the logfile:
Code: Select all
function lg($msg)
{
$fp=fopen('/var/log/domoticz.log', "a+");
$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);
}
Make sure the www-data user has rights to write to the file.
Use tail -f to watch the logfile, these lines or NOT shown in the domoticz GUI logviewer.
Once you have the lg function working it's a lot easier to debug.
Re: Pass2PHP
Posted: Friday 10 May 2019 12:24
by Trigun
Egregius wrote: ↑Friday 10 May 2019 11:14
Look at the lg function for the location of the logfile:
Code: Select all
function lg($msg)
{
$fp=fopen('/var/log/domoticz.log', "a+");
$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);
}
Make sure the www-data user has rights to write to the file.
Use tail -f to watch the logfile, these lines or NOT shown in the domoticz GUI logviewer.
Once you have the lg function working it's a lot easier to debug.
I am using tail -f for monitoring the logfile with a grep on "Garageportaal" and another view for "Bijkeuken"
it might be possible the www-data user does nog have the correct permissions, but how to set these?
I am not sure what to do with the code you posted
Re: Pass2PHP
Posted: Friday 10 May 2019 13:18
by Egregius
Well, you have to verify that /var/log/domoticz.log is the logfile used by domoticz, check /etc/init.d/domoticz.sh for that.
Don't use a grep yet, or are there +100 lines each minute?
easiest way to set permissions is
Re: Pass2PHP
Posted: Friday 10 May 2019 13:28
by sincze
sudo chown www-data:www-data /var/log/domoticz.log
This command hand feeds apache/nginx the Logfile
chmod works 100 percent as well
I believe domoticz.sh is using /var/log/domoticz.txt by default and pass2php
/var/log/domoticz.log
Spot the difference.
Any way you made it a long way. Don't give up
hang on!
At the moment still no access to keyboard. I'll add some proof of that below.
Sent from my ONEPLUS A6003 using Tapatalk
Re: Pass2PHP
Posted: Friday 10 May 2019 13:42
by Egregius
Have a nice vacation!
We're of to The Ardennes
Could be that .txt is the default. Altough that wouldn't be logical to use a .txt as logfile when .log is the default.
Re: Pass2PHP
Posted: Friday 10 May 2019 14:47
by sincze
Muchas Gracias @egregius.
Hope it is dry and a nice Temperature in the Ardennen.
Lots of Belgian people here.
Re: Pass2PHP
Posted: Friday 10 May 2019 16:06
by Trigun
Egregius wrote: ↑Friday 10 May 2019 13:18
Well, you have to verify that /var/log/domoticz.log is the logfile used by domoticz, check /etc/init.d/domoticz.sh for that.
Don't use a grep yet, or are there +100 lines each minute?
easiest way to set permissions is
I think I allready made the right config for that.
- 2019-05-10 15_56_35-log - Domoticz-NEW! - WinSCP.png (2.04 KiB) Viewed 1311 times
monitoring the domoticz.txt looks the same as the domoticz log whereas the domoticz.log is more clearer.
I use the grep to select see what the function does.
I do have a lot of log rules as I poll the amount of Lux ever several minutes.
how do I use the lg function in the _cron or device files to see if its working?
Re: Pass2PHP
Posted: Friday 10 May 2019 16:08
by Trigun
sincze wrote: ↑Friday 10 May 2019 13:28
Wow Sincze that's looking good. a beer must tast extra well over there
I also thought @Egregius could use one
Re: Pass2PHP
Posted: Friday 10 May 2019 16:38
by sincze
Domoticz log as defined in domoticz.sh should have far more entries (log lines) compared to the pass2php generated log file.
My Cron 60 starts with
lg('this is __cron60');
So it shows up in the log Everytime cron60 is called.
Evey minute that is
Sent from my ONEPLUS A6003 using Tapatalk
Re: Pass2PHP
Posted: Friday 10 May 2019 19:13
by Trigun
sincze wrote: ↑Friday 10 May 2019 16:38
Domoticz log as defined in domoticz.sh should have far more entries (log lines) compared to the pass2php generated log file.
My Cron 60 starts with
lg('this is __cron60');
So it shows up in the log Everytime cron60 is called.
Evey minute that is
Sent from my ONEPLUS A6003 using Tapatalk
ok, well this is what I put in the code.
Code: Select all
<?php
lg('this is __cron60');
if ($d['Bijkeuken']['s']=='On'&&$d['PIR-Bijkeuken']['s']=='Off'&&past('PIR-Bijkeuken')>60) {
sw('Bijkeuken', 'Off');
}
if ($d['Garageportaal']['s']=='On'&&$d['PIR-Garageportaal']['s']=='Off'&&past('Garageportaal')>60) {
sw('Garageportaal', 'Off');
}
?>
I am monitoring both domoticz.log as wel as domoticz.txt and the apache log
unfortunately no "this is _cron60". I must be doing something wrong
Re: Pass2PHP
Posted: Friday 10 May 2019 19:28
by Trigun
Trigun wrote: ↑Friday 10 May 2019 19:13
sincze wrote: ↑Friday 10 May 2019 16:38
[/code]
I am monitoring both domoticz.log as wel as domoticz.txt and the apache log
unfortunately no "this is _cron60". I must be doing something wrong
ok, now I know for sure that my cron is not working
because when I manually start the cron.sh script I get the lg line in the domoticz.log
so, back to the cron
Re: Pass2PHP
Posted: Friday 10 May 2019 19:36
by Trigun
Trigun wrote: ↑Friday 10 May 2019 19:28
Trigun wrote: ↑Friday 10 May 2019 19:13
sincze wrote: ↑Friday 10 May 2019 16:38
ok, now I know for sure that my cron is not working
because when I manually start the cron.sh script I get the lg line in the domoticz.log
so, back to the cron
ok, I think I got it.
2 things - the cron.sh was not executable so I did a chmod 777 to cron.sh
and I found out that I used "sudo crontab -e" instead of crontab -e.
now I see the script is running perfectly every minute
just keeping you all informed as it might help others as wel.