Page 61 of 76

Re: Pass2PHP

Posted: Saturday 15 February 2020 0:47
by Egregius
I fetch a different site for sunrise/sunset.
Reason for this is that domoticz uses in my opinion the wrong type of sunrise/sunset.
For example today I see in domoticz ☀▲08:01 ▼18:03
While the civil twilight is 7:27 to 18:35.
At the sunset of domoticz it's already completely light outside. I rather use civil twilight so I can see the sunrise/sunset.

Anyway, the code...

from cron3600: Every hour I fetch the sunrise/sunset and store that.

Code: Select all

$sunrise=json_decode(
    file_get_contents(
        'https://api.sunrise-sunset.org/json?lat='
        .$lat.'&lng='
        .$lon.'&date=today&formatted=0'
    ),
    true
);
if (isset($sunrise['results']['civil_twilight_begin'])) {
    if (strtotime($sunrise['results']['civil_twilight_begin'])!=$d['civil_twilight']['s']) {
        store('civil_twilight', strtotime($sunrise['results']['civil_twilight_begin']), basename(__FILE__).':'.__LINE__);
    }
    if (strtotime($sunrise['results']['civil_twilight_end'])!=$d['civil_twilight']['m']) {
        storemode('civil_twilight', strtotime($sunrise['results']['civil_twilight_end']), basename(__FILE__).':'.__LINE__);
    }
}
from cron60: Every minute I check if current time is between sunrise and sunset. If that's the case I store that in the mode of auto.
This is an optional step. You could also just use the if statement everywhere. I just tought it would be easier to just have to if($d['auto']['m']==true) than each time the complete if civil...

Code: Select all

if (TIME>=$d['civil_twilight']['s']&&TIME<=$d['civil_twilight']['m']) {
    if ($d['auto']['m']!=true) {
        storemode('auto', true, basename(__FILE__).':'.__LINE__);
        $d['auto']['m']=true;
    }
} else {
    if ($d['auto']['m']!=false ) {
        storemode('auto', false, basename(__FILE__).':'.__LINE__);
        $d['auto']['m']=false;
    }
}

Re: Pass2PHP

Posted: Saturday 15 February 2020 22:51
by madradrakie
thanks for your answer, clearly.

I still have two problems which i can not figure out.
1. The logging of pass2php to the domoticz.log file is not working. I have used the following script and the light goes on but i see no log record.
I performed all the steps as described in de manual of Trigun.

Code: Select all

<?php
lg('PIRKastenkamer-1test');

if ($status==15466446){
	sw('Studeer-Kast-1','On');

}

?>
2. The _cron60 file is not working because the light is not going off. I executed all the things as decribed in the manual of Trigun but do not get it to work. Also the logging of this file is not working.

Code: Select all

<?php
lg('this is __cron60');
$d=fetchdata();

if ($d['Studeer-Kast-1']['s]=='On'&&$d['PIRStudeerk.']['s']=='Off'&&past('PIRStudeerk.')>60) {
	sw('Studeer-Kast-1', 'Off');
}

?>
i appreciate the help because i think i am very close by using pass2php for some of my blocky scripts.

Re: Pass2PHP

Posted: Sunday 16 February 2020 8:36
by Egregius
Isn't there anything in the error log?
Did you check the lg function for the right path to the domoticz logfile?
Did you give permissions to that logfile so the www-data user may write to it?
Keep in mind that these lines are not shown in the domoticz gui. You have to open the logfile or use tail to follow it. Couple of pages back I gave a tip of multitail to watch mutliple logfiles at once in terminal.
Your second code block contains an error ['s] instead of ['s'].

Pass2PHP

Posted: Sunday 16 February 2020 8:42
by Trigun
Indeed, Is the log file present in the /var/log directory? Also make sure you give the log file the correct rights, I used 777.

If you create a script, use the phpcodechecker website. You can check your code there and see if it has errors. It helped me a lot!


Sent from my iPhone using Tapatalk

Re: Pass2PHP

Posted: Sunday 16 February 2020 19:00
by Joep123
I try to get Pass2PHP working but i get every few seconds an error:

Code: Select all

2020-02-16 18:58:30.925 Error: EventSystem: in Script #7: /home/pi/domoticz/scripts/lua/ee5_base64.lua:560: Neither Lua 5.2 bit32 nor LuaJit bit library found!
How can I solve this (Raspbian Buster, Lua 5.2.4 Copyright (C) 1994-2015 Lua.org, PUC-Rio)

Re: Pass2PHP

Posted: Sunday 16 February 2020 19:26
by Trigun
Sorry mate no experience with buster but looks like your Lua is not installed or the right version


Sent from my iPhone using Tapatalk

Re: Pass2PHP

Posted: Sunday 16 February 2020 20:14
by Egregius
Can you post the lua script that you used?

Re: Pass2PHP

Posted: Sunday 08 March 2020 12:42
by Trigun
Hi Guys,

I have a Duco indoor ventilation system currently running.
But when the outdoor temperature is equal or higher than the indoor temperature, the Duco ventilations system need to swith off.

I've created the following PHP script but it isn't working.

can anybody tell me what I've done wrong?

Code: Select all

<?php

if ($d['Outdoor-Temp&Hum']['s']>=$d['Indoor-Temp&Hum']){
	sw('Duco-afzuiging', 'Off');
}
?>
thanks in advance!

Re: Pass2PHP

Posted: Sunday 08 March 2020 13:11
by Egregius
You're missing a ['s'] in your script to use the status of that device.

Re: Pass2PHP

Posted: Sunday 08 March 2020 13:15
by Trigun
ah right

<?php

if ($d['Outdoor-Temp&Hum']['s']<=$d['Indoor-Temp&Hum']['s']){
sw('Duco-afzuiging', 'Off');
}
?>

Re: Pass2PHP

Posted: Sunday 08 March 2020 18:26
by Egregius
Is it working now?

Re: Pass2PHP

Posted: Sunday 08 March 2020 19:37
by Trigun
I don't think so.
I've tried testing it today with this script.

Code: Select all

<?php

if ($d['Outdoor-Temp&Hum']['s']<=$d['Indoor-Temp&Hum']['s']){
	sw('Duco-afzuiging', 'Off');
}
?>
but it since the temp outdoor is always lower than the temp indoor, it should be switching off.
it doesn't so far.

Re: Pass2PHP

Posted: Sunday 08 March 2020 21:44
by Egregius
I think the ampersand gives the problem.

Re: Pass2PHP

Posted: Wednesday 11 March 2020 14:49
by Trigun
sorry for the late reply, work got me swamped. in the end I got it working. I just did a retype of the code and worked :? guess I am happy it worked so never worked out what the issue was, allthough I guess some typo. :)

but since I've got it working i want to take it to the next step and have a tablet on the wall with the php floorplans.
I was wondering how to setup that part.
Can please let me know how to setup those floorplans? or is it pointed out somewhere?

thanx in advanced!

Re: Pass2PHP

Posted: Wednesday 11 March 2020 15:32
by Egregius
Guess you need to copy/paste some stuff for that.
It drastically changed about a year ago. I moved almost everything to javascript.
Basically floorplan.php loads the floorplanjs.js javascript and the styles/floorplan.php css stylesheet.
In floorplanjs.js in the floorplan function the plan is created. All the stuff above that is for the dynamic updates.
The location/placement of devices is done in the stylesheet.

Think you need to open floorplan.php in a browser, see what happens. Change some things, reload look at the differences. It's not plug-and-play designed :lol:

The idea of a tablet also played in my mind several times but I never did it. I stick to some strategically placed remotes and smartphones.

Re: Pass2PHP

Posted: Wednesday 11 March 2020 15:41
by Trigun
ahh, ok. I guess I stick with the light version than :)

thnx again for your help!

Re: Pass2PHP

Posted: Wednesday 11 March 2020 19:40
by Egregius
Try it, you’ll fall in love with it and never want anything alse anymore.

Re: Pass2PHP

Posted: Thursday 19 March 2020 17:22
by Trigun
Egregius wrote: Sunday 08 March 2020 21:44 I think the ampersand gives the problem.
Unfortunately it is still not workling as it should.

the scripts is as follows:

Code: Select all

if ($d['Outdoor-Temp&Hum']['s']>=$d['Indoor-Temp&Hum']['s']){
	sw('Duco-afzuiging', 'Off');
}
I've put it in the cron60 job to have it checked every minute. but even though it is colder outside than inside de switch gets turned off.
but I only want it to turn off when the temp outside is higher than inside.\

could it be that this is happening because the sensor is both temp as well as humidity?

thnx again!

Re: Pass2PHP

Posted: Friday 20 March 2020 6:47
by Egregius
Add a log line to it:

Code: Select all

lg('Outdoor temperature = '.$d['Outdoor-Temp&Hum']['s']);
I have one smoke detector that suddenly started reporting as temp/hum and have these lines in pass2php for it:

Code: Select all

} elseif (in_array($device, array('badkamer_temp'))) {
    $status=explode(';', $status);
    $status=$status[0];

Re: Pass2PHP

Posted: Friday 20 March 2020 15:48
by Trigun
ok, the log says the following.
i've put a log line for the indoor tem as well and there I see a different output.

anyway since i've activated the script again, my duco gets swithed off

Code: Select all

2020-03-20 15:38:01.979 STATUS ==> Outdoor temperature = 4.3
2020-03-20 15:38:01.979 STATUS ==> Indoor temperature = 20.7 C, 47 %, 1014.6 hPa
2020-03-20 15:38:01.979  (SWITCH)                => Duco-afzuiging => Off ()