Page 51 of 76

Re: Pass2PHP

Posted: Saturday 13 July 2019 14:14
by Egregius
sl = set level.
So that is:
sl('Dimmer', 50);

Re: Pass2PHP

Posted: Monday 15 July 2019 11:51
by Trigun
Nice!! thnx :)

Re: Pass2PHP

Posted: Tuesday 23 July 2019 8:51
by Trigun
Hi Guys,

I have a PIR in my bathroom so when I enter the bathroom at night the light is only at 30% instead of the full 100%.
I have the following script to do so:
Device script:

Code: Select all

<?php
if($status=='On'&&TIME>=strtotime('T20:00')){
sl('Badkamer', 30, true);
}
_cron60 script:

Code: Select all

if ($d['Badkamer']['s']>='1'&&$d['Auto']['s']=='Off'&&$d['PIR_Badkamer']['s']=='Off'&&past('Badkamer')>60) {
	sl('Badkamer', 0);
}
for some reason it keeps triggering the set level to 0 which causes my logfile to fill up with these requests.
I have more PIR's in my hous and they don't act this way.
the only difference is that the light in the bathroom is a dimmer and not a switch.

is there a chance you can help me out to prevent this from happening?

thnx!

Re: Pass2PHP

Posted: Tuesday 23 July 2019 17:20
by sincze
quick fix:

if not off after 60 sec... $d['Badkamer']['s']!='Off' and the rest of the requirements is true...
sw('Badkamer', ' Off');

should do the trick

Re: Pass2PHP

Posted: Sunday 28 July 2019 21:32
by Egregius
Your cron60 has an error:

Code: Select all

if ($d['Badkamer']['s']>='1'&&$d['Auto']['s']=='Off'&&$d['PIR_Badkamer']['s']=='Off'&&past('Badkamer')>60) {
	sl('Badkamer', 0);
}
That should be:

Code: Select all

if ($d['Badkamer']['s']>=1&&$d['Auto']['s']=='Off'&&$d['PIR_Badkamer']['s']=='Off'&&past('Badkamer')>60) {
	sl('Badkamer', 0);
}
Remove the quotes around numbers. With quotes numbers are treated as string and can't be evaluated with >=

Re: Pass2PHP

Posted: Saturday 03 August 2019 19:29
by Trigun
Egregius wrote: Sunday 28 July 2019 21:32
I can't seem to get my head around it.

the script is as following:

Code: Select all

<?php
if($status=='On'/*&&TIME<=strtotime('T08:00')&&TIME>=strtotime('T19:00')*/){
sl('Badkamer', 30, true);
}

Elseif($status=='On'&&TIME>=strtotime('T08:00')&&TIME<=strtotime('T19:00')){
sl('Badkamer', 90, true);
}
and the cronjob is as following:

Code: Select all

if ($d['Badkamer']['s']>=1&&$d['PIR_Badkamer']['s']=='Off'&&past('Badkamer')>60) {
	sl('Badkamer', 0);
}
with this setup the light does not automatically go off but is cron job is definitely running, since its working for te rest.

What did I mis? :(

Re: Pass2PHP

Posted: Saturday 03 August 2019 21:20
by Egregius
Look in the database for the exact names and values. Code looks good.

Re: Pass2PHP

Posted: Sunday 04 August 2019 6:36
by Egregius
Or add a lg function just in front of it and keep the logfile open in tail:

Code: Select all

lg('Badkamer='.$d['Badkamer']['s'].', PIR='.$d['PIR_Badkamer']['s'].', past='.past('Badkamer'));

Re: Pass2PHP

Posted: Monday 05 August 2019 23:23
by Trigun
Egregius wrote: Saturday 03 August 2019 21:20 Look in the database for the exact names and values. Code looks good.
ive added the lg function which works good and it gives me the values as expected but the cron doesnt work(for the others it works ok though)

i checked the database, the name is correct but the value in the database says: ”Set Level: 57 %” instead of just 57.
could this be the reason?

Re: Pass2PHP

Posted: Tuesday 06 August 2019 6:16
by Egregius
Then it doesn't give values as expected.
The logfile should be something like this then:
Badkamer = Set Level: 57 %... instead of Badkamer = 57.

You must check what version of Pass2php you're using:
In older versions there was a array in the pass2php file that had to be filled with the names of dimmers.
In the latest versions that's handled in the sql database, the dt field should be 'dimmer'.

For the dimmer devices this is done:

Code: Select all

if ($d[$device]['dt']=='dimmer'||$d[$device]['dt']=='rollers'||$d[$device]['dt']=='luifel') {
    if ($status=='Off'||$status=='Open') {
        $status=0;
    } elseif ($status=='On'||$status=='Closed') {
        $status=100;
    } else {
        $status=filter_var($status, FILTER_SANITIZE_NUMBER_INT);
    }
}
the filter_var strips all characters that aren't numeric.

Pass2PHP

Posted: Tuesday 06 August 2019 7:08
by Trigun

I have php version 7.0.33-0 which is the latest right?
You are right! The log file says: Badkamer = Set Level: 57 %

I really need it to numeric as it is much easier to work with instead of set level etc etc

BTW. If I quote the value like this: >'1'

Code: Select all

 if ($d['Badkamer']['s']>'1'/*&&$d['PIR_Badkamer']['s']=='Off'*/&&past('Badkamer')>60){
	sl('Badkamer', 20);
}
It does workImageImage
What is going on?? Haha

Sent from my iPhone using Tapatalk

Re: Pass2PHP

Posted: Tuesday 06 August 2019 9:47
by Egregius
Post the code of pass2php.

Re: Pass2PHP

Posted: Tuesday 06 August 2019 11:22
by Trigun
Egregius wrote: Tuesday 06 August 2019 9:47 Post the code of pass2php.
the code of the pass2php.php file is as following(You mean this file right?:

Code: Select all

<?php
/**
 * Pass2PHP
 * php version 7.3.3-1
 *
 * @category Home_Automation
 * @package  Pass2PHP
 * @author   Guy Verschuere <[email protected]>
 * @license  GNU GPLv3
 * @link     https://egregius.be
 **/
require '/var/www/config.php';
require 'functions.php';
$device=$_REQUEST['d'];
$status=$_REQUEST['s'];
$username='Domoticz';
if (endswith($device, '_Temperature')) {
    die('Nothing to do');
} elseif (endswith($device, '_Utility')) {
    die('Nothing to do');
}
if (in_array(
    $device, array(
            'PIR-Bijkeuken',
            'zithoek',
            'kamer',
            'tobi',
            'alex',
            'terras',
            'lichtbadkamer',
            'Xvol',
            'Rliving',
            'Rbureel',
            'RkeukenL',
            'RkeukenR',
            'RkamerL',
            'RkamerR',
            'Rtobi',
            'Ralex',
            'luifel'
        )
    )
) {
    if ($status=='Off'||$status=='Open') {
        store($device, 0);
    } elseif ($status=='On'||$status=='Closed') {
        store($device, 100);
    } else {
        $status=filter_var($status, FILTER_SANITIZE_NUMBER_INT);
        store($device, $status);
    }
} elseif (in_array($device, array('badkamer_temp'))) {
    $status=explode(';', $status);
    $status=$status[0];
    store($device, $status);
} elseif ($device=='achterdeur') {
    if ($status=='Open') {
        $status='Closed';
    } else {
        $status='Open';
    }
    store($device, $status);
} else {
    store($device, $status);
}
lgsql('Domoticz',$device,$status);
lg($device.' = '.$status);
@include 'pass2php/'.$device.'.php';
The function: $d['Badkamer']['s']>'1' doesn't work though, it seems that the script skipt it. Unfortunately there is no error in the NginX error.log though

Re: Pass2PHP

Posted: Tuesday 06 August 2019 16:13
by Trigun
I saw that more values within the database are not broken down in separate values.
2019-08-06 16_08_07-192.168.1.200 _ localhost _ domotica _ devices _ phpMyAdmin 4.6.6deb4.png
2019-08-06 16_08_07-192.168.1.200 _ localhost _ domotica _ devices _ phpMyAdmin 4.6.6deb4.png (30.96 KiB) Viewed 1415 times
2019-08-06 16_08_53-192.168.1.200 _ localhost _ domotica _ devices _ phpMyAdmin 4.6.6deb4.png
2019-08-06 16_08_53-192.168.1.200 _ localhost _ domotica _ devices _ phpMyAdmin 4.6.6deb4.png (34.74 KiB) Viewed 1415 times

Re: Pass2PHP

Posted: Wednesday 07 August 2019 6:44
by Egregius
Either you update to the latest pass2php version where devicetypes are stored in the dt column of the database or you fill the array with your own devices:

Code: Select all

$device, array(
            'PIR-Bijkeuken',
            'zithoek',
            'kamer',
            'tobi',
            'alex',
            'terras',
            'lichtbadkamer',
            'Xvol',
            'Rliving',
            'Rbureel',
            'RkeukenL',
            'RkeukenR',
            'RkamerL',
            'RkamerR',
            'Rtobi',
            'Ralex',
            'luifel'
        )
PIR-Bijkeuken shouldn't be in there. That array holds the devices of wich the data has to be filtered to numbers.

For the other devices you'll have to make something like I did for my badkamer_temp:

Code: Select all

elseif (in_array($device, array('badkamer_temp'))) {
    $status=explode(';', $status);
    $status=$status[0];
    store($device, $status);
}
explode splits a string into a array.

Re: Pass2PHP

Posted: Wednesday 07 August 2019 6:51
by Trigun
What is the latest PHP version?
If I do a regular apt-get update and upgrade, it says everything is up to date?


Sent from my iPhone using Tapatalk

Re: Pass2PHP

Posted: Wednesday 07 August 2019 6:57
by Egregius
I didn't wrote the last php version, but the last pass2php version.
That's always on my Github.

Re: Pass2PHP

Posted: Wednesday 07 August 2019 7:21
by Trigun
Egregius wrote:I didn't wrote the last php version, but the last pass2php version.
That's always on my Github.
I only see a reference to php 7.0 based on the pass2php topic. Is there another topic or a link to share?


Sent from my iPhone using Tapatalk

Re: Pass2PHP

Posted: Wednesday 07 August 2019 9:03
by Egregius
Please read my previous reply carefully.

Re: Pass2PHP

Posted: Wednesday 07 August 2019 9:35
by Trigun
Egregius wrote:Please read my previous reply carefully.
Of course I can enter all the device in the array but I would rather have the latest PHP version. I checked your github page Image but couldn’t find the php version


Sent from my iPhone using Tapatalk