
Re: Feature Request: SQL Logger Creates Views
matt (support) wrote:So your idea is to add views that allow selection on device/variable names instead of ID, which means we would need a device and variable ID/name mapping table as well, correct?
Well, I guess one could be created. However, what I had in mind wouldn't require any mapping table. My understanding is that SQLite3 supports the creation of read-only table views. So, for example, instead of finding the maximum temperature from yesterday using the SQL statement
- Code: Select all
SELECT ts, MAX(temperatureinput1)
FROM device_history_1652127487
WHERE ts BETWEEN '2012-05-26 00:00:00' AND '2012-05-27 00:00:00';
one could do the same thing with the SQL statement
- Code: Select all
SELECT ts, MAX(temperatureinput1)
FROM device_history_Main_Thermostat
WHERE ts BETWEEN '2012-05-26 00:00:00' AND '2012-05-27 00:00:00';
The plugin could create the view immediately after the table was created using
- Code: Select all
CREATE VIEW device_history_<modified device name> AS SELECT h.* FROM device_history_<device ID> h;
If the device name changes, the view would have to be dropped and re-created with the new device name.
However, I think I know where you're going with the device ID-to-device name mapping table and I like that idea too! In fact, that'd probably be better than a separate view for each device_history_*/variable_history_* table as one could use the actual device name in SQL statements rather than the character-set-limited device name version that would be required for view names.
Any ideas for other views that might be useful?
I like both of those examples you provided. The CSV output idea could be very useful, and not just for thermostats. Perhaps a view that shows the top 5 (or 10) most frequently turned on lights/devices? I'll ponder on it some more and post again if I can think of other useful data that could be gleaned from the database. It does strike me, though, that it could be possible to calculate historical device energy usage from the device history tables. I might investigate that further for my little eTrack setup.