Pass2PHP

Moderator: leecollings

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 »

poudenes wrote: Thursday 02 May 2019 16:54
Trigun wrote: Thursday 02 May 2019 16:53
poudenes wrote: Thursday 02 May 2019 15:22


Add this in _fetch and still I get the error :(

GOT IT!!
my database is filled! whoehoo!
I put the config file in the www folder and added require '/var/www/config.php'; and require 'functions.php'; in the _fetch file.

i see the following output for all my devices.

Code: Select all

Notice: Undefined index: Temperature Garage in /var/www/html/secure/functions.php on line 368
PHP Notice:  Undefined index: Tuinsproeier(1hour) in /var/www/html/secure/functions.php on line 368
when I check the database i can see all the devices are added but am sure if the output is correct because of the undefined index?
Where did you add the mysql credentials? so php knows how to connect?
I used the same files which were already present.
I didn't change any credentials.
when you created the database and the uses (both domotica) this was all set.
somewhere in the files these credentials are present.

does this help?
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 »

Function.php line 11/12 or round about there :)
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.
poudenes
Posts: 667
Joined: Wednesday 08 March 2017 9:42
Target OS: Linux
Domoticz version: 3.8993
Location: Amsterdam
Contact:

Re: Pass2PHP

Post by poudenes »

This is what I did not:

Code: Select all

sudo apt-get update
sudo apt-get upgrade
sudo apt-get install apache
sudo apt-get install mysql-server
sudo apt-get install phpmyadmin
sudo mysql_secure_installation 

mysql -u root -p

GRANT ALL PRIVILEGES ON *.* TO 'domotica'@'localhost' IDENTIFIED BY 'domotica';
CREATE DATABASE domotica;
Download the GitHub package zip file. In this zip file you have ‘Create-Update SQL Database.txt'

Code: Select all

mysql -u domotica -p domotica < 'Create-Update SQL Database.txt'
mysql -u root -p

MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| domotica           |
| information_schema |
| mysql              |
| performance_schema |
+--------------------+
4 rows in set (0.00 sec)

sudo ln -s /usr/share/phpmyadmin /var/www/html
Copy all files from the ZIP to:

Code: Select all

/var/www/html/
So lots of files are in /var/www/html/
And lots of files are in /var/www/html/secure

moved config.php to /var/www/html

Edit _fetchdomoticz.php and add 2 lines:

Code: Select all

require '/var/www/html/config.php';
require 'functions.php';


copy from /var/www/html/secure/lua the file

Code: Select all

script_device_pass2php
to

Code: Select all

/domoitcz/script/lua
On webbrowser I give:

Code: Select all

http://192.168.xxx.xx/secure/_fetchdomoticz.php
No errors, open phpmyadmin and see some devices. Not all of them...
Is this normal or does the dB filled in with all the devices from Domoticz?

Can someone post a very simple script to test if it now work as well?
a dummy switch turn on then a bulb must turn on?
- Dummy switch name TEST1
- Bulb name BULB1

Then I can see how script must look like then can try build my own :D
RPi3 B+, Debain Stretch, Domoticz, Homebridge, Dashticz, RFLink, Milight, Z-Wave, Fibaro, Nanoleaf, Nest, Harmony Hub, Now try to understand 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 »

poudenes wrote: Thursday 02 May 2019 17:31 This is what I did not:

Code: Select all

sudo apt-get update
sudo apt-get upgrade
sudo apt-get install apache
sudo apt-get install mysql-server
sudo apt-get install phpmyadmin
sudo mysql_secure_installation 

mysql -u root -p

GRANT ALL PRIVILEGES ON *.* TO 'domotica'@'localhost' IDENTIFIED BY 'domotica';
CREATE DATABASE domotica;
Download the GitHub package zip file. In this zip file you have ‘Create-Update SQL Database.txt'

Code: Select all

mysql -u domotica -p domotica < 'Create-Update SQL Database.txt'
mysql -u root -p

MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| domotica           |
| information_schema |
| mysql              |
| performance_schema |
+--------------------+
4 rows in set (0.00 sec)

sudo ln -s /usr/share/phpmyadmin /var/www/html
Copy all files from the ZIP to:

Code: Select all

/var/www/html/
So lots of files are in /var/www/html/
And lots of files are in /var/www/html/secure

moved config.php to /var/www/html

Edit _fetchdomoticz.php and add 2 lines:

Code: Select all

require '/var/www/html/config.php';
require 'functions.php';


copy from /var/www/html/secure/lua the file

Code: Select all

script_device_pass2php
to

Code: Select all

/domoitcz/script/lua
On webbrowser I give:

Code: Select all

http://192.168.xxx.xx/secure/_fetchdomoticz.php
No errors, open phpmyadmin and see some devices. Not all of them...
Is this normal or does the dB filled in with all the devices from Domoticz?
do you mean dit NOT do or DID do?
because creating the database etc. is crucial
poudenes
Posts: 667
Joined: Wednesday 08 March 2017 9:42
Target OS: Linux
Domoticz version: 3.8993
Location: Amsterdam
Contact:

Re: Pass2PHP

Post by poudenes »

Trigun wrote: Thursday 02 May 2019 17:34 do you mean dit NOT do or DID do?
because creating the database etc. is crucial
dB was created ...

now try to do some scripting and see if it work.

created a file called hall.php

Code: Select all

/**                                                                                                                                                                                          
 * Pass2PHP                                                                                                                                                                                  
 * php version 7.3.3-1                                                                                                                                                                       
 *                                                                                                                                                                                           
 * @category Home_Automation                                                                                                                                                                 
 * @package  Pass2PHP                                                                                                                                                                        
 * @author   Guy Verschuere <[email protected]>                                                                                                                                                
 * @license  GNU GPLv3                                                                                                                                                                       
 * @link     https://egregius.be                                                                                                                                                             
 **/                                                                                                                                                                                         
if ($d['Hall']['s']=='On') {                                                                                              
    sw('Dressoir All', 'On');                                                                                                                                                                
}  
but nothing happen
RPi3 B+, Debain Stretch, Domoticz, Homebridge, Dashticz, RFLink, Milight, Z-Wave, Fibaro, Nanoleaf, Nest, Harmony Hub, Now try to understand 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 »

sincze wrote: Thursday 02 May 2019 17:06 @trigun: excellent job.
Now have a look if all devices (domoticz) idx are there as well.
Hi,

since the database is filled what would be the next step?
creating scripts?
how does it work? I believe the script name and the names used in the scripts itself need to exact as the device names?
or something like that>
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 »

With phpnyadmin

Is devixe
['Hall'] in your database?
Is the idx of the device in your database?

Same goes for the lamp you want to switch. Are idx and name in the database?

Check if you can enable logging.
I use function lg to log everything to my Domoticz log. I use that for debugging :)
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.
poudenes
Posts: 667
Joined: Wednesday 08 March 2017 9:42
Target OS: Linux
Domoticz version: 3.8993
Location: Amsterdam
Contact:

Re: Pass2PHP

Post by poudenes »

sincze wrote:With phpnyadmin

Is devixe
['Hall'] in your database?
Is the idx of the device in your database?

Same goes for the lamp you want to switch. Are idx and name in the database?

Check if you can enable logging.
I use function lg to log everything to my Domoticz log. I use that for debugging :)
I see just 17 devices are add in dB and not all the devices.... What can that be?


Verzonden vanaf mijn iPhone met Tapatalk Pro
RPi3 B+, Debain Stretch, Domoticz, Homebridge, Dashticz, RFLink, Milight, Z-Wave, Fibaro, Nanoleaf, Nest, Harmony Hub, Now try to understand 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 »

poudenes wrote:
sincze wrote:With phpnyadmin

Is devixe
['Hall'] in your database?
Is the idx of the device in your database?

Same goes for the lamp you want to switch. Are idx and name in the database?

Check if you can enable logging.
I use function lg to log everything to my Domoticz log. I use that for debugging :)
I see just 17 devices are add in dB and not all the devices.... What can that be?


Verzonden vanaf mijn iPhone met Tapatalk Pro
Maybe a stupid question but Did you select the correct number of rows to show in the phpmyadmin? I had to look twice to figure that out Image


Sent from my iPhone using Tapatalk
poudenes
Posts: 667
Joined: Wednesday 08 March 2017 9:42
Target OS: Linux
Domoticz version: 3.8993
Location: Amsterdam
Contact:

Re: Pass2PHP

Post by poudenes »

Trigun wrote: Thursday 02 May 2019 19:02
Maybe a stupid question but Did you select the correct number of rows to show in the phpmyadmin? I had to look twice to figure that out Image
Sent from my iPhone using Tapatalk
haha yes I did:

