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 »

Yes, if a blockly can be triggered then the device status update will also trigger the lua script to send the status to php.

It should also be possible to let php subscribe to the same MQTT server and receive the messages even faster.
madradrakie
Posts: 64
Joined: Wednesday 11 September 2019 21:24
Target OS: -
Domoticz version:
Contact:

Re: Pass2PHP

Post by madradrakie »

Egregius wrote: Saturday 08 February 2020 16:29 Yes, if a blockly can be triggered then the device status update will also trigger the lua script to send the status to php.

It should also be possible to let php subscribe to the same MQTT server and receive the messages even faster.
well, then i give it a try to install the script. Probably i come back to you for help to let the the php script talk to the mqtt server.
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 can help you with the lua script and pass2php but I have no experience with mqtt. A quick google learned me that it’s possible.
madradrakie
Posts: 64
Joined: Wednesday 11 September 2019 21:24
Target OS: -
Domoticz version:
Contact:

Re: Pass2PHP

Post by madradrakie »

Egregius wrote: Saturday 08 February 2020 19:15 I can help you with the lua script and pass2php but I have no experience with mqtt. A quick google learned me that it’s possible.
oke, first NOOB question probably :-)
I followed all the installation steps but get the following error when i type in the following command in my browser:
http://190.168.2.xxx/secure/_fetchdomoticz.php


Notice: Undefined variable: db in /var/www/html/secure/_fetchdomoticz.php on line 84

Fatal error: Uncaught Error: Call to a member function query() on null in /var/www/html/secure/_fetchdomoticz.php:84 Stack trace: #0 {main} thrown in /var/www/html/secure/_fetchdomoticz.php on line 84
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 »

That page get’s included in my floorplan. If you want to execute it directly in a browser you need the include the functions.php file.
madradrakie
Posts: 64
Joined: Wednesday 11 September 2019 21:24
Target OS: -
Domoticz version:
Contact:

Re: Pass2PHP

Post by madradrakie »

Egregius wrote: Sunday 09 February 2020 10:30 That page get’s included in my floorplan. If you want to execute it directly in a browser you need the include the functions.php file.
I have deleted that part of the code because i am not intend to use the floorplan. I placed all the necessary files at the location as prescribed and added the functions.php and confog.php in the _fetchdomoticz file. I have no more errors anymore. Unfortunatley the database is not filled with the switches of domoticz when i trigger one in domoticz. Could this something to do with the fact that i use apache2 instead of nginx?
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 »

No, I also use apache2 so that's not the problem.

With fetchdomoticz all current states are stored in the database.
Did you place the lua script? That script sents the updates in realtime.
User avatar
McMelloW
Posts: 434
Joined: Monday 20 November 2017 17:01
Target OS: Raspberry Pi / ODroid
Domoticz version: V2024.1
Location: Harderwijk, NL
Contact:

Re: Pass2PHP

Post by McMelloW »

madradrakie wrote: Monday 10 February 2020 7:19 I have deleted that part of the code because i am not intend to use the floorplan. I placed all the necessary files at the location as prescribed and added the functions.php and config.php in the _fetchdomoticz file. I have no more errors anymore. Unfortunatley the database is not filled with the switches of domoticz when i trigger one in domoticz. Could this something to do with the fact that i use apache2 instead of nginx?
I had the same kind of problem. See previous postings in this thread, the answers are very valuable and helpful.
I think I put these lines at the top of _fetchdomoticz.php

Code: Select all

  require '/var/www/config.php'; 
  require '/var/www/html/secure/functions.php';
  
  $db=new PDO("mysql:host=localhost;dbname=$dbname;",$dbuser,$dbpass);
And stripped config.php to this minimal

Code: Select all

<?php
/**
 * Pass2PHP
 * php version 7.3.4-2
 *
 * Example config file
 * Can be placed in /var/www/config.php
 *
 * @category Home_Automation
 * @package  Pass2PHP
 * @author   Guy Verschuere <[email protected]>
 * @license  GNU GPLv3
 * @link     https://egregius.be
 **/
error_reporting(E_ALL);
ini_set("display_errors", "on");
date_default_timezone_set('Europe/Brussels');
if (!defined('TIME')) {
    define('TIME', $_SERVER['REQUEST_TIME']);
}
$log=false;
$page=basename($_SERVER['PHP_SELF']);

$dbname='domotica';
$dbuser='domotica';
$dbpass='domotica';

$domoticzurl='http://127.0.0.1:8080';

After this it did run without any errors. With PhpMyAdmin, I saw all active devises as a row in the Devices table. Correct me if I am wrong.
Greetings McMelloW
madradrakie
Posts: 64
Joined: Wednesday 11 September 2019 21:24
Target OS: -
Domoticz version:
Contact:

Re: Pass2PHP

Post by madradrakie »

McMelloW wrote: Monday 10 February 2020 16:47
madradrakie wrote: Monday 10 February 2020 7:19 I have deleted that part of the code because i am not intend to use the floorplan. I placed all the necessary files at the location as prescribed and added the functions.php and config.php in the _fetchdomoticz file. I have no more errors anymore. Unfortunatley the database is not filled with the switches of domoticz when i trigger one in domoticz. Could this something to do with the fact that i use apache2 instead of nginx?
I had the same kind of problem. See previous postings in this thread, the answers are very valuable and helpful.
I think I put these lines at the top of _fetchdomoticz.php

Code: Select all

  require '/var/www/config.php'; 
  require '/var/www/html/secure/functions.php';
  
  $db=new PDO("mysql:host=localhost;dbname=$dbname;",$dbuser,$dbpass);
And stripped config.php to this minimal

Code: Select all

<?php
/**
 * Pass2PHP
 * php version 7.3.4-2
 *
 * Example config file
 * Can be placed in /var/www/config.php
 *
 * @category Home_Automation
 * @package  Pass2PHP
 * @author   Guy Verschuere <[email protected]>
 * @license  GNU GPLv3
 * @link     https://egregius.be
 **/
error_reporting(E_ALL);
ini_set("display_errors", "on");
date_default_timezone_set('Europe/Brussels');
if (!defined('TIME')) {
    define('TIME', $_SERVER['REQUEST_TIME']);
}
$log=false;
$page=basename($_SERVER['PHP_SELF']);

$dbname='domotica';
$dbuser='domotica';
$dbpass='domotica';

$domoticzurl='http://127.0.0.1:8080';

After this it did run without any errors. With PhpMyAdmin, I saw all active devises as a row in the Devices table. Correct me if I am wrong.
SUPER! it is working. I think i have seen all 60 pages of this forum but did not found this solution. Thanks again for this part! Now lets start with the next step :-)
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 »

Glad to hear it's working also for you. Seems like it's getting easier to get it running.
I enabled wiki's on the gitbub repo.
I'll try to fill them in the next days but feel free to add information there. Advantage will be that it get's centralized in a couple of pages instead of 60 pages here.
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 11 February 2020 7:03
That’s a great idea egregius!!
Is it an idea to select two solutions.
1. A solution with the floorplan
2. A solution without the floorplan

This will give the user a choice.

Both are great options!
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 can only advice to use the floorplan. It's way easier and faster than the default gui. Try imagining what time it costs to scroll to a switch list of 88 switches to find the right one? Add to that that on mobile device you may not hit a dimmer slider and you have a unusable thing.
With the floorplan you see instantly the status of the whole house and you just have to click whatever light you want to switch.
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 »

And it's perfectly ok to leave the files in their place. The html folder only occupies 460KB... So no need to strip out anything.

I'm wondering how far @sincze got with the floorplan? Any screenshots?
madradrakie
Posts: 64
Joined: Wednesday 11 September 2019 21:24
Target OS: -
Domoticz version:
Contact:

Re: Pass2PHP

Post by madradrakie »

oke, still one more problem. My idx are not shown in the table. I tried to figure uit what @sincze did because he had the same problem but have not that many skills to figure it out.
Knipsel.JPG
Knipsel.JPG (51.99 KiB) Viewed 6981 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 »

Idx is only filled while running fetchdomoticz.
That script must also be executed every time you add/change devices in domoticz.
madradrakie
Posts: 64
Joined: Wednesday 11 September 2019 21:24
Target OS: -
Domoticz version:
Contact:

Re: Pass2PHP

Post by madradrakie »

Egregius wrote: Tuesday 11 February 2020 22:29 Idx is only filled while running fetchdomoticz.
That script must also be executed every time you add/change devices in domoticz.
the following thing i did (already multiple times). I opened putty.
Opened the secure map )(cd /var/.. and execeted php _fetchdomoticz.php. I get no errors.
Is this what you mean by execiting _fetchdomoticz.php?
When i look at the database the status of the devices is updated every time so that is not the problem.
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 »

What is the output of the script?

I've made some small changes in it so the output in CLI mode would be nice.
madradrakie
Posts: 64
Joined: Wednesday 11 September 2019 21:24
Target OS: -
Domoticz version:
Contact:

Re: Pass2PHP

Post by madradrakie »

Egregius wrote: Wednesday 12 February 2020 8:32 What is the output of the script?

I've made some small changes in it so the output in CLI mode would be nice.
it is working. I had made a small error in the _fetchdomoticz file....
The first simple php script is also working, lets continue explorering...next step... cron files..
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 »

Great, good job.
You'll find plenty of cron stuf in my _underscore files.
If not, just ask, we'll try to help where possible.
madradrakie
Posts: 64
Joined: Wednesday 11 September 2019 21:24
Target OS: -
Domoticz version:
Contact:

Re: Pass2PHP

Post by madradrakie »

in my domoticz blockies i often use the function of sunset and sunrise as condition to switch a light on or off. Is this also possible in php to make use of this domoticz functionality? Or do i have to make a dummy switch in domoticz for this?
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest