Pass2PHP

Moderator: leecollings

User avatar
sincze
Posts: 1300
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 »

Trigun wrote: Sunday 09 June 2019 16:17 Hi Sincze,

What does it do?
I have a goodwe inverter as well and am curious Image


Sent from my iPhone using Tapatalk
Friend of mine wanted to be added to my Solar Monitoring installation. :lol:

Script does 2 things for me:
1. My friend has a GoodWe inverter and I need the data. So I created this script to scrape the data from the GoodWe server and store it in my Domoticz / Influx / Grafana.
2. As my friend does not have Pass2PHP I added a few functions to the script so he can store the data in his Domoticz as well. (He does not have Pass2PHP).

Now everybody is happy.
I did the same before for SunnyPortal, Omnik and Growatt inverters. :lol:
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.
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 »


[/quote]:[/quote]

Ok that sounds good!! Does it give me more data than when I have a P1 cable attached to my smart meter? Please don’t get me wrong, I’m a big fan


Sent from my iPhone using Tapatalk
User avatar
sincze
Posts: 1300
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 »

It will give you the exact amount of Watts the inverter is producing every minute.

Your P1 only shows
- usage
- inverter - Usage....

So by using P1 you loose precious production data.
On a sunny day You will see return but not the usage!

Still following me on this one?
:)
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.
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 »

sincze wrote:It will give you the exact amount of Watts the inverter is producing every minute.

Your P1 only shows
- usage
- inverter - Usage....

So by using P1 you loose precious production data.
On a sunny day You will see return but not the usage!

Still following me on this one?
:)
Ok, cool! I’ll definitely give it a go to see how it works


Sent from my iPhone using Tapatalk
DarkAllMan
Posts: 52
Joined: Friday 23 December 2016 9:41
Target OS: Linux
Domoticz version:
Contact:

Re: Pass2PHP

Post by DarkAllMan »

Uncaught PDOException: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'dt' in 'field list'

Code: Select all

function fetchdata()
{
    global $db;
    $stmt=$db->query("select n,i,s,t,m,dt,icon from devices;");
    while ($row=$stmt->fetch(PDO::FETCH_ASSOC)) {
        $d[$row['n']] = $row;
    }
    return $d;
}
Ik mis de dt creatie:

Code: Select all

CREATE TABLE IF NOT EXISTS `devices` (
  `n` varchar(50) NOT NULL,
  `i` smallint(6) DEFAULT NULL,
  `s` varchar(500) DEFAULT NULL,
  `t` int(11) DEFAULT NULL,
  `m` varchar(500) DEFAULT NULL,
  PRIMARY KEY (`n`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
User avatar
sincze
Posts: 1300
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 »

It seems the
https://github.com/Egregius/PHP-Floorpl ... tabase.txt is not up to date.

I did not use dt column so did not notice it.
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: 2582
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: v2024.7
Location: Beitem, BE
Contact:

Re: Pass2PHP

Post by Egregius »

True that :o

Updated with

Code: Select all

ALTER TABLE `devices` ADD IF NOT EXISTS `dt` VARCHAR(20) NULL AFTER `m`;
ALTER TABLE `devices` ADD IF NOT EXISTS `icon` VARCHAR(20) NULL AFTER `dt`;
This fields are only used by my ajax based floorplan. If you only use Pass2PHP for automation you don't need them.
Last edited by Egregius on Thursday 11 July 2019 9:57, edited 1 time in total.
DarkAllMan
Posts: 52
Joined: Friday 23 December 2016 9:41
Target OS: Linux
Domoticz version:
Contact:

Re: Pass2PHP

Post by DarkAllMan »

I think the fields should be able to be NULL. Otherwise you get errors on other functions.
The update statement did not work for me, but at least I know the field types.
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 All,

Perhaps someone can help me out with a bit of PHP in combination with Pass2PHP.
I have a weather station which measures also Rain and have automated my garden sprinklers.
Also, I have pass2php setup which works great for PIRS I have ATM.

Now I would like to extend to the next feature but have no idea how to write this in PHP.
I would like to establish that when it has rained in the last 12 hours, the sprinklers should NOT turn on.
If it hasn't rained in the past 12 hours, the sprinklers should turn on.

Within domoticz I have set a time that the sprinklers turn on at 5AM every morning.

Is there a chance someone can help me out?

Much appreciated!

thnx!
User avatar
sincze
Posts: 1300
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 »

If you have a sensor for Rain that has a timestamp when it was the last time it has rained (mm in weatherstation) you could work with that. ? Or you could also just store the timestamp of last rain detection and work with that?

Do you want to keep the connection to 5AM and 12 hours or is the 12 hours leading and we forget about the 5AM ??

This is not for my sprinklers... but for sun-screens.
Rain.png
Rain.png (21.25 KiB) Viewed 14872 times
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.
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 »

[/quote]

Jep I got one. I have a Netatmo weather station which gives me the following.
rain.JPG
rain.JPG (25.72 KiB) Viewed 14871 times
how does that work? can I use it with pass2php?

ideally I would like to stick with the 5am as this is the most ideal time to water the lawn (just before sunrise) :)
the 12 hours might change.

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

Re: Pass2PHP

Post by Egregius »

something like this in a one of the cron files:

Code: Select all

<?php
if (TIME>=strtotime('5:00')&&TIME<strtotime('6:00')&&past('BANO_Outdoor-Rain')>43200&&$d['Rain expected']['s']=='Off'&&past('Water')>43200&&$d['Water']['s']=='Off') {
	sw('Water', 'On');
}
if ($d['Water']['s']=='On'&&past('Water')>900) {
	sw('Water', 'Off');
}
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: Thursday 11 July 2019 6:58 something like this in a one of the cron files:

Code: Select all

<?php
if (TIME>=strtotime('5:00')&&TIME<strtotime('6:00')&&past('BANO_Outdoor-Rain')>43200&&$d['Rain expected']['s']=='Off'&&past('Water')>43200&&$d['Water']['s']=='Off') {
	sw('Water', 'On');
}
if ($d['Water']['s']=='On'&&past('Water')>900) {
	sw('Water', 'Off');
}
I think that's it, Thank you Egregius!
But I have a few questions to understand.
TIME>=strtotime('5:00')&&TIME<strtotime('6:00') --> does this mean: when time is between 5am and 6am? (this is a new function for me, sorry :) )
('BANO_Outdoor-Rain')>43200&&$d['Rain expected']['s']=='Off'&&past('Water')>43200&&$d --> I don't have A "rain expected" sensor but I guess if Bano Rain is >43200 it will work right?

if ($d['Water']['s']=='On'&&past('Water')>900) { --> this means the sprinklers will be on for 15 minutes?
sw('Water', 'Off');
User avatar
Egregius
Posts: 2582
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: v2024.7
Location: Beitem, BE
Contact:

Re: Pass2PHP

Post by Egregius »

I'll split the code in severall lines for you ;)

Code: Select all

<?php
if (TIME>=strtotime('5:00') // If time of day is later than 5am
	&&TIME<strtotime('6:00')// And if time of day is before 6am
	&&past('BANO_Outdoor-Rain')>43200 // And if BANO_Outdoor-Rain hasn't been updated in the last 43200 seconds (12 hours)
	&&$d['Rain expected']['s']=='Off' // And if there's no rain expected
	&&past('Water')>43200 // And the water hasn't been turned on in the last 12 hours
	&&$d['Water']['s']=='Off' // And the water is off
) {
	sw('Water', 'On'); // Switch on the water
}
if ($d['Water']['s']=='On' // If the water is on
	&&past('Water')>900 // And it's on for more than 900 seconds (15 minutes) 
) {
	sw('Water', 'Off'); // Turn off the water
}
User avatar
Egregius
Posts: 2582
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: v2024.7
Location: Beitem, BE
Contact:

Re: Pass2PHP

Post by Egregius »

DarkAllMan wrote: Monday 08 July 2019 13:36 I think the fields should be able to be NULL. Otherwise you get errors on other functions.
The update statement did not work for me, but at least I know the field types.
True, changed my post and the script.
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: Thursday 11 July 2019 9:50 I'll split the code in severall lines for you ;)
Thank You!
I can definitely work with this :)
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: Thursday 11 July 2019 9:50
BTW, I believe the first part is for a PHP file and the second part for a cron file right?
User avatar
Egregius
Posts: 2582
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: v2024.7
Location: Beitem, BE
Contact:

Re: Pass2PHP

Post by Egregius »

No, both go in one of the pass2php cron files.
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: Thursday 11 July 2019 12:24 No, both go in one of the pass2php cron files.
aah ok. so what I did is:

Created a _cron3600.php file which runs every hour in a crontab with:

Code: Select all

if (TIME>=strtotime('5:00')&&TIME<strtotime('6:00')&&past('BANO_Outdoor-Rain')>43200&&past('Tuinsproeiers')>43200&&$d['Tuinsproeiers']['s']=='Off') {
	sw('Tuinsproeiers', 'On');
}
and I added the following to a the _cron60.php file which runs every minute in a crontab:

Code: Select all

if ($d['Tuinsproeiers']['s']=='On'&&past('Tuinsproeiers')>3600) {
	sw('Tuinsproeiers', 'Off');
}
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,

Just received two more Pir's combining those two with pass2php works great!

I was just wondering, I know to to switch a light on and off but how does it work with a dimmer?
for example when I enter the bathroom I want the lights to be at 50% instead of of full on.

I thought this would dol the trick but nothing happens.
I used this for PIR_Badkamer in a php file

Code: Select all

<?php
if($status=='On'&&TIME<strtotime('21:00')) {
sw('Badkamer','50%', true);
}
and this in a cron file.

Code: Select all

if ($d['Badkamer']['s']=='On'&&$d['PIR_Badkamer']['s']=='Off'&&past('Badkamer')>60) {
	sw('Badkamer', 'Off');
}
thanks for your help guys!
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest