PHP Custom Floorplan for Domoticz
Moderator: leecollings
- Egregius
- Posts: 2592
- Joined: Thursday 09 April 2015 12:19
- Target OS: Linux
- Domoticz version: v2024.7
- Location: Beitem, BE
- Contact:
PHP Custom Floorplan for Domoticz
edit:
See https://github.com/Egregius/PHP-Custom- ... r-Domoticz and http://egregius.be/tag/domoticz
See https://github.com/Egregius/PHP-Custom- ... r-Domoticz and http://egregius.be/tag/domoticz
Last edited by Egregius on Tuesday 27 December 2016 17:55, edited 9 times in total.
-
- Posts: 890
- Joined: Tuesday 30 September 2014 8:49
- Target OS: Linux
- Domoticz version: beta
- Location: The Netherlands
- Contact:
Re: Floorplan - PHP Skills required
Awesome, thanks for sharing! I think i will have a try at it soon.
Although i'm not really keen about the 'logic' in your script, that is something that i have already handled by Domoticz
I thought this was just a frontend, but it seems to do more than i thought 
And about the cron stuff, why not use something like AJAX / jQuery? With that you can refresh the content of a div without refreshing the whole page.
Although i'm not really keen about the 'logic' in your script, that is something that i have already handled by Domoticz


And about the cron stuff, why not use something like AJAX / jQuery? With that you can refresh the content of a div without refreshing the whole page.
I am not active on this forum anymore.
- Egregius
- Posts: 2592
- Joined: Thursday 09 April 2015 12:19
- Target OS: Linux
- Domoticz version: v2024.7
- Location: Beitem, BE
- Contact:
Re: Floorplan - PHP Skills required
You mean the hw2domoticz script to handle al kinds of stuff?
That's just because I don't have any knowledge of LUA.
Edit: see you're edit now...
The reload of the page only takes 4KB of data, nothing to worry about.
At the bottom of floorplan.php you can easily alter the refresh rate.
That's just because I don't have any knowledge of LUA.
Edit: see you're edit now...
The reload of the page only takes 4KB of data, nothing to worry about.
At the bottom of floorplan.php you can easily alter the refresh rate.
-
- Posts: 58
- Joined: Friday 29 May 2015 7:03
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Floorplan - PHP Skills required
This is really really stunning ! Something I dreamed of, but due to my very limited html/php skills I did not even think of a realisation. I will definitely have a look at it. Perhaps it helps me to dive into php 
Thank you very much for sharing !!!
Cheers
Josh

Thank you very much for sharing !!!
Cheers
Josh
-
- Posts: 58
- Joined: Friday 29 May 2015 7:03
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Floorplan - PHP Skills required
Hm, I just tried your link given in the first post. It says access denied because violation of terms of usage ???
Josh
Josh
- Egregius
- Posts: 2592
- Joined: Thursday 09 April 2015 12:19
- Target OS: Linux
- Domoticz version: v2024.7
- Location: Beitem, BE
- Contact:
Re: Floorplan - PHP Skills required
I just replaced the link, didn't now Google had terms on the URL shortner.
- Egregius
- Posts: 2592
- Joined: Thursday 09 April 2015 12:19
- Target OS: Linux
- Domoticz version: v2024.7
- Location: Beitem, BE
- Contact:
Re: Floorplan - PHP Skills required
I worked hard on the code to have it somewhat more 'shareable', and published to Github: https://github.com/Egregius/PHP-Custom- ... r-Domoticz
Creating the floorplan is now as simple as placing stuf on coördinates:
TypeOfDevice('NameOfDevice',sizeofficon,posistionfromtop,positionfromleft);
In case of a switch (Schakelaar) you can choose the icon by name.
Creating the floorplan is now as simple as placing stuf on coördinates:
TypeOfDevice('NameOfDevice',sizeofficon,posistionfromtop,positionfromleft);
In case of a switch (Schakelaar) you can choose the icon by name.
Code: Select all
Dimmer('Zithoek',48,115,125);
Dimmer('Eettafel',48,115,269);
Schakelaar('Lamp_Bureel','Light', 45, 8,207);
Schakelaar('TV','TV', 48, 3,92);
Schakelaar('Denon','Amp', 48, 6,154);
Schakelaar('Licht_Inkom','Light', 40, 60,360);
Schakelaar('Licht_Voordeur','Light', 40, 60,441);
Schakelaar('Licht_Hall','Light', 42, 416,252);
Schakelaar('Licht_Hall_Auto','Clock', 36, 420,299);
Schakelaar('Licht_Garage','Light', 48, 305,216);
Schakelaar('Licht_Garage_Auto','Clock', 36, 312,180);
Schakelaar('Pluto','Laptop', 30, 365,266);
Schakelaar('Thuis','Home', 48, 268,428);
Schakelaar('Slapen','Sleepy', 48, 335,428);
Schakelaar('Meldingen','Alarm', 48, 5,16);
Schakelaar('Terras','Light', 48, 77,15);
Schakelaar('Brander','Fire', 48, 765,260);
Schakelaar('Licht_Zolder','Light', 48, 705,260);
Schakelaar('Bureel_Tobi','Plug', 36, 780,380);
Smokedetector('SD_Hall_General',36,434,218);
Smokedetector('SD_Zolder_General',36,710,320);
Thermometer('Buiten',110,140,17);
Thermometer('Living',80,141,225);
Thermometer('Badkamer',70,426,435);
Thermometer('Slaapkamer',70,568,435);
Thermometer('Slaapkamer_Tobi',70,458,135);
Thermometer('Slaapkamer_Tobi',70,568,135);
Thermometer('Garage_Temp',60,296,310);
Thermometer('SD_Hall_Temperatuur',60,470,224);
Thermometer('SD_Zolder_Temperatuur',60,707,160);
Setpoint('Living',48,161,172);
Setpoint('Badkamer',40,437,385);
Setpoint('Slaapkamer',40,580,385);
Setpoint('Slaapkamer_Tobi',40,470,90);
Setpoint('Slaapkamer_Tobi',40,580,90);
Radiator('LivingZE',90,160,310);
Radiator('LivingZZ',-90,221,76);
Radiator('BadkamerZ',0,403,349);
if($SwitchThuis == 'Off' || $SwitchSlapen == 'On') {Secured(52,88,250,196);Secured(50,345,129,57);Secured(255,88,316,141);}
if($SwitchThuis == 'Off') {Secured(404,212,129,65);Secured(469,214,45,66);}
if($SwitchPIR_Living != 'Off') Motion(52,88,250,196);
if($SwitchPIR_Inkom != 'Off') Motion(50,345,129,57);
if($SwitchPIR_Garage != 'Off') Motion(255,88,316,141);
if($SwitchPIR_Hall != 'Off') {Motion(404,212,129,65);Motion(469,214,45,66);}
if($SwitchTimeDeurbel>$eendag) Timestamp('Deurbel',-90,17,456);
if($SwitchTimePIR_Garage>$eendag) Timestamp('PIR_Garage',0,255,223);
if($SwitchTimePIR_Living>$eendag) Timestamp('PIR_Living',0,232,223);
if($SwitchTimePIR_Inkom>$eendag) Timestamp('PIR_Inkom',0,40,360);
if($SwitchTimePIR_Hall>$eendag) Timestamp('PIR_Hall',0,403,215);
if($SwitchTimeAchterdeur>$eendag) Timestamp('Achterdeur',-90,280,79);
if($SwitchTimepoort>$eendag) Timestamp('poort',90,315,377);
if($SwitchTimeBrander>$eendag) Timestamp('Brander',0,812,265);
if($SwitchTimeLicht_Zolder>$eendag) Timestamp('Licht_Zolder',0,688,266);
if($SwitchTimeBureel_Tobi>$eendag) Timestamp('Bureel_Tobi',0,782,433);
- Egregius
- Posts: 2592
- Joined: Thursday 09 April 2015 12:19
- Target OS: Linux
- Domoticz version: v2024.7
- Location: Beitem, BE
- Contact:
Re: Floorplan - PHP Skills required
Updated Github with my latest changes...
I know found a way to instantly run the hw2domoticz script upon change of a switch.
I have this in /home/pi/domoticz/scripts/domoticz_main
The advantage of that is that I don't longer need to run the script 15 times a minute.
I also installed Xcache for code and variable caching.
Results of that: 2% CPU usage instead of 10-15%
AND full control of everything that must be done in one php script. No longer need to use blockly etc to activate lights etc.
I know found a way to instantly run the hw2domoticz script upon change of a switch.
I have this in /home/pi/domoticz/scripts/domoticz_main
Code: Select all
!/bin/sh
curl 'http://127.0.0.1:portofwwwserver/secure/hw2domoticz.php'
I also installed Xcache for code and variable caching.
Results of that: 2% CPU usage instead of 10-15%

AND full control of everything that must be done in one php script. No longer need to use blockly etc to activate lights etc.
- Egregius
- Posts: 2592
- Joined: Thursday 09 April 2015 12:19
- Target OS: Linux
- Domoticz version: v2024.7
- Location: Beitem, BE
- Contact:
Re: Floorplan - PHP Skills required
Committed some changes:
- Code optimalisation
- jquery not longer needed, faster and smaller pageload.
- new function: percentdevice($idx, $value) Fill data (like batterylevel) to a dummy percentage device.
- variables in secure/functions.php instead of Domoticz. One call less on every pageload.
- domoticzurl pulls only switches from a room. Get data speed down by 80% in my situation. Data was cluttered with to many devices that aren't needed on the floorplan.
Now I have my floorplan loaded in just 0.1 seconds! That's 0.07 seconds to get the data from Domoticz and 0.03 seconds to parse the PHP.
- Code optimalisation
- jquery not longer needed, faster and smaller pageload.
- new function: percentdevice($idx, $value) Fill data (like batterylevel) to a dummy percentage device.
- variables in secure/functions.php instead of Domoticz. One call less on every pageload.
- domoticzurl pulls only switches from a room. Get data speed down by 80% in my situation. Data was cluttered with to many devices that aren't needed on the floorplan.
Now I have my floorplan loaded in just 0.1 seconds! That's 0.07 seconds to get the data from Domoticz and 0.03 seconds to parse the PHP.
- Egregius
- Posts: 2592
- Joined: Thursday 09 April 2015 12:19
- Target OS: Linux
- Domoticz version: v2024.7
- Location: Beitem, BE
- Contact:
Re: PHP Floorplan
As I finally can dump my Homewizard I moved some code from hw2domoticz.php to cron.php
hw2domoticz.php stays on Github for feature reference
I also managed to have domoticz restarted if there's no good reply on the JSON api
I don't need monit or zabbix or anything else anymore.
hw2domoticz.php stays on Github for feature reference

I also managed to have domoticz restarted if there's no good reply on the JSON api

I don't need monit or zabbix or anything else anymore.
- Egregius
- Posts: 2592
- Joined: Thursday 09 April 2015 12:19
- Target OS: Linux
- Domoticz version: v2024.7
- Location: Beitem, BE
- Contact:
Re: PHP Floorplan
Placed some updates on Github.
Mainly the handling of dimmers is improved (will install 3 more soon
)
Now, besides the slider, also 3 buttons: On, Off and sleep.
Sleep activates a function to dim the lights slowly, like a Philips wakeup light
Mainly the handling of dimmers is improved (will install 3 more soon

Now, besides the slider, also 3 buttons: On, Off and sleep.
Sleep activates a function to dim the lights slowly, like a Philips wakeup light

- Egregius
- Posts: 2592
- Joined: Thursday 09 April 2015 12:19
- Target OS: Linux
- Domoticz version: v2024.7
- Location: Beitem, BE
- Contact:
Re: PHP Floorplan

Added some more switches in the house, still some work to do but almost there

Updated some stuff on Github.
I now wake and put to sleep my iMac from Domoticz.
Kodi is controlled by the cron job, I don't need Kodi hardware anymore. This way Kodi is only monitored when it's really active.
- Egregius
- Posts: 2592
- Joined: Thursday 09 April 2015 12:19
- Target OS: Linux
- Domoticz version: v2024.7
- Location: Beitem, BE
- Contact:
Re: PHP Floorplan
Another update:



Changed the way dimmers and setpoints are controlled. The slider wasn't that interesting for bulbs that mainly need 1 to 10% level.
Added gcal.php which if my implementation of Google Calendar. Everything that can be set on the floorplan can be set with a Google appointment.
Examples: 'Setpoint bathroom 21', 'Dimmer Seat 20', 'Light Kitchen On',...



Changed the way dimmers and setpoints are controlled. The slider wasn't that interesting for bulbs that mainly need 1 to 10% level.
Added gcal.php which if my implementation of Google Calendar. Everything that can be set on the floorplan can be set with a Google appointment.
Examples: 'Setpoint bathroom 21', 'Dimmer Seat 20', 'Light Kitchen On',...
- Egregius
- Posts: 2592
- Joined: Thursday 09 April 2015 12:19
- Target OS: Linux
- Domoticz version: v2024.7
- Location: Beitem, BE
- Contact:
Re: PHP Floorplan, cron script and Google Calendar
Updated the readme at https://github.com/Egregius/PHP-Custom- ... /README.md with more explanation of variables etc.
Included all nescessary files for Google Calendar in the secure/gcal folder.
Included all nescessary files for Google Calendar in the secure/gcal folder.
- Egregius
- Posts: 2592
- Joined: Thursday 09 April 2015 12:19
- Target OS: Linux
- Domoticz version: v2024.7
- Location: Beitem, BE
- Contact:
Re: PHP Floorplan, cron script and Google Calendar
Added some more updates on Github.
ia:
Logfile for every user action taken on floorplan or cron. Easy to use by logwrite($msg) function.
D= time it took to get JSON reply
P= time it took to parse all php code
T= total time of cron script
M= Memory usage
C= CPU usage
E=Errors during this run
TE=Total errors since last reboot (helped me find a type in a switch name today)
Count of errors reported by Domoticz on the JSON API.
Reboot the Rpi at 3AM if memory usage or error count is on warning level.
Reboot during day if memory usage or error count is at panic level.
ia:
Logfile for every user action taken on floorplan or cron. Easy to use by logwrite($msg) function.
D= time it took to get JSON reply
P= time it took to parse all php code
T= total time of cron script
M= Memory usage
C= CPU usage
E=Errors during this run
TE=Total errors since last reboot (helped me find a type in a switch name today)
Code: Select all
2015-12-20 22:39:22.900 Switch 632 kristal On by Guy = OK
2015-12-20 22:46:01.613 Switch 26 brander Off by cron = OK
2015-12-20 22:46:01.642 D0.200|P0.050|T0.250|M14.45|C0.09|E0|TE0|All > 1 actions
Reboot the Rpi at 3AM if memory usage or error count is on warning level.
Reboot during day if memory usage or error count is at panic level.
- Egregius
- Posts: 2592
- Joined: Thursday 09 April 2015 12:19
- Target OS: Linux
- Domoticz version: v2024.7
- Location: Beitem, BE
- Contact:
Re: PHP Floorplan, cron script and Google Calendar
You can run it on any PHP enabled machine that has access to your domoticz.maomanna wrote:Can i run the php floorplan on another machine? Or is running on the rpi the best way?
I run it on the same Rpi2, it's more than fast enough to handle both. I only have about 0,5% cpu usage and 5% memory usage for Domoticz, fail2ban and apache.
-
- Posts: 94
- Joined: Monday 30 November 2015 16:21
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: PHP Floorplan, cron script and Google Calendar
i dony get it, how do i get my devices on the floorplan?
I renamed the devices on your floorplan, but nothing happend.
And how can I set my own floorplan?
and how about a house with 2+ floors? (My house has 3 floors)
I renamed the devices on your floorplan, but nothing happend.
And how can I set my own floorplan?
and how about a house with 2+ floors? (My house has 3 floors)
- Egregius
- Posts: 2592
- Joined: Thursday 09 April 2015 12:19
- Target OS: Linux
- Domoticz version: v2024.7
- Location: Beitem, BE
- Contact:
Re: PHP Floorplan, cron script and Google Calendar
Can you post your code in a code block here please?
And maybe a screenshot of your devices?
The floorplan is in images/Home.png
For easiest implementation your image should be the same size.
My house also has 3 floors, I just draw them under each other.
And maybe a screenshot of your devices?
The floorplan is in images/Home.png
For easiest implementation your image should be the same size.
My house also has 3 floors, I just draw them under each other.
-
- Posts: 94
- Joined: Monday 30 November 2015 16:21
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: PHP Floorplan, cron script and Google Calendar
I only edited
nothing showed up
Code: Select all
Dimmer('Lamp keuken',40,420,130); //kamer Tobi
- Egregius
- Posts: 2592
- Joined: Thursday 09 April 2015 12:19
- Target OS: Linux
- Domoticz version: v2024.7
- Location: Beitem, BE
- Contact:
Re: PHP Floorplan, cron script and Google Calendar
If 'Lamp Keuken' is exactly the name of the switch that's OK.
Did you set all variables in secure/functions.php ?
Did you set all variables in secure/functions.php ?
Who is online
Users browsing this forum: No registered users and 1 guest