PHP Custom Floorplan for Domoticz

Moderator: leecollings

maomanna
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

Post by maomanna »

I fixed the problem.

line 4 of the functions.php says

$domoticzurl='http://ip:port/json.htm?';
After removing json.htm? I see plenty of parameters of the devices in domoticz at test.php

ThenI checked floorplan.php, which said that it could not make connection with domoticz.

I put /json.htm? back and I see all your devices (which are in the github 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: PHP Floorplan, cron script and Google Calendar

Post by Egregius »

Completely redesigned color scheme:

Image

And a complete new view and control of the heating:
Image

Above we see the 5 rooms that are controlled by Domoticz and Danfoss valves.
Rooms in red are hot enough, blue room needs heating.
You instantly see a complete overview, how much difference there is, desired temperature, actual temperature and the setpoint of the valves.
The + sign right of the bathroom indicates that that room needs the most heat.
Valves in such rooms receive by default a setpoint +2°C setting. This way the valves are already open before the temperature drops below the desired setpoint. Before I put this in place I noticed that sometimes the heater burns with all valves closed, this because of the x minutes wake-up interval of the valves.


Example of advanced heating schedule:

Code: Select all

		//Slaapkamer tobi
		$Settobi = 8.0;
		$setpointtobi = cget('setpointtobi');
		if($setpointtobi!=0 && $RTtobi < $eenuur) {cset('setpointtobi',0);$setpointtobi=0;}
		if($setpointtobi!=2) {
			if($Tbuiten<15 && $Sraamtobi=='Closed' && $Sheating=='On' && ($STraamtobi<$tweeuur||$time > $achtavond)) {
				$Settobi = 12.0;
				if (date('W')%2==1) {
						 if (date('N') == 3) { if($time > $achtavond) $Settobi = 16.0;}
					else if (date('N') == 4) { if($time < $zevenochtend || $time > $achtavond) $Settobi = 16.0;}
					else if (date('N') == 5) { if($time < $zevenochtend) $Settobi = 16.0;}
				} else {
						 if (date('N') == 3) { if($time > $achtavond) $Settobi = 16.0;}
					else if (in_array(date('N'),array(4,5,6))) { if($time < $zevenochtend || $time > $achtavond) $Settobi = 16.0;}
					else if (date('N') == 7) { if($time < $zevenochtend) $Settobi = 16.0;}
				}
			}
			$Settobi = number_format($Settobi,1);
			if($Rtobi != $Settobi) {Udevice($RItobi,0,$Settobi,'Rtobi');$Rtobi=$Settobi;cset('temptobi', serialize(array('1' => $Settobi, 't' => $time)));}
		}
		$diftobi = number_format($Ttobi - $Rtobi,1);
Above we see that the default setpoint of Tobi's room is 8°. If several conditions (hour of day, day of week, odd/even weeknumber and window closed) are in place the setpoint is raised to 16°.

The room that needs the most heating is partly choosen by this part:

Code: Select all

$kamers=array('living','badkamer','alex','tobi','kamer');
		$bigdif=100;$rooms = 0;
		foreach($kamers as $kamer) {
			${'koud'.$kamer} = false;
			if(${'dif'.$kamer}<$bigdif) {
				$bigdif = ${'dif'.$kamer};
			}
			if(${'dif'.$kamer} <= $bigdif) $rooms = $rooms + 1;
			if(${'dif'.$kamer} < 0) ${'color'.$kamer} = '#1199FF';
			else if(${'dif'.$kamer} > 0) ${'color'.$kamer} = '#FF5511';
			else ${'color'.$kamer} = '#AAAAAA';
			${'Set'.$kamer} = number_format(${'Set'.$kamer},1);
		}
Also the controlling of the relay for the burner is optimized. Heater is already switched off before the temperature is achieved, this way I optimally make use of the remaining heat in the radiators.
Depending on the biggest difference between actual temperature and setpoint, number of 'cold' rooms, I decide when and how long the heater is active:

Code: Select all

if     ($bigdif <= -0.2 && $Sbrander == "Off" && $STbrander < $time-60 ) {Schakel($SIbrander,'On', 'brander');logwrite('1 Brander On OR -0.2, was '.$Sbrander.' for '.($time - $STbrander).' seconds');}
		else if($bigdif <= -0.1 && $Sbrander == "Off" && $STbrander < $time-290) {Schakel($SIbrander,'On', 'brander');logwrite('2 Brander On OR -0.1, was '.$Sbrander.' for '.($time - $STbrander).' seconds');}
		else if($bigdif <= 0    && $Sbrander == "Off" && $STbrander < $time-550) {Schakel($SIbrander,'On', 'brander');logwrite('3 Brander On OR 0, was '.$Sbrander.' for '.($time - $STbrander).' seconds');}
		else if ($bigdif >= 0.1 && $Sbrander == "On"  && $STbrander < $time-60 ) {Schakel($SIbrander,'Off','brander');logwrite('4 Brander Off AND +0.1, was '.$Sbrander.' for '.($time - $STbrander).' seconds');}
		else if ($bigdif >= 0   && $Sbrander == "On"  && $STbrander < $time-(90 * $rooms * 0.65 )) {Schakel($SIbrander,'Off','brander');logwrite('5 Brander Off AND 0, was '.$Sbrander.' for '.($time - $STbrander).' seconds');}
		else if ($bigdif >= -0.1 && $Sbrander == "On"  && $STbrander < $time-(180* $rooms * 0.65 )) {Schakel($SIbrander,'Off','brander');logwrite('6 Brander Off AND -0.1, was '.$Sbrander.' for '.($time - $STbrander).' seconds');}
		else if ($bigdif >= -0.2 && $Sbrander == "On"  && $STbrander < $time-(360* $rooms * 0.65 )) {Schakel($SIbrander,'Off','brander');logwrite('7 Brander Off AND -0.2, was '.$Sbrander.' for '.($time - $STbrander).' seconds');}

For some reason, since I moved to Syno, I can't access the domoticz db anymore. Therefore I searched a different way to display multiple sensors in one graph:
Image

By calling the history of 3 sensors I was able to accomplish that:

Code: Select all

if($setpoint>0) {
			$temps = json_decode(file_get_contents('http://127.0.0.1:8084/json.htm?type=graph&sensor=temp&idx='.$sensor.'&range=day',false,$ctx),true);
			$setpoints = json_decode(file_get_contents('http://127.0.0.1:8084/json.htm?type=graph&sensor=temp&idx='.$setpoint.'&range=day',false,$ctx),true);
			$radiators = json_decode(file_get_contents('http://127.0.0.1:8084/json.htm?type=graph&sensor=temp&idx='.$radiator.'&range=day',false,$ctx),true);
			$graph = array();
			foreach(array_keys($temps['result']) as $id) {
				array_push($graph, array('Date' => $temps['result'][$id]['d'], 'Radiator' => number_format($radiators['result'][$id]['te'],1), 'Setpoint' => number_format($setpoints['result'][$id]['te'],1), 'Temperature' => number_format($temps['result'][$id]['te'],1)));
			}
		}
		
User avatar
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

Post by Egregius »

Updated the telegram bot script.
Now it can sent text, photo's and videos.
New option is also to disable notification, nice to have some history without being bothered with sound for each text.

Usage from bash:

Code: Select all

/usr/bin/php /wolume1/web/secure/telegram.php text 'Test notification'
/usr/bin/php /wolume1/web/secure/telegram.php photo /volume1/files/PiCam1/snapshot.jpg
/usr/bin/php /wolume1/web/secure/telegram.php video /volume1/files/PiCam1/video.mp4
curl -s --connect-timeout 2 --max-time 5 --data-urlencode "text=Domoticz Status OK" --data "silent=true" https://127.0.0.1/secure/telegram.php
The PHP function also received the silent option.
Usage from php:

Code: Select all

telegram('message without notification');
telegram('message with notification', false);
User avatar
blackdog65
Posts: 311
Joined: Tuesday 17 June 2014 18:25
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Norfolk, UK
Contact:

Re: PHP Floorplan, cron script and Google Calendar

Post by blackdog65 »

Hi Egregius,
I've just installed this and I'm getting the same blank screen.
I tried the test.php and it listed all my devices, so I assume apache, php etc are working.
In my download, the index.php is a blank file. Is this correct?
Also, if I change "Schakelaar" to "Switch" in floorplan.php will it work (if I get it working)

Thanks,

Sean
CubieTruck Master
RasPi slaves
Aeon Labs Z-Stick, multi sensor
Fibaro Dimmers, relays, Universal sensors
EQ3 MAX!
TKB Sockets
RFXCOM
LightwaveRF sockets, switches, relays, doorbell
MySensors
ESPEasy ESP8266-12E
User avatar
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

Post by Egregius »

Think you'll need to add code in blocks to see where it goes wrong.
Are the display_errors there? (On vacation, can't see much)

Yes, index.php is empty file. Just a small extra security thing.

"Schakelaar" is the name of the function in functions.php
You can change it, but not to Switch because thats a predefined php function.
wervisser
Posts: 29
Joined: Monday 28 November 2016 18:38
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.1
Contact:

Re: PHP Floorplan, cron script and Google Calendar

Post by wervisser »

Well, let's dust this topic off :lol:

I downloaded the code, placed it on my Synology in the /volume1/web folder and went ahead adjusting settings.php to my installation. Actually the only thing changed is the URL and zwaveidx (I've set this to my ZWave stick). I've commented most of the others lines out, since I'm currently not using these.
Then I opened up floorplan.php and made a few adjustments at the 'Schakelaar' section.

When I open up floorplan.php in my browser it just shows a black screen with 1:00:00 in the top and no other icons. Any idea what I've missed here ?
User avatar
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

Post by Egregius »

Can you post your fode in a code=php block?
wervisser
Posts: 29
Joined: Monday 28 November 2016 18:38
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.1
Contact:

Re: PHP Floorplan, cron script and Google Calendar

Post by wervisser »

Sure, which files are you looking for exactly ? floorplan.php and settings.php ?
User avatar
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

Post by Egregius »

If you didn't change functions.php, yes, those 2.
wervisser
Posts: 29
Joined: Monday 28 November 2016 18:38
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.1
Contact:

Re: PHP Floorplan, cron script and Google Calendar

Post by wervisser »

Snippet from floorplan.php. I only modified some lines of the devices to see if something would pop up.

Code: Select all

Dimmer('Philips_Hue',70,435,135);
Dimmer('Philips_Hue',70,110,105);
Dimmer('Philips_Hue',70,110,245);
Dimmer('Philips_Hue',70,545,345);
Dimmer('Philips_Hue',70,560,135);
Schakelaar('Philips_Hue','Light',52,8,88);
Schakelaar('Philips_Hue','Light',52,8,147);
Schakelaar('Philips_Hue','Light',52,8,206);
Schakelaar('Philips_Hue','Light',52,51,349);
Schakelaar('Philips_Hue','Light',52,157,390);
Schakelaar('Philips_Hue','Light',40,145,345);
Schakelaar('Philips_Hue','Light',40,115,386);
Schakelaar('Philips_Hue','Light',40,208,434);
Schakelaar('Philips_Hue','Light',70,420,390);
Schakelaar('Philips_Hue','Light',40,463,349);
Only the first two lines of settings.php are updated. After the update the message indicating Domoticz cannot be found disappears. So this looks like it has a connection.

Code: Select all

$domoticzurl='http://xxx.xxx.xxx.x:8084/';
$zwaveidx=2;
User avatar
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

Post by Egregius »

Why do they all have the same name?
wervisser
Posts: 29
Joined: Monday 28 November 2016 18:38
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.1
Contact:

Re: PHP Floorplan, cron script and Google Calendar

Post by wervisser »

I just wanted to check if anything would come up on the floorplan ;)
User avatar
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

Post by Egregius »

You should start with one device.
Is 'Philips_Hue' the exact name os the switch?
Could be the Hue just doesn't work, try with a normal switch or dimmer first.
Firepeet
Posts: 3
Joined: Sunday 04 December 2016 10:59
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Contact:

Re: PHP Floorplan, cron script and Google Calendar

Post by Firepeet »

I have exactly the same problem as wervisser.

Domoticz are running on a Synology. I tried to run floorplan on my Synology and also on an external server. Both give same problem. A black screen with only the standard floorplan.

Image

Code: Select all

Schakelaar('Lamp_eettafel','Light',52,8,88);
Schakelaar('Lamp_ventilator','Light',52,8,147);
Lamp_eettafel and Lamp_ventilator are the same names of the switches in Domoticz.
The only changes i made are the files floorplan.php en and settings.php (only the domoticzurl and zwaveidx).
User avatar
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

Post by Egregius »

Hmmm, strange... You do have a roomplan with the swiches? Or removed &plan=2?
Let's start with a test file.
Create test.php with this code:

Code: Select all

<?php
error_reporting(E_ALL);
ini_set("display_errors","on");
require "../secure/settings.php";
require "../secure/functions.php";
$domoticz=json_decode(curl('http://127.0.0.1:8084/json.htm?type=devices&plan=2',true,$ctx),true);
if($domoticz)
{
    foreach($domoticz['result'] as $dom)
    {
        $name=$dom['Name'];
        isset($dom['SwitchType'])
            ?$SwitchType=$dom['SwitchType']
            :'none';
        if($SwitchType=='Dimmer')
        {
            ${'DI'.$name}=$dom['idx'];
            $dom['Status']=='Off'?${'D'.$name}='Off':${'D'.$name}='On';
            $dom['Status']=='Off'?${'Dlevel'.$name}=0:${'Dlevel'.$name}=$dom['Level'];
        }
        else
        {
            ${'S'.$name}=$dom['Data'];
            ${'SI'.$name}=$dom['idx'];
            ${'ST'.$name}=strtotime($dom['LastUpdate']);
        }
    }
    echo '<pre>';
    print_r(get_defined_vars());
    echo '</pre>';
}
You should see an array dumped with all the switches of your roomplan.
Spoiler: show
[domoticz] => Array
(
[ActTime] => 1480972851
[ServerTime] => 2016-12-05 22:20:51
[Sunrise] => 08:35
[Sunset] => 16:41
[result] => Array
(
[0] => Array
(
[AddjMulti] => 1
[AddjMulti2] => 1
[AddjValue] => 0
[AddjValue2] => 0
[BatteryLevel] => 255
[CustomImage] => 13
[Data] => Off
[Description] =>
[Favorite] => 1
[HardwareID] => 2
[HardwareName] => Dummy
[HardwareType] => Dummy (Does nothing, use for virtual switches only)
[HardwareTypeVal] => 15
[HaveDimmer] => 1
[HaveGroupCmd] => 1
[HaveTimeout] =>
[ID] => 00000002
[Image] => Alarm
[IsSubDevice] =>
[LastUpdate] => 2016-12-05 06:01:42
[Level] => 0
[LevelInt] => 0
[MaxDimLevel] => 100
[Name] => slapen
[Notifications] => false
[PlanID] => 2
[PlanIDs] => Array
(
[0] => 2
)

[Protected] =>
[ShowNotifications] => 1
[SignalLevel] => -
[Status] => Off
[StrParam1] =>
[StrParam2] =>
[SubType] => Switch
[SwitchType] => On/Off
[SwitchTypeVal] => 0
[Timers] => false
[Type] => Light/Switch
[TypeImg] => lightbulb
[Unit] => 1
[Used] => 1
[UsedByCamera] =>
[XOffset] => 0
[YOffset] => 0
[idx] => 2
)
At the end you should see them like this:

Code: Select all

 [Sbureel] => Off
    [SIbureel] => 22
    [STbureel] => 1480963390
    [Sdenon] => On
    [SIdenon] => 18
    [STdenon] => 1480926566
    [Skodi] => On
    [SIkodi] => 15
    [STkodi] => 1480963450
    [Skristal] => Off
    [SIkristal] => 21
    [STkristal] => 1480928629
    [Stv] => On
    [SItv] => 19
    [STtv] => 1480963377
    [Stvled] => On
    [SItvled] => 20
    [STtvled] => 1480968679
    [DIeettafel] => 35
    [Deettafel] => Off
    [Dleveleettafel] => 0
    [DIzithoek] => 38
    [Dzithoek] => Off
    [Dlevelzithoek] => 0
    
User avatar
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

Post by Egregius »

Just published my latest code about Floorplan. Maybe a good idea to start with that code...
https://egregius.be/2016/php-floorplan- ... -domoticz/
wervisser
Posts: 29
Joined: Monday 28 November 2016 18:38
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.1
Contact:

Re: PHP Floorplan, cron script and Google Calendar

Post by wervisser »

What exactly do you mean with 'you do have a roomplan with switches'. I haven't created anything in Domoticz, I thought this was meant to replace the Domoticz floorplan.

I have created a test file, but it won't list my devices. When I open up the URL provided in the file I get the following output.

Code: Select all

{
   "ActTime" : 1481005776,
   "ServerTime" : "2016-12-06 07:29:36",
   "Sunrise" : "08:32",
   "Sunset" : "16:30",
   "status" : "OK",
   "title" : "Devices"
}
If I open up the test.php file from within a browser I get 'Fatal error: Call to undefined function curl() in /volume1/web/secure/test.php on line 6'.

Line 6 is

Code: Select all

$domoticz=json_decode(curl('http://xxx.xxx.xxx.xxx:8084/json.htm?type=devices&plan=2',true,$ctx),true);
User avatar
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

Post by Egregius »

Either you use this url, wich will pull all used devices.

Code: Select all

http://xxx.xxx.xxx.xxx:8084/json.htm?type=devices&used=true
or a specific roomplan.

Code: Select all

http://xxx.xxx.xxx.xxx:8084/json.htm?type=devices&plan=2
Difference in my case:
Used = 233 Devices = 159msec load time
Plan = 48 Devices = 35msec load time

The curl function should be in settings.php...
wervisser
Posts: 29
Joined: Monday 28 November 2016 18:38
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.1
Contact:

Re: PHP Floorplan, cron script and Google Calendar

Post by wervisser »

That's a nice speed improvement :-)

The curl line stated was set in the test.php file as you explained in a previous post. The only reference line in settings.php is the Domoticz URL. The contents of the file was copied from your new upload on your private website. I assume I only have to replace the contents of these specific files and leave the rest intact. As such there will have to be one folder added 'styles'.

Back to the floorplan. I can use the second URL provided which will only give me the following output. I do need to create a floorplan first in Domoticz to accomplish this ? Yes, I just created a roomplan with one device and tried the json again. This lists the devices I just added :oops:

Code: Select all

{
   "ActTime" : 1481008466,
   "ServerTime" : "2016-12-06 08:14:26",
   "Sunrise" : "08:32",
   "Sunset" : "16:30",
   "status" : "OK",
   "title" : "Devices"
}
User avatar
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

Post by Egregius »

So you're using

Code: Select all

http://xxx.xxx.xxx.xxx:8084/json.htm?type=devices&plan=2
now?
"2" at the end should be the ID of the roomplan.
You must get output like in http://www.domoticz.com/forum/posting.p ... 1#pr107423
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest