Curious if there is a way to access the data that the Analyzer Widget uses to create the graphs?
Running openHAB 3.2.0.M4 using Jython scripting
For instance, how can I know (programatically) which motion sensor had the most recent activity? Seems that unless I create an Item and store the date/time for each sensor triggers, there is not another way.
Be sure to look at the Persistence Actions, one of which is “lastUpdate” which returns the most recent value stored in the database. Take note of that last sentence, it’s really important.
By default OH 3 uses rrd4j configured to store every Item every minute and on every change. That’s what drives the charts. However, because it saves every value every minute it makes it unsuitable for your use case. The most recent value in the database is going to be no more than one minute ago regardless of when the Item last changed.
Therefore you’ll want to use a different persistence for this. In this case, assuming you can use rrd4j for other historic data and calculations (e.g. averageSince, minSince, etc.) I recommend using MapDB. This persistence engine only saves the most recent value. However, there could be a conflict between rrd4j and MapDB’s default persistence strategies. Both will save the states of all Items and restoreOnStartup which means that Items will be restoredOnStartup twice during a book and which one updates any given Item second is not defined.
Using the link above, create a mapdb.persist file to save only those Items you care about on every change. Alternatively, create a rrd4j.persist file to save all Items every minute and on every change but do not use restoreOnStartup and let MapDB handle that. MapDB is better for that anyway because it can handle Item types that rrd4j cannot like String Items.
Sorry, I seem to have a mental block to look there first, thank you again
… ok so I can access the .lastUpdate … but it doesn’t seem to matter if I have the Item in the MapDB.persist file or not, the .lastUpdate is always every minute. The MapDB file is being reloaded after the change, but do I need to restart the system for it to take affect? (I doubt it)
If that is literally how your file is named it means that MapDB is using the default strategies which is to save all Items on every change with restoreOnStartup. Your .persist file is being ignored. Here too case matters.
Hmm ok … but when originally installed the MapDB for the TimeOfDay defaults etc and for some other items, they seems to be working as I would expect (ie. restored correctly after reboot) … sounds like I need to go back and check that.
but, it must be correct that I dont need to specify the Motion sensors in a mapdb.persist file to get the .lastUpdate to work … since it’s working.