I’m looking to add a widget that shows the power/energy usage during the last hour, based on an item that stores the cumulative all-time energy usage.
The approach that seems sensible, is to access the persistence/history data directly from the widget using an expression, but I suspect that this is not possible. Maybe because widget expressions really are just ran in the browser on a very limited subset of data, while the persistence methods are available in the server only? I’m not quite sure, since there’s quite a few different types of scripting going around…
In any case, here’s what I tried:
(I added the string concat to show that the result is undefined)
One alternative that I considered (and found mentioned in the forum already) is doing this in a rule, so whenever
energy_delivered changes, get the delta over the last hour and store that into a new item. However, this seems a bit wasteful and bad separation of concerns, to add and update a new item which is only used for display and does not store any new information by itself. Or is this a common pattern when using OpenHAB and should I just bite this bullet and add more items and rules?
Or is there another approach that makes sense?
- Platform information:
- Hardware: Rpi 3
- OS: Openhabian
- openHAB version: 3.0.2