Showing rows 0 - 17 (18 total, Query took 0.0008 seconds.)

Total 18 rows... :(
RPi3 B+, Debain Stretch, Domoticz, Homebridge, Dashticz, RFLink, Milight, Z-Wave, Fibaro, Nanoleaf, Nest, Harmony Hub, Now try to understand pass2php
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 »

poudenes wrote: Thursday 02 May 2019 17:41 dB was created ...

now try to do some scripting and see if it work.

created a file called hall.php

Code: Select all

/**                                                                                                                                                                                          
 * Pass2PHP                                                                                                                                                                                  
 * php version 7.3.3-1                                                                                                                                                                       
 *                                                                                                                                                                                           
 * @category Home_Automation                                                                                                                                                                 
 * @package  Pass2PHP                                                                                                                                                                        
 * @author   Guy Verschuere <[email protected]>                                                                                                                                                
 * @license  GNU GPLv3                                                                                                                                                                       
 * @link     https://egregius.be                                                                                                                                                             
 **/                                                                                                                                                                                         
if ($d['Hall']['s']=='On') {                                                                                              
    sw('Dressoir All', 'On');                                                                                                                                                                
}  
but nothing happen
Keep in mind that the $d array is fetched at the start of the execution. This means it holds the previous status.
Assuming 'Hall' is a motion sensor that would almost certain mean that the status is off at the start.
You have to use this to use the new status, because $status holds the new status.

Code: Select all

                                                                                                                                                                     
if ($status=='On') {                                                                                              
    sw('Dressoir All', 'On');                                                                                                                                                                
}  
Right before the execution of the device script $status is written to the database so the next script will have the new status in the $d array.
poudenes
Posts: 667
Joined: Wednesday 08 March 2017 9:42
Target OS: Linux
Domoticz version: 3.8993
Location: Amsterdam
Contact:

Re: Pass2PHP

Post by poudenes »

Thanks!!! Now I'm still struggling why not all my devices are fetched into db


Verzonden vanaf mijn iPhone met Tapatalk Pro
RPi3 B+, Debain Stretch, Domoticz, Homebridge, Dashticz, RFLink, Milight, Z-Wave, Fibaro, Nanoleaf, Nest, Harmony Hub, Now try to understand pass2php
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 »

poudenes wrote: Thursday 02 May 2019 21:24 Showing rows 0 - 17 (18 total, Query took 0.0008 seconds.)

Total 18 rows... :(
_fetchdomoticz should fetch all used devices from domoticz. There's nothing really special in the script, just some sanetizing of the values (like strippin °C for a thermometer).
The only odd thing in it is the 'achterdeur' part, that's because that's a switch that reports inverted to domoticz.

Just after the store line you could add this to see what happens:

Code: Select all

echo $idx.' '.$name.' = '.$status.'<br>';
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 found out that when I created a test switch and I run the _fetch script, it gets added to the database, great!
but when I delete this switch, its not deleted from the database. is this correct?

also, I am struggling what to do next?
will pass2php also make the response quicker when I simply set a lamp on/off?
or does it only work in case of a Pir --> when pir is On, set lamp X on?

and ofcourse how to implement this?
I need to create scripts? but where do I need to put them?

thnx in advance!
poudenes
Posts: 667
Joined: Wednesday 08 March 2017 9:42
Target OS: Linux
Domoticz version: 3.8993
Location: Amsterdam
Contact:

Re: Pass2PHP

Post by poudenes »

Egregius wrote: Friday 03 May 2019 9:04
poudenes wrote: Thursday 02 May 2019 21:24 Showing rows 0 - 17 (18 total, Query took 0.0008 seconds.)

Total 18 rows... :(
_fetchdomoticz should fetch all used devices from domoticz. There's nothing really special in the script, just some sanetizing of the values (like strippin °C for a thermometer).
The only odd thing in it is the 'achterdeur' part, that's because that's a switch that reports inverted to domoticz.

Just after the store line you could add this to see what happens:

Code: Select all

echo $idx.' '.$name.' = '.$status.'<br>';
When I add this line I don't see anything

This is only thing I have...
Screen Shot 2019-05-03 at 10.23.10.png
RPi3 B+, Debain Stretch, Domoticz, Homebridge, Dashticz, RFLink, Milight, Z-Wave, Fibaro, Nanoleaf, Nest, Harmony Hub, Now try to understand 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 »

poudenes wrote: Friday 03 May 2019 10:20
Egregius wrote: Friday 03 May 2019 9:04
poudenes wrote: Thursday 02 May 2019 21:24 Showing rows 0 - 17 (18 total, Query took 0.0008 seconds.)

Total 18 rows... :(
_fetchdomoticz should fetch all used devices from domoticz. There's nothing really special in the script, just some sanetizing of the values (like strippin °C for a thermometer).
The only odd thing in it is the 'achterdeur' part, that's because that's a switch that reports inverted to domoticz.

Just after the store line you could add this to see what happens:

Code: Select all

echo $idx.' '.$name.' = '.$status.'<br>';
When I add this line I don't see anything

This is only thing I have...

Screen Shot 2019-05-03 at 10.23.10.png
what's the output when you start the script from SSH or from your browser?
poudenes
Posts: 667
Joined: Wednesday 08 March 2017 9:42
Target OS: Linux
Domoticz version: 3.8993
Location: Amsterdam
Contact:

Re: Pass2PHP

Post by poudenes »

from SSH:

Code: Select all

root@raspberrypi:/var/www/html/secure# php _fetchdomoticz.php                                                                                                                                                                                                                                  
PHP Warning:  require(/var/www/html/config.php): failed to open stream: No such file or directory in /var/www/html/secure/_fetchdomoticz.php on line 12
PHP Fatal error:  require(): Failed opening required '/var/www/html/config.php' (include_path='.:/usr/share/php') in /var/www/html/secure/_fetchdomoticz.php on line 12
from browser:

(A white screen)
RPi3 B+, Debain Stretch, Domoticz, Homebridge, Dashticz, RFLink, Milight, Z-Wave, Fibaro, Nanoleaf, Nest, Harmony Hub, Now try to understand pass2php
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 »

Your /var/www/html/config.php doesn't exist or the www-data user doesn't have rights to read it.
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 »

Trigun wrote: Friday 03 May 2019 9:47 hi Guys,

I found out that when I created a test switch and I run the _fetch script, it gets added to the database, great!
but when I delete this switch, its not deleted from the database. is this correct?

also, I am struggling what to do next?
will pass2php also make the response quicker when I simply set a lamp on/off?
or does it only work in case of a Pir --> when pir is On, set lamp X on?

and ofcourse how to implement this?
I need to create scripts? but where do I need to put them?

thnx in advance!
If you use the floorplan to switch the light on the switch will be instantaneous. But that should also be the case when you switch from the Domoticz GUI. If not there's something else wrong.

There are several scripts in place.
Automation is done in the _cron php files. That's stuff that is time related like fetching weather data, controlling blinds, switching lights off...
Device script are placed in secure/pass2php and must have the exact same name (case sensitive) as the device. Those are script that you want to run directly when that device changes.
Take some time to study the files that are in my Github, there's a lot in it. After 4 years I'm still expanding the system and tweaking it so it responds exactly as I want.
It's quite a learning curve, but once you get it it's very easy and flexible to work with.

It is true that devices aren't removed automatically. I don't do that because I have a lot of stuff in the device table that isn't in domoticz.
I don't use the virtual hardware because the device table replaces that.
There is a timestamp stored so it should be easy to sort on that and remove the unused devices.
Once in true production devices don't change that often.
poudenes
Posts: 667
Joined: Wednesday 08 March 2017 9:42
Target OS: Linux
Domoticz version: 3.8993
Location: Amsterdam
Contact:

Re: Pass2PHP

Post by poudenes »

Egregius wrote: Friday 03 May 2019 11:14 Your /var/www/html/config.php doesn't exist or the www-data user doesn't have rights to read it.
correct the path now and get all the devices but with notice:

Code: Select all

Notice: Undefined index: Fibaro Diningroom in /var/www/html/secure/functions.php on line 368
PHP Notice:  Undefined index: Fibaro Bedroom in /var/www/html/secure/functions.php on line 368
All devices give this notice msg
RPi3 B+, Debain Stretch, Domoticz, Homebridge, Dashticz, RFLink, Milight, Z-Wave, Fibaro, Nanoleaf, Nest, Harmony Hub, Now try to understand pass2php
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests