Read temp value 15 min ago
Moderator: leecollings
- Minglarn
- Posts: 214
- Joined: Friday 21 August 2015 19:27
- Target OS: Raspberry Pi / ODroid
- Domoticz version: v3.8153
- Location: Stockholm / Sweden
- Contact:
Read temp value 15 min ago
Hi folks!
I need to read the stored temp value for a specific temperature senor from domoticz.
I'm reprogramming my front-page to use the domoticz as a base for temp values and to read status from a couple of switches. As seen in the picture above I have a "trending" arrow for outside temperature. I'ts based on comparison of outside temperature 30 min ago. But it reads the value from a WAN stored database and I dont want that.
Is it possible to read the stored value for a specific time from Domotics?
I need to read the stored temp value for a specific temperature senor from domoticz.
I'm reprogramming my front-page to use the domoticz as a base for temp values and to read status from a couple of switches. As seen in the picture above I have a "trending" arrow for outside temperature. I'ts based on comparison of outside temperature 30 min ago. But it reads the value from a WAN stored database and I dont want that.
Is it possible to read the stored value for a specific time from Domotics?
“When you eliminate the impossible, whatever remains, however improbable, must be the truth.” -Spock in Star Trek VI
- Egregius
- Posts: 2592
- Joined: Thursday 09 April 2015 12:19
- Target OS: Linux
- Domoticz version: v2024.7
- Location: Beitem, BE
- Contact:
Re: Read temp value 15 min ago
You could read it directly from the SQLite database.
- Minglarn
- Posts: 214
- Joined: Friday 21 August 2015 19:27
- Target OS: Raspberry Pi / ODroid
- Domoticz version: v3.8153
- Location: Stockholm / Sweden
- Contact:
Re: Read temp value 15 min ago
Ok, any info on how to do it?
Using PHP to do my frontpage so it would be perfect if its doable from PHP.
EDIT: did a search on "SQLite" and see now that domoticz has to be stopped first... No good.
Using PHP to do my frontpage so it would be perfect if its doable from PHP.
EDIT: did a search on "SQLite" and see now that domoticz has to be stopped first... No good.

Last edited by Minglarn on Saturday 07 November 2015 13:56, edited 1 time in total.
“When you eliminate the impossible, whatever remains, however improbable, must be the truth.” -Spock in Star Trek VI
- Egregius
- Posts: 2592
- Joined: Thursday 09 April 2015 12:19
- Target OS: Linux
- Domoticz version: v2024.7
- Location: Beitem, BE
- Contact:
Re: Read temp value 15 min ago
Something quick:
That gives you a array $times() with all values for that thermometer. Add a limit 0,5 to only take last 5. Or whatever query you like.
I never stop domoticz for reading the database. Reading is the only thing I do and never had a problem with it.
I use above for some custom temperature graphs with the associated setpoints in 1 graph.
The complete code can be viewed at https://github.com/Egregius/PHP-Custom- ... r/temp.php
Code: Select all
<?php
$dbd = new SQLite3('/home/pi/domoticz/domoticz.db');
$sensor = 38; //IDX of the thermometer
$sql = "SELECT Date, Temperature FROM Temperature WHERE DeviceRowID = $sensor ORDER BY Date DESC";
if(!$result = $dbd->query($sql)){ echo('There was an error running the query [' . $dbd->error . ']');}
$times = array();
while($row = $result->fetchArray()){
array_push($times, array('Date' => $row['Date'], 'Temperature' => $row['Temperature']));
}
I never stop domoticz for reading the database. Reading is the only thing I do and never had a problem with it.
I use above for some custom temperature graphs with the associated setpoints in 1 graph.
The complete code can be viewed at https://github.com/Egregius/PHP-Custom- ... r/temp.php
Re: Read temp value 15 min ago
SELECT should work on a SQLite database allthough it is not supported!!!Minglarn wrote:did a search on "SQLite" and see now that domoticz has to be stopped first... No good.
- Minglarn
- Posts: 214
- Joined: Friday 21 August 2015 19:27
- Target OS: Raspberry Pi / ODroid
- Domoticz version: v3.8153
- Location: Stockholm / Sweden
- Contact:
Re: Read temp value 15 min ago
Thanks for the code, but ain't there a easier way to get the values or?Egregius wrote:Something quick:
That gives you a array $times() with all values for that thermometer. Add a limit 0,5 to only take last 5. Or whatever query you like.Code: Select all
<?php $dbd = new SQLite3('/home/pi/domoticz/domoticz.db'); $sensor = 38; //IDX of the thermometer $sql = "SELECT Date, Temperature FROM Temperature WHERE DeviceRowID = $sensor ORDER BY Date DESC"; if(!$result = $dbd->query($sql)){ echo('There was an error running the query [' . $dbd->error . ']');} $times = array(); while($row = $result->fetchArray()){ array_push($times, array('Date' => $row['Date'], 'Temperature' => $row['Temperature'])); }
I never stop domoticz for reading the database. Reading is the only thing I do and never had a problem with it.
I use above for some custom temperature graphs with the associated setpoints in 1 graph.
The complete code can be viewed at https://github.com/Egregius/PHP-Custom- ... r/temp.php
Sent from space using an app.

“When you eliminate the impossible, whatever remains, however improbable, must be the truth.” -Spock in Star Trek VI
- Egregius
- Posts: 2592
- Joined: Thursday 09 April 2015 12:19
- Target OS: Linux
- Domoticz version: v2024.7
- Location: Beitem, BE
- Contact:
Re: Read temp value 15 min ago
It's quite easy to pull one value:
Maybe average of last 3 values could be interesting for you:
Code: Select all
<?php
$dbd = new SQLite3('/home/pi/domoticz/domoticz.db');
$sql = "SELECT Temperature FROM Temperature WHERE DeviceRowID = 38 ORDER BY Date DESC limit 2,1";
if(!$result = $dbd->query($sql)){ echo('There was an error running the query [' . $dbd->error . ']');}
$row = $result->fetchArray();
echo $row['Temperature'];
Code: Select all
<?php
$dbd = new SQLite3('/home/pi/domoticz/domoticz.db');
$sql = "SELECT avg(Temperature) as Temperature FROM Temperature WHERE DeviceRowID = 38 ORDER BY Date DESC limit 0,3";
if(!$result = $dbd->query($sql)){ echo('There was an error running the query [' . $dbd->error . ']');}
$row = $result->fetchArray();
echo $row['Temperature'];
- Minglarn
- Posts: 214
- Joined: Friday 21 August 2015 19:27
- Target OS: Raspberry Pi / ODroid
- Domoticz version: v3.8153
- Location: Stockholm / Sweden
- Contact:
Re: Read temp value 15 min ago
Thanks!! I really appreciate your support...
So how do I gain access to domoticz database? Do I need to install SQL Lite?
So how do I gain access to domoticz database? Do I need to install SQL Lite?
“When you eliminate the impossible, whatever remains, however improbable, must be the truth.” -Spock in Star Trek VI
- Egregius
- Posts: 2592
- Joined: Thursday 09 April 2015 12:19
- Target OS: Linux
- Domoticz version: v2024.7
- Location: Beitem, BE
- Contact:
Re: Read temp value 15 min ago
Did you try the code above? Does it give an error?
I can't remember if I installed SQLite3 myself or that it was already installed in the Rpi image.
Otherwise I would think "sudo apt-get install sqlite3" should do it.
I can't remember if I installed SQLite3 myself or that it was already installed in the Rpi image.
Otherwise I would think "sudo apt-get install sqlite3" should do it.
- Minglarn
- Posts: 214
- Joined: Friday 21 August 2015 19:27
- Target OS: Raspberry Pi / ODroid
- Domoticz version: v3.8153
- Location: Stockholm / Sweden
- Contact:
Re: Read temp value 15 min ago
Having trouble to get PHP script running on domoticz... investigating at the moment. 

“When you eliminate the impossible, whatever remains, however improbable, must be the truth.” -Spock in Star Trek VI
- Minglarn
- Posts: 214
- Joined: Friday 21 August 2015 19:27
- Target OS: Raspberry Pi / ODroid
- Domoticz version: v3.8153
- Location: Stockholm / Sweden
- Contact:
Re: Read temp value 15 min ago
Hmm. Seems that I have to install Apache and php.
Sent from space using an app.
Sent from space using an app.

“When you eliminate the impossible, whatever remains, however improbable, must be the truth.” -Spock in Star Trek VI
- Egregius
- Posts: 2592
- Joined: Thursday 09 April 2015 12:19
- Target OS: Linux
- Domoticz version: v2024.7
- Location: Beitem, BE
- Contact:
Re: Read temp value 15 min ago
I guessed you already had those because you asked for a php script.
Apache runs fine on the Rpi
Apache runs fine on the Rpi

Who is online
Users browsing this forum: No registered users and 1 guest