Pass2PHP

Moderator: leecollings

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

Re: Pass2PHP

Post by Egregius »

sl = set level.
So that is:
sl('Dimmer', 50);
Trigun
Posts: 390
Joined: Wednesday 30 November 2016 11:58
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.10717
Contact:

Re: Pass2PHP

Post by Trigun »

Nice!! thnx :)
Trigun
Posts: 390
Joined: Wednesday 30 November 2016 11:58
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.10717
Contact:

Re: Pass2PHP

Post 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!
User avatar
sincze
Posts: 1302
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 »

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
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: 2592
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: v2024.7
Location: Beitem, BE
Contact:

Re: Pass2PHP

Post 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 >=
Trigun
Posts: 390
Joined: Wednesday 30 November 2016 11:58
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.10717
Contact:

Re: Pass2PHP

Post 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? :(
User avatar
Egregius
Posts: 2592
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: v2024.7
Location: Beitem, BE
Contact:

Re: Pass2PHP

Post by Egregius »

Look in the database for the exact names and values. Code looks good.
User avatar
Egregius
Posts: 2592
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: v2024.7
Location: Beitem, BE
Contact:

Re: Pass2PHP

Post 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'));
Trigun
Posts: 390
Joined: Wednesday 30 November 2016 11:58
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.10717
Contact:

Re: Pass2PHP

Post 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?
User avatar
Egregius
Posts: 2592
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: v2024.7
Location: Beitem, BE
Contact:

Re: Pass2PHP

Post 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.
Trigun
Posts: 390
Joined: Wednesday 30 November 2016 11:58
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.10717
Contact:

Pass2PHP

Post 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
User avatar
Egregius
Posts: 2592
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: v2024.7
Location: Beitem, BE
Contact:

Re: Pass2PHP

Post by Egregius »

Post the code of pass2php.
Trigun
Posts: 390
Joined: Wednesday 30 November 2016 11:58
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.10717
Contact:

Re: Pass2PHP

Post 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
Trigun
Posts: 390
Joined: Wednesday 30 November 2016 11:58
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.10717
Contact:

Re: Pass2PHP

Post 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 1406 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 1406 times
User avatar
Egregius
Posts: 2592
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: v2024.7
Location: Beitem, BE
Contact:

Re: Pass2PHP

Post 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.
Trigun
Posts: 390
Joined: Wednesday 30 November 2016 11:58
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.10717
Contact:

Re: Pass2PHP

Post 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
User avatar
Egregius
Posts: 2592
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: v2024.7
Location: Beitem, BE
Contact:

Re: Pass2PHP

Post by Egregius »

I didn't wrote the last php version, but the last pass2php version.
That's always on my Github.
Trigun
Posts: 390
Joined: Wednesday 30 November 2016 11:58
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.10717
Contact:

Re: Pass2PHP

Post 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
User avatar
Egregius
Posts: 2592
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: v2024.7
Location: Beitem, BE
Contact:

Re: Pass2PHP

Post by Egregius »

Please read my previous reply carefully.
Trigun
Posts: 390
Joined: Wednesday 30 November 2016 11:58
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.10717
Contact:

Re: Pass2PHP

Post 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
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest