<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[How to setup and event on rate of change?]]></title><description><![CDATA[<p dir="auto">I'd like to be able to setup an alarm that sends an email if the value changes by a certain amount over a set time.</p>
<p dir="auto">Eg, if the data point drops by more than 20 in 5 mins it should trigger an event. I am trying to detect if someone has started to empty a storage tank and trigger an alert based on this.</p>
<p dir="auto">There is a change event for the data points but it doesn'y have any values or settings.</p>
<p dir="auto">Is this possible to do?</p>
]]></description><link>https://forum.mango-os.com/topic/2373/how-to-setup-and-event-on-rate-of-change</link><generator>RSS for Node</generator><lastBuildDate>Fri, 13 Mar 2026 11:32:15 GMT</lastBuildDate><atom:link href="https://forum.mango-os.com/topic/2373.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 27 Jul 2016 14:43:36 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to How to setup and event on rate of change? on Sat, 30 Jul 2016 03:41:01 GMT]]></title><description><![CDATA[<p dir="auto">Very true. The community definitely makes me take a closer look at many things, which I enjoy.</p>
<p dir="auto">Virtual points can be useful to check if your meta point is behaving as you expect.</p>
<p dir="auto">The blue help icon (?) in sections with scripts has a 'related item' called 'Mango JavaScript' that documents the functions a data point has. Examples are definitely spread around the forum as well. There's a whole section called 'Scripting general discussion'</p>
]]></description><link>https://forum.mango-os.com/post/12247</link><guid isPermaLink="true">https://forum.mango-os.com/post/12247</guid><dc:creator><![CDATA[phildunlap]]></dc:creator><pubDate>Sat, 30 Jul 2016 03:41:01 GMT</pubDate></item><item><title><![CDATA[Reply to How to setup and event on rate of change? on Sat, 30 Jul 2016 03:12:02 GMT]]></title><description><![CDATA[<p dir="auto">No worries Phil, without this interaction you would not have known this so in the end we both benefit from the exchange of data.</p>
<p dir="auto">I am slowly learning Mango and it's pretty impressive what you can do with it. Your only downside of the whole system is the lack of really good documentation on things like the scripting etc. Other than this, with the support on the forum it makes up for this until such time as you have the documentation done.</p>
<p dir="auto">Thanks Terry, That seems to work this time. There are no errors appearing in the log file now. I just need to wait for the sensor to change and then hopefully I can detect the change.</p>
]]></description><link>https://forum.mango-os.com/post/12246</link><guid isPermaLink="true">https://forum.mango-os.com/post/12246</guid><dc:creator><![CDATA[v8dave]]></dc:creator><pubDate>Sat, 30 Jul 2016 03:12:02 GMT</pubDate></item><item><title><![CDATA[Reply to How to setup and event on rate of change? on Fri, 29 Jul 2016 22:27:09 GMT]]></title><description><![CDATA[<p dir="auto">Thanks Terry!</p>
<p dir="auto">Terry's code will work on Java 7 and 8. I guess I've mostly been interacting with Java 8... mine only works on Java 8's JavaScript engine. So, you can convert .length to .size() as per Terry's suggestion and use get() instead of square brackets []. I will try to be more conscious of this in the future when contributing example code snippets.</p>
<p dir="auto">Sorry for the confusion!</p>
]]></description><link>https://forum.mango-os.com/post/12245</link><guid isPermaLink="true">https://forum.mango-os.com/post/12245</guid><dc:creator><![CDATA[phildunlap]]></dc:creator><pubDate>Fri, 29 Jul 2016 22:27:09 GMT</pubDate></item><item><title><![CDATA[Reply to How to setup and event on rate of change? on Fri, 29 Jul 2016 21:28:29 GMT]]></title><description><![CDATA[<p dir="auto">Dave,</p>
<p dir="auto">That last post shows that you are using the statistics method to get the data.  I'll just ignore that and focus on the first problems you were having.  You are expecting the method:</p>
<pre><code>bbl1.pointValuesSince()
</code></pre>
<p dir="auto">to return an Array, but it actually returns a Java style ArrayList.  The difference is that ArrayLists have a method called size() instead of the member length and accessing the values is done via get(index).</p>
<p dir="auto">So here is an updated version of your script to run using an array list instead of an array:</p>
<pre><code>var data = bbl1.pointValuesSince(new Date().getTime() - 5*60*1000); //Five minutes in milliseconds
if( data.size() &lt;= 1 ) //we have the same edge conditions for our range
   return false;
var firstValue = data.get(0);
var changeThreshhold = -20; //so, this would mean that if any point in the period it is more than
for( var k = 1; k &lt; data.size(); k+=1 ) {
  if( firstValue.value - data.get(k).value &lt; changeThreshhold)
    return true;
}
return false;
</code></pre>
<p dir="auto">Hope this helps.</p>
]]></description><link>https://forum.mango-os.com/post/12244</link><guid isPermaLink="true">https://forum.mango-os.com/post/12244</guid><dc:creator><![CDATA[terrypacker]]></dc:creator><pubDate>Fri, 29 Jul 2016 21:28:29 GMT</pubDate></item><item><title><![CDATA[Reply to How to setup and event on rate of change? on Fri, 29 Jul 2016 15:17:07 GMT]]></title><description><![CDATA[<p dir="auto">With .get(0) I get this error.</p>
<pre><code>ERROR 2016-07-29 08:13:13,576 (com.serotonin.m2m2.meta.JavaScriptPointLocatorRT.executeImpl:54) - sun.org.mozilla.javascript.EcmaError: TypeError: Cannot find function get in object {minimumValue: 99.05402923333332, minimumTime: 1469804893540, maximumValue: 99.568, maximumTime: 1469805193538, average: 99.15065249671122, sum: 397.38296884523055, count: 4, delta: 0.5139707666666737, integral: 29745.195749013365, firstValue: 99.05402923333332, firstTime: 1469805036550, lastValue: 99.568, lastTime: 1469805193538, periodStartTime: 1469804893540, periodEndTime: 1469805193540}. (&lt;Unknown Source&gt;#9) in &lt;Unknown Source&gt; at line number 9 in &lt;Unknown Source&gt; at line number 9 
javax.script.ScriptException: sun.org.mozilla.javascript.EcmaError: TypeError: Cannot find function get in object {minimumValue: 99.05402923333332, minimumTime: 1469804893540, maximumValue: 99.568, maximumTime: 1469805193538, average: 99.15065249671122, sum: 397.38296884523055, count: 4, delta: 0.5139707666666737, integral: 29745.195749013365, firstValue: 99.05402923333332, firstTime: 1469805036550, lastValue: 99.568, lastTime: 1469805193538, periodStartTime: 1469804893540, periodEndTime: 1469805193540}. (&lt;Unknown Source&gt;#9) in &lt;Unknown Source&gt; at line number 9 in &lt;Unknown Source&gt; at line number 9

</code></pre>
]]></description><link>https://forum.mango-os.com/post/12241</link><guid isPermaLink="true">https://forum.mango-os.com/post/12241</guid><dc:creator><![CDATA[v8dave]]></dc:creator><pubDate>Fri, 29 Jul 2016 15:17:07 GMT</pubDate></item><item><title><![CDATA[Reply to How to setup and event on rate of change? on Fri, 29 Jul 2016 15:06:51 GMT]]></title><description><![CDATA[<p dir="auto">It's running on a Centos system and the "java -version" command gives me this error.</p>
<pre><code>Error occurred during initialization of VM
Could not reserve enough space for object heap
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.
</code></pre>
<p dir="auto">I have Mango running as a service on this machine. Java is install and running otherwise Mango won't run.</p>
]]></description><link>https://forum.mango-os.com/post/12240</link><guid isPermaLink="true">https://forum.mango-os.com/post/12240</guid><dc:creator><![CDATA[v8dave]]></dc:creator><pubDate>Fri, 29 Jul 2016 15:06:51 GMT</pubDate></item><item><title><![CDATA[Reply to How to setup and event on rate of change? on Fri, 29 Jul 2016 15:01:13 GMT]]></title><description><![CDATA[<p dir="auto">It works fine for me, so, I wonder if it's a Java version issue.</p>
<p dir="auto">Judging from that error message, I would try using data.get(0) instead of data[0]</p>
<p dir="auto">Can you run "java -version" on the command line and report the result?</p>
]]></description><link>https://forum.mango-os.com/post/12239</link><guid isPermaLink="true">https://forum.mango-os.com/post/12239</guid><dc:creator><![CDATA[phildunlap]]></dc:creator><pubDate>Fri, 29 Jul 2016 15:01:13 GMT</pubDate></item><item><title><![CDATA[Reply to How to setup and event on rate of change? on Fri, 29 Jul 2016 14:43:25 GMT]]></title><description><![CDATA[<p dir="auto">Looking at the log file, it is still failing at this line.</p>
<pre><code>var firstValue = data[0];
</code></pre>
<pre><code>ERROR 2016-07-29 07:39:00,004 (com.serotonin.m2m2.meta.JavaScriptPointLocatorRT.executeImpl:54) - sun.org.mozilla.javascript.EvaluatorException: Java class "java.util.ArrayList" has no public instance field or method named "0". (&lt;Unknown Source&gt;#9) in &lt;Unknown Source&gt; at line number 9 in &lt;Unknown Source&gt; at line number 9
</code></pre>
<p dir="auto">I export and send you the file.</p>
]]></description><link>https://forum.mango-os.com/post/12238</link><guid isPermaLink="true">https://forum.mango-os.com/post/12238</guid><dc:creator><![CDATA[v8dave]]></dc:creator><pubDate>Fri, 29 Jul 2016 14:43:25 GMT</pubDate></item><item><title><![CDATA[Reply to How to setup and event on rate of change? on Fri, 29 Jul 2016 14:38:33 GMT]]></title><description><![CDATA[<p dir="auto">Are you getting errors in the log, or just on the script's page? Is it still reporting null at line 4? Did you try a very simple script, just</p>
<pre><code>return false;
</code></pre>
<p dir="auto">And see if it reports success result=false?</p>
<p dir="auto">Well, would it be possible for you to email me the JSON for your Mango and I'll try to find the problem locally? I'd like your whole configuration.</p>
]]></description><link>https://forum.mango-os.com/post/12237</link><guid isPermaLink="true">https://forum.mango-os.com/post/12237</guid><dc:creator><![CDATA[phildunlap]]></dc:creator><pubDate>Fri, 29 Jul 2016 14:38:33 GMT</pubDate></item><item><title><![CDATA[Reply to How to setup and event on rate of change? on Fri, 29 Jul 2016 14:30:16 GMT]]></title><description><![CDATA[<p dir="auto">Hi Phil, it doesn't seem to run. Nothing appears from the debug. I also deleted the jsp directory and still the same.</p>
]]></description><link>https://forum.mango-os.com/post/12236</link><guid isPermaLink="true">https://forum.mango-os.com/post/12236</guid><dc:creator><![CDATA[v8dave]]></dc:creator><pubDate>Fri, 29 Jul 2016 14:30:16 GMT</pubDate></item><item><title><![CDATA[Reply to How to setup and event on rate of change? on Fri, 29 Jul 2016 14:15:36 GMT]]></title><description><![CDATA[<p dir="auto">Yeah, just checking. That script I posted surely runs for me, here's a version of yours with lots of print statements, maybe it will help find the issue?</p>
<pre><code>print("bbl1:");
print(bbl1);
var data = bbl1.pointValuesSince(new Date().getTime() - 5*60*1000); //Five minutes in milliseconds
print("data:");
print(data);
if( data.length &lt;= 1 ) //we have the same edge conditions for our range
   return false;
print("Passed the length condition...");
var firstValue = data[0];
var changeThreshhold = -20; //so, this would mean that if any point in the period it is more than
for( var k = 1; k &lt; data.length; k+=1 ) {
  if( firstValue.value - data[k].value &lt; changeThreshhold)
    return true;
}
return false;
</code></pre>
<p dir="auto">If you see no output, I encourage you to 1) check for updates, 2) clear your browsers cache, 3) delete Mango/work/jsp and then try again.</p>
]]></description><link>https://forum.mango-os.com/post/12235</link><guid isPermaLink="true">https://forum.mango-os.com/post/12235</guid><dc:creator><![CDATA[phildunlap]]></dc:creator><pubDate>Fri, 29 Jul 2016 14:15:36 GMT</pubDate></item><item><title><![CDATA[Reply to How to setup and event on rate of change? on Fri, 29 Jul 2016 13:54:48 GMT]]></title><description><![CDATA[<p dir="auto">I am assuming that the variable is based on the area I circled?<br />
<img src="https://camo.nodebb.org/8ac1bc5623a114af90d04962d44a84d0ea7e2ea9?url=https%3A%2F%2Fi.imgur.com%2FH3cWhNN.jpg" alt="0_1469800445894_Untitled.jpg" class=" img-fluid img-markdown" /></p>
]]></description><link>https://forum.mango-os.com/post/12233</link><guid isPermaLink="true">https://forum.mango-os.com/post/12233</guid><dc:creator><![CDATA[v8dave]]></dc:creator><pubDate>Fri, 29 Jul 2016 13:54:48 GMT</pubDate></item><item><title><![CDATA[Reply to How to setup and event on rate of change? on Fri, 29 Jul 2016 13:42:18 GMT]]></title><description><![CDATA[<p dir="auto">No, I was curious if that's where the error was occurring, not telling you that you needed to install it.</p>
<p dir="auto">Do you get the same error from a very simple script, perhaps just...</p>
<pre><code>return false;
</code></pre>
<p dir="auto">Are you sure your point is in the context as bbl1 (b - b - lower case L - numeral 1)?</p>
]]></description><link>https://forum.mango-os.com/post/12232</link><guid isPermaLink="true">https://forum.mango-os.com/post/12232</guid><dc:creator><![CDATA[phildunlap]]></dc:creator><pubDate>Fri, 29 Jul 2016 13:42:18 GMT</pubDate></item><item><title><![CDATA[Reply to How to setup and event on rate of change? on Fri, 29 Jul 2016 00:06:04 GMT]]></title><description><![CDATA[<p dir="auto">I found the module and installed it and the icon is now present. My scripts still don't seem the be running as there is no output from the print(data) statement.</p>
]]></description><link>https://forum.mango-os.com/post/12230</link><guid isPermaLink="true">https://forum.mango-os.com/post/12230</guid><dc:creator><![CDATA[v8dave]]></dc:creator><pubDate>Fri, 29 Jul 2016 00:06:04 GMT</pubDate></item><item><title><![CDATA[Reply to How to setup and event on rate of change? on Thu, 28 Jul 2016 23:09:02 GMT]]></title><description><![CDATA[<p dir="auto">I don't have that icon. Is this a module I need to install or a setting somewhere?</p>
]]></description><link>https://forum.mango-os.com/post/12229</link><guid isPermaLink="true">https://forum.mango-os.com/post/12229</guid><dc:creator><![CDATA[v8dave]]></dc:creator><pubDate>Thu, 28 Jul 2016 23:09:02 GMT</pubDate></item><item><title><![CDATA[Reply to How to setup and event on rate of change? on Thu, 28 Jul 2016 23:03:44 GMT]]></title><description><![CDATA[<p dir="auto">It would be below the script window, if it ran, where you saw the error. If it didn't, I wonder if you have a global script declared? The global scripts page is this icon: <img src="https://camo.nodebb.org/0089e127b3723f7d02ee86385afca56f7ea45055?url=https%3A%2F%2Fi.imgur.com%2FkyBXuIK.png" alt="0_1469746987325_script-globe.png" class=" img-fluid img-markdown" /></p>
]]></description><link>https://forum.mango-os.com/post/12228</link><guid isPermaLink="true">https://forum.mango-os.com/post/12228</guid><dc:creator><![CDATA[phildunlap]]></dc:creator><pubDate>Thu, 28 Jul 2016 23:03:44 GMT</pubDate></item><item><title><![CDATA[Reply to How to setup and event on rate of change? on Thu, 28 Jul 2016 23:00:29 GMT]]></title><description><![CDATA[<p dir="auto">I've added that but where do I see the output from this?</p>
]]></description><link>https://forum.mango-os.com/post/12227</link><guid isPermaLink="true">https://forum.mango-os.com/post/12227</guid><dc:creator><![CDATA[v8dave]]></dc:creator><pubDate>Thu, 28 Jul 2016 23:00:29 GMT</pubDate></item><item><title><![CDATA[Reply to How to setup and event on rate of change? on Thu, 28 Jul 2016 13:19:48 GMT]]></title><description><![CDATA[<p dir="auto">That is odd....<br />
I would put print(data) at line 2 to investigate.</p>
]]></description><link>https://forum.mango-os.com/post/12222</link><guid isPermaLink="true">https://forum.mango-os.com/post/12222</guid><dc:creator><![CDATA[phildunlap]]></dc:creator><pubDate>Thu, 28 Jul 2016 13:19:48 GMT</pubDate></item><item><title><![CDATA[Reply to How to setup and event on rate of change? on Thu, 28 Jul 2016 13:00:09 GMT]]></title><description><![CDATA[<p dir="auto">Ah yes, so I was. Just trying it now but there is an error about a null value on line 4 which seems strange because it would not get to this line unless there was data.</p>
<pre><code>var data = bbl1.pointValuesSince(new Date().getTime() - 5*60*1000); //Five minutes in milliseconds
if( data.length &lt;= 1 ) //we have the same edge conditions for our range
   return false;
