Show current temp/value on homepage

Moderator: leecollings

Post Reply
Cribbe
Posts: 5
Joined: Saturday 24 June 2017 19:39
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.5866
Location: Sweden
Contact:

Show current temp/value on homepage

Post by Cribbe »

I am trying to build a homepage that are made for an old smartphone that will be mounted on the wall.
I want to get current temp from my different temp sensors and perhaps wind and rain sensors as well.
Trying to do this by json but I just get day/month or year and not the just the current value.
Could somebody perhaps help me? Mayby I shall use something else but json?

Thanks!
User avatar
Egregius
Posts: 2589
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: v2024.7
Location: Beitem, BE
Contact:

Re: Show current temp/value on homepage

Post by Egregius »

Json should do just fine. Maybe my PHP Floorplan could give you some ideas? Altough, the current version is totally based on using apcu cache together with pass2php.

Main thing to do is put the devices you want in a roomplan and query that with json.
Loop thru the reply to display the stuff.
Cribbe
Posts: 5
Joined: Saturday 24 June 2017 19:39
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.5866
Location: Sweden
Contact:

Re: Show current temp/value on homepage

Post by Cribbe »

So I must do a roomplan for this? I can´t "just" query current temp by json and print that value on a page?
User avatar
Egregius
Posts: 2589
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: v2024.7
Location: Beitem, BE
Contact:

Re: Show current temp/value on homepage

Post by Egregius »

That's the best way because you then only need one api call.
For one device: /json.htm?type=devices&rid=IDX
For all temp devices: /json.htm?type=devices&filter=temp&used=true
For a roomplan: /json.htm?type=devices&used=true&plan=IDX (IDX of the roomplan)
For all used devices: /json.htm?type=devices&used=true
Cribbe
Posts: 5
Joined: Saturday 24 June 2017 19:39
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.5866
Location: Sweden
Contact:

Re: Show current temp/value on homepage

Post by Cribbe »

Well so much I have figured out :-)
But if I for exampel do /json.htm?type=devices&rid=IDX I get a reply with lots of values.
I see that "Temp" is one of them, but I can´t figure out the php code for this to show on my webpage.
For example on the webpage:
Pool - (current temp, json script)
Inside - (current temp, json script)
Outside - (current temp, json script)
User avatar
Egregius
Posts: 2589
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: v2024.7
Location: Beitem, BE
Contact:

Re: Show current temp/value on homepage

Post by Egregius »

Give me few minutes to write some code...
User avatar
Egregius
Posts: 2589
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: v2024.7
Location: Beitem, BE
Contact:

Re: Show current temp/value on homepage

Post by Egregius »

Code: Select all

//Lets grab all temp devices
$domoticz=json_decode(file_get_contents('http://127.0.0.1:8080/json.htm?type=devices&filter=temp&used=true'),true);
//Check if we got a result
if($domoticz){
	//loop thru the result
	foreach($domoticz['result'] as $dom){
		//set a variable with the name
		$name=$dom['Name'];
		//if we have a temp device set a variable with the name of the device with it's value
		if($dom['Type']=='Temp')${$name}=str_replace(' C','',$dom['Data']);
	}
}
//echo some data on the page. Ex alex_temp is the name of a thermometer
echo '<table>
<tr><td>Alex</td><td>'.$alex_temp.' °C</td></tr>
<tr><td>Tobi</td><td>'.$tobi_temp.' °C</td></tr>
<tr><td>Living</td><td>'.$living_temp.' °C</td></tr>
<tr><td>Kamer</td><td>'.$kamer_temp.' °C</td></tr>
<tr><td>Badkamer</td><td>'.$badkamer_temp.' °C</td></tr>
</table>';
This will print a small table with the values:

Code: Select all

Alex	21.1 °C
Tobi	21.1 °C
Living	21.1 °C
Kamer	21.2 °C
Badkamer	21.3 °C
Cribbe
Posts: 5
Joined: Saturday 24 June 2017 19:39
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.5866
Location: Sweden
Contact:

Re: Show current temp/value on homepage

Post by Cribbe »

Thanks!
Got it to work, but got stuck on one sensor that is both temp & humidity.
I´ve tried this:

Code: Select all

<?php
//Lets grab all temp devices
$domoticz=json_decode(file_get_contents('http://192.168.1.77:8080/json.htm?type=devices&filter=temp&used=true'),true);
//Check if we got a result
if($domoticz){
	//loop thru the result
	foreach($domoticz['result'] as $dom){
		//set a variable with the name
		$name=$dom['Name'];
		//if we have a temp device set a variable with the name of the device with it's value
		if($dom['Type']=='Temp + Humidity')${$name}=str_replace(' C','',$dom['Data']);
	}
}

//echo some data on the page. Ex alex_temp is the name of a thermometer
echo '<table>
<tr><td>Ute</td><td>'.$Ute.' °C</td></tr>
</table>';
But that give me this as result:

Ute 14.2, 71 % °C

I can´t figure out how to give me the result like this (if it is possible):
Ute 14,2 °C, 72% humidity or something similar :D
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests