Rrd4j will save data as set in the respective config.
If you go with the default setup it will keep your exact values for every minute for the time frame of the last 8 houres. For longer time frames the values will be “compressed” , like one value for each 14 minutes in a frame of 159 houres…
When using a custom config you can keep each minute value for the last 24 houres. Additionally you can use rrd4j to keep a singe value for each 6 houre step in a time frame of your decision . This value could be configured to be the average.
You have to understand that rrd4j will not have any value beyond the respective timeframe. For the default setup there is no minute value keep beyond the 8 houres.
Hm, i don´t know, what you exactly want to say me with one single value each 6 hours step…
Temperature is changing maybe every minute, so average temp is changing also. So i don´t see any need for one single item in a time period of 6 hours???
Ok, then let´s do it for the last 6h at the moment.
How can i get the average temp of the last 6 hours out of the rrd4j-database?
Later maybe i will change rrd4j config to save more values. Whre can i find the config-file to change this?
I tried to point out that by using rrd4j in the default setting, you are getting a database that holds the saved value for every minute only for the last 8 houres. The next archive in the default setting holds one value for every 14 minutes for 156 houres. There are more archives in the default setting.
If you want to get an exact average for the last 6, 12 and 24 houres, you can either change the default setting or you have to use the compressed data that rrd4j holds.
The compression itself , which is done by rrd4j, is taking the average ( if not set differently) of during the time steps ( in the above mentioned second archive the average of 14 minutes).
Using this compressed data, the items function mentioned by @spy0r will calculate the average.
And I believe YES, you will delete all saved data if changing the settings of rrd4j.
Using influxdb 0.13 as persistence provider, I am not getting the expected results from the averageSince function.
Maybe my expectations are wrong, but I would expect it to weight the values with the time they where valid.
Simple example:
Using a temperature item which is stored on every change.
12:00 - 20.0
12:20 - 22.0
So, it was 20.0 for 20 minutes and after that 22.0 for 40 minutes
If I query this at 13:00 with temp.averageSince(now.minusHours(1)), I would expect it to return
I’m trying to do something similar and wanted to reuse your little script with some modifications.
Basically what I’m after is creaing items with the highest and lowest temperature value during the last 7 days. I have my temp sensor logging values every 10 minutes in a mariaDB instance, everything works fine.
I created an item (number) called “HighTempWeek” and then created a rule that looks like this:
rule “Weekly high” when Item Ute_Temperature received update then HighTempWeek.postUpdate(Ute_Temperature.maximumSince(now.minusDays(7))) end
but the script doesnt work and I get the error message:
[ERROR] [untime.internal.engine.RuleEngineImpl] - Rule ‘Weekly high’: An error occurred during the script execution: Could not invoke method: org.eclipse.smarthome.model.script.actions.BusEvent.postUpdate(org.eclipse.smarthome.core.items.Item,org.eclipse.smarthome.core.types.State) on instance: null
The persistence service seems properly configured. The service stores sensor data in a table with two colums, time and value. The “time” column is of type timestamp and value is of type double. I havent created the schema myself, everything was auto generated by the persistence service.
that’s not what is supposed to get back here…
Since i have no testing object during the day… This looks like you want to access an Item value, but forget to use the .state statement. But in persistence cases, the syntax isn’t wrong at all i think.
If we assume that the persistence service is configured correctly, try to shrink the period and/or the statement first.
What if you replace yout statement with something like:
Thanks for your tip. Unfortunately though it doesnt work for me
This is a sample output from the log after I customized your rule
13:12:21.709 [WARN ] [.ui.internal.items.ItemUIRegistryImpl] - Exception while formatting value '24.9 °C (13:12)' of item WeekTempHigh with format '%.1f °C': f != java.lang.String
It seems like it both fetches the value and time. If I just can get rid of the timestamp I guess it will work.
Displaying the Item in habpanel shows this
I also want to be able to display the item in openhab for android and that doesnt work right now…