var firstValue = data[0];
var changeThreshhold = -20; //so, this would mean that if any point in the period it is more than
for( var k = 1; k &lt; data.length; k+=1 ) {
  if( firstValue.value - data[k].value &lt; changeThreshhold)
    return true;
}
return false;
</code></pre>
]]></description><link>https://forum.mango-os.com/post/12220</link><guid isPermaLink="true">https://forum.mango-os.com/post/12220</guid><dc:creator><![CDATA[v8dave]]></dc:creator><pubDate>Thu, 28 Jul 2016 13:00:09 GMT</pubDate></item><item><title><![CDATA[Reply to How to setup and event on rate of change? on Thu, 28 Jul 2016 12:25:47 GMT]]></title><description><![CDATA[<p dir="auto">it looks like you are using the scripting data source, instead of a meta data source and putting these scripting in a meta data point.</p>
<p dir="auto">Scripts are intended for a multiple-output control loop. Scripting data source scripts don't contain return statements, they set a point's value with p.set(value, time) or just p.set(value) for the current time.</p>
<p dir="auto">This kind of thing, where we're producing a single answer from perhaps multiple inputs, should be a meta point.</p>
]]></description><link>https://forum.mango-os.com/post/12219</link><guid isPermaLink="true">https://forum.mango-os.com/post/12219</guid><dc:creator><![CDATA[phildunlap]]></dc:creator><pubDate>Thu, 28 Jul 2016 12:25:47 GMT</pubDate></item><item><title><![CDATA[Reply to How to setup and event on rate of change? on Thu, 28 Jul 2016 06:12:37 GMT]]></title><description><![CDATA[<p dir="auto">Hi Phil, I am using a numerical data point. Here is the screen capture. I modified the script as I only need to detect a falling trend.!!</p>
<p dir="auto"><a href="https://i.imgur.com/kIrX3zz.png" rel="nofollow ugc">0_1469686311138_script.png</a></p>
]]></description><link>https://forum.mango-os.com/post/12216</link><guid isPermaLink="true">https://forum.mango-os.com/post/12216</guid><dc:creator><![CDATA[v8dave]]></dc:creator><pubDate>Thu, 28 Jul 2016 06:12:37 GMT</pubDate></item><item><title><![CDATA[Reply to How to setup and event on rate of change? on Thu, 28 Jul 2016 05:34:07 GMT]]></title><description><![CDATA[<p dir="auto">Are you using the scripts as posted or as they arrived in an email notification?</p>
<p dir="auto">I am able to run all of these with a numeric point for p. That looks like a syntax error, which I think I would get regardless of the code path.</p>
]]></description><link>https://forum.mango-os.com/post/12215</link><guid isPermaLink="true">https://forum.mango-os.com/post/12215</guid><dc:creator><![CDATA[phildunlap]]></dc:creator><pubDate>Thu, 28 Jul 2016 05:34:07 GMT</pubDate></item><item><title><![CDATA[Reply to How to setup and event on rate of change? on Thu, 28 Jul 2016 03:19:51 GMT]]></title><description><![CDATA[<p dir="auto">Just trying this now and when I input the script and then click save, I get this error at the bottom.</p>
<pre><code>invalid return
at line -1
</code></pre>
<p dir="auto">I've selected a suitable data point and set its name to p for this test.</p>
]]></description><link>https://forum.mango-os.com/post/12214</link><guid isPermaLink="true">https://forum.mango-os.com/post/12214</guid><dc:creator><![CDATA[v8dave]]></dc:creator><pubDate>Thu, 28 Jul 2016 03:19:51 GMT</pubDate></item><item><title><![CDATA[Reply to How to setup and event on rate of change? on Thu, 28 Jul 2016 02:51:28 GMT]]></title><description><![CDATA[<p dir="auto">Data will be coming from it, won't it? :D</p>
<p dir="auto">A solution some people use for noisy data, to avoid what I was talking about, is to just use averages from time periods to compare instead of raw data, so,</p>
<pre><code>var period = 300000 //5*60*1000 Five minutes
var now = new Date();
var start = now.getTime() - period;
var middle = now.getTime() - period/2;
if( Math.abs( p.getStats(middle, now).average - p.getStats(start, middle).average ) &gt; 5 ) //Threshhold
  return true;
return false;
</code></pre>
<p dir="auto">Depending on your needs or thoughts on your data.</p>
]]></description><link>https://forum.mango-os.com/post/12213</link><guid isPermaLink="true">https://forum.mango-os.com/post/12213</guid><dc:creator><![CDATA[phildunlap]]></dc:creator><pubDate>Thu, 28 Jul 2016 02:51:28 GMT</pubDate></item></channel></rss>