Page 60 of 76
Re: Pass2PHP
Posted: Saturday 08 February 2020 16:29
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.
Re: Pass2PHP
Posted: Saturday 08 February 2020 17:47
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.
Re: Pass2PHP
Posted: Saturday 08 February 2020 19:15
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.
Re: Pass2PHP
Posted: Sunday 09 February 2020 10:16
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
Re: Pass2PHP
Posted: Sunday 09 February 2020 10:30
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.
Re: Pass2PHP
Posted: Monday 10 February 2020 7:19
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?
Re: Pass2PHP
Posted: Monday 10 February 2020 7:59
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.
Re: Pass2PHP
Posted: Monday 10 February 2020 16:47
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.
Re: Pass2PHP
Posted: Monday 10 February 2020 22:50
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

Re: Pass2PHP
Posted: Tuesday 11 February 2020 7:03
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.
Re: Pass2PHP
Posted: Tuesday 11 February 2020 13:06
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!
Re: Pass2PHP
Posted: Tuesday 11 February 2020 17:42
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.
Re: Pass2PHP
Posted: Tuesday 11 February 2020 17:49
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?
Re: Pass2PHP
Posted: Tuesday 11 February 2020 22:18
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 (51.99 KiB) Viewed 6987 times
Re: Pass2PHP
Posted: Tuesday 11 February 2020 22:29
by Egregius
Idx is only filled while running fetchdomoticz.
That script must also be executed every time you add/change devices in domoticz.
Re: Pass2PHP
Posted: Wednesday 12 February 2020 7:09
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.
Re: Pass2PHP
Posted: Wednesday 12 February 2020 8:32
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.
Re: Pass2PHP
Posted: Wednesday 12 February 2020 21:13
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..
Re: Pass2PHP
Posted: Wednesday 12 February 2020 23:13
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.
Re: Pass2PHP
Posted: Friday 14 February 2020 22:07
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?