Posts: 176
Threads: 42
Joined: Jul 2015
Reputation:
2
Hi. When creating a trend there should be an option to choose between accumulate values or use average values. When trending a temperature it would be best to use average( this is the only option today) when trending kwh accumulate would be best. When changing view of the trend (day by day, or week by week) the trend value can be correct. Now I have to multiply the value by 24 if it is day by day and so on.
Posts: 1764
Threads: 6
Joined: Jul 2015
Reputation:
117
Hi,
You already can... use absolute value for average and counter for cumulative.
BR,
Erwin
Posts: 176
Threads: 42
Joined: Jul 2015
Reputation:
2
I tried counter a couple of years ago but that made no sense with the values. I can try again to see.
Posts: 1764
Threads: 6
Joined: Jul 2015
Reputation:
117
05.02.2017, 19:17
(This post was last modified: 05.02.2017, 19:33 by Erwin van der Zwart.)
Hi,
Can be, currently i don't see any issue with trends. There is a lot changed the last years (:
For kWh i advice mostly to make even 2 trends on same object, 1 absolute to see average consumption and 1 counter to see total (however this is a straight line upwards).
Make sure to use counter only for values that are not getting lower then the previous value (temperature or kW is not a real good idea to use counter, this results in wrong trends) Kwh can be used as counter.
BR,
Erwin
Posts: 176
Threads: 42
Joined: Jul 2015
Reputation:
2
Aha. My measuring is based on Watts x Ampere which gives me Kw realtime. I dont want a counter as that gives a line up as you say. I just want an accumulate of the seperate values to get a trend. It is not possible to se previous trend and compare it to current if the values are unlike as the line up counter will do. If I have 1 hour trend and chose to se day by day, i would likr the lm to add up all the 24 points and give me the total for each day
Posts: 1764
Threads: 6
Joined: Jul 2015
Reputation:
117
05.02.2017, 23:23
(This post was last modified: 06.02.2017, 00:26 by Erwin van der Zwart.)
Okay new approach (:
Well what you could do in this case is create a dummy object and create a trend to this dummy object and create a scheduled script that runs once a day at 0:01. (or run every x minutes if you want multiple points in between)
In this scheduled script you do a trends.fetchone on the trend with the 24 points, this will give you a average day value of your day values. Write this result once a day to your dummy object and the second trend attached to the dummy object will show your day average value(s).
If you want a total sum of the day values you can do a trend.fetch (instead of the fetchone) this will result in a data set of the full day and do a loop through the result table to sum all values and write the sum result to your dummy object, this results in a trend with sum of day values.
See http://openrb.com/docs/trends-new.htm for a sample how to fetch one average day value or a table with day values where you can loop through to sum up the day values.
BR,
Erwin
Posts: 7758
Threads: 42
Joined: Jun 2015
Reputation:
447
Trends are not meant for realtime values. It will produce incorrect data because the lowest possible sampling time is 5 minutes. You can create a script which acts as a counter and adds the current consumption value to an object which is then added as a trend with counter type.
Posts: 176
Threads: 42
Joined: Jul 2015
Reputation:
2
When you write that the sampling time is 5 min i suppose you mean that the trend values is an average of the 5 minutes? Not just a reading that takes place every 5 minutes?
Posts: 7758
Threads: 42
Joined: Jun 2015
Reputation:
447
The object value is read every 5 minutes, so everything else in between is lost. That's why you should not use it for realtime data without extra processing beforehand.
Posts: 176
Threads: 42
Joined: Jul 2015
Reputation:
2
Ok. I was not aware of that. This means that trending of anything that changes rapidly is not incorrect. What should i do to get it to be more accurate? The best would be to take a sample every minute and then use the 5 values to make one 5 minute sample. Or 10 to make 10 min sample. Is this possible and then make a trend with the data?
Posts: 49
Threads: 3
Joined: May 2018
Reputation:
0
23.08.2023, 12:45
(This post was last modified: 23.08.2023, 12:49 by fabiorusco.)
Hallo,
I need know how time it's rained in the last 24 hours (for garden irrigation), I thinked to use the trend about rain address of weather station, with 15 minutes of perdiod. I need keep continuosly only the last 48 sample and sum all the values (FIFO). If the result is more then 24 I don't start the irrigation. How I can do it?
Thank you and best regards.
Fabio Rusconi
Posts: 4643
Threads: 24
Joined: Aug 2017
Reputation:
207
Try this, change test2 to your trend name.
Code: require('trends')
-- get data for the past day
dates = {}
dates['start'] = os.date('*t')
dates['start'].day = dates['start'].day - 1
dates['end'] = os.date('*t')
-- fetch previous value
day = trends.fetch('test2', dates)
rain=0
-- for i = START, STOP, STEP
for i = 1, 48, 1 do
rain=rain + day[i]
end
log(rain)
------------------------------
Ctrl+F5
Posts: 49
Threads: 3
Joined: May 2018
Reputation:
0
(23.08.2023, 13:43)Daniel Wrote: Try this, change test2 to your trend name.
Code: require('trends')
-- get data for the past day
dates = {}
dates['start'] = os.date('*t')
dates['start'].day = dates['start'].day - 1
dates['end'] = os.date('*t')
-- fetch previous value
day = trends.fetch('test2', dates)
rain=0
-- for i = START, STOP, STEP
for i = 1, 48, 1 do
rain=rain + day[i]
end
log(rain)
I modify the script :
-- Verifico numeri quarti d'ora di pioggia ultime 24 ore
require('trends')
-- Prelevo i dati ultime 24 ore
dates = {}
dates['start'] = os.date('*t')
dates['start'].day = dates['start'].day - 1
dates['end'] = os.date('*t')
-- fetch previous value
day = trends.fetch('Andamento_pioggia', dates)
rain=0
-- for i = START, STOP, STEP
for i = 1, 48, 1 do
rain=rain + day[i]
end
grp.write('0/2/226',rain)
log(rain)
The trend this morning is:
from 0 to 9.45 all 15 minutes the trend it's 1, but the rain indicate 0.
What's the mistake?
Posts: 4643
Threads: 24
Joined: Aug 2017
Reputation:
207
What type of trend do you use?
------------------------------
Ctrl+F5
Posts: 49
Threads: 3
Joined: May 2018
Reputation:
0
(09.02.2024, 09:03)Daniel Wrote: What type of trend do you use? see attacched:
Posts: 49
Threads: 3
Joined: May 2018
Reputation:
0
Hallo,
someone can help me, please.
Fabio
Posts: 4643
Threads: 24
Joined: Aug 2017
Reputation:
207
Log the object to see what value it actually is. Manually change it to 0 if is 1.
------------------------------
Ctrl+F5
Posts: 49
Threads: 3
Joined: May 2018
Reputation:
0
Hallo,
I understad the problem:
the trend.fetch use the start time at 0 hour and 0 minutes. I need that the start time will be the same of the time that run the script (the day will be the day before).
Othewise I have the number of slot with rain of the last day and not in the last 24 hours.
It's possible solve the problem?
Best regards
Posts: 7758
Threads: 42
Joined: Jun 2015
Reputation:
447
Posts: 49
Threads: 3
Joined: May 2018
Reputation:
0
(04.09.2024, 14:35)admin Wrote: See this thread: https://forum.logicmachine.net/showthread.php?tid=5475
Code: require('trends')
-- get data for the past day
date = os.date('*t')
time = os.time(date, true) -- UTC timestamp
log(time)
datarange = {
['start'] = time - 86400,
['end'] = time,
}
log(datarange)
alert('passo 0')
-- fetch previous value
day = trends.fetch('Andamento_Pioggia_Valore_Unico', datarange, 900, true)
log(day)
alert('passo a')
rain=0
-- for i = START, STOP, STEP
for i = 1, 96, 1 do
rain=rain + day[i]
end
alert('passo b')
log(rain)
I want, in the last 24 hours, steps are 15 min (900 sec), read in how many quarter of hour have rain. With the script above alert '(passo a') don't is showed. Can someone tell where is my mistake please?
|