Wednesday, April 5, 2017

Correcting values in Domoticz database

The underlying database in Domoticz is a SQLite3 database. Make sure that you have the sqlite3 package installed.

sudo apt-get install sqlite3

Stop Domoticz just to be sure

sudo service domoticz.sh stop

Make a backup copy of the Domoticz database.

cd ~/domoticz
cp domoticz.db domoticz.db.bak

Start SQLite3 on the Domoticz DB

sqlite3 domoticz.db

Some useful commands
.header on
.mode column
.tables
.dump

Temperature values for today are stored in the Temperature table. Historic values are stored in the Temperature_Calendar.

SELECT * FROM Temperature_Calendar;

Show all values for a certain date or earlier

SELECT * FROM Temperature_Calendar WHERE [Date] = '2017-03-13';
SELECT * FROM Temperature_Calendar WHERE [Date] < '2017-03-13';

Show all values for a specific device. You can find the right DeviceRowID in the Domoticz interface by opening the graphs and looking at the values in the parameters of the URL.

SELECT * FROM Temperature_Calendar WHERE [DeviceRowID] = 8;

You can delete old values as follows (useful to test your query first with a SELECT):

SELECT * FROM Temperature_Calendar WHERE [DeviceRowID] = 107 AND [Date] < '2017-02-19';
DELETE FROM Temperature_Calendar WHERE [DeviceRowID] = 107 AND [Date] < '2017-02-19';

You can correct certain values by using the UPDATE statement for a device on a certain date.

UPDATE Temperature_Calendar SET [Temp_Max] = 20.9 WHERE [DeviceRowID] = 8 AND [Date] = '2017-03-13';

I'm not sure why it happens, but the records for the Sunday on which the summer time starts, get stored under the Saterday, which results in two Temperature_Calendar records with the same date. This translates in the graphs to a vertical jump. This can be fixed in the database by listing the entries for that date and updating the date of the second record.

SELECT * FROM Temperature_Calendar WHERE [Date] = '2017-03-25'
 
You have to choose one of the values that identifies the second record, because you have to tell the database which one to update (and you can't say the second stored record, AFAIK). I chose the Temp_Min value.

UPDATE Temperature_Calendar SET [Date] = '2017-03-26' WHERE [Date] = '2017-03-25' AND [Temp_Min] = 21.1;
Make sure that you filter on both DeviceRowID and on Date or you will be changing the value for all devices or for all dates. Exit SQLite3 with .quit.

.quit

Start Domoticz to check your results.

sudo service domoticz.sh start

Thursday, March 16, 2017

Adding an https certificate to ownCloud on FreeNAS 9


  1. Copy the certificate file (e.g. .crt) and the decrypted key file (e.g. .key.decrypted) to the jail in which ownCloud runs.

    cp {servername.crt,servername.key.decrypted} /mnt/tank/jails/owncloud_1/usr/pbi/owncloud-amd64/etc/apache24/
  2. Click on the Jails icon in the FreeNAS top menu, select the ownCloud jail (owncloud_1) and open a Shell by pressing the shell icon at the bottom.
  3. Edit the httpd-ssl.conf file in the 'extra' folder of the Apache config folder.

    vi /usr/pbi/owncloud-amd64/etc/apache24/extra/httpd-ssl.conf
  4. Change the value of the SSLCertificateFile setting.

    SSLCertificateFile "/usr/pbi/owncloud-amd64/etc/apache24/servername.crt"
  5. Change the value of the SSLCertificateKeyFile setting

    SSLCertificateKeyFile "/usr/pbi/owncloud-amd64/etc/apache24/servername.key.decrypted"
  6. Restart Apache

    /usr/pbi/owncloud-amd64/etc/rc.d/apache24 restart
The certificate should be working.