Page 1 of 1
Show current temp/value on homepage
Posted: Saturday 12 August 2017 22:40
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!
Re: Show current temp/value on homepage
Posted: Saturday 12 August 2017 22:47
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.
Re: Show current temp/value on homepage
Posted: Saturday 12 August 2017 23:15
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?
Re: Show current temp/value on homepage
Posted: Saturday 12 August 2017 23:32
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
Re: Show current temp/value on homepage
Posted: Saturday 12 August 2017 23:58
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)
Re: Show current temp/value on homepage
Posted: Sunday 13 August 2017 9:46
by Egregius
Give me few minutes to write some code...
Re: Show current temp/value on homepage
Posted: Sunday 13 August 2017 9:57
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
Re: Show current temp/value on homepage
Posted: Sunday 13 August 2017 21:38
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
