Thank you very much Michal!
Had to chew on this one - and the code looks ugly as hell - but it does what it should:
the “else” command didn´t work, so I put in 2 rules. But the oldPrice had no initial value, so I created a 3rd rule to initially set the old value.
But again - thank you Michal
package org.openremote.controller.protocol;
global org.openremote.controller.statuscache.CommandFacade execute;
import java.util.*;
import java.util.regex.*;
rule “initial”
timer (cron: 0 0 0/1 * * ?)
when
eval(true)
Event(source == “ETH SENSOR”, $val: value)
then
double val = Double.parseDouble($val.toString());
{execute.command(“ETH OLD”, $val.toString());}
end
rule “up”
timer (cron: 0 0/1 * * * ?)
when
eval(true)
Event(source == “ETH SENSOR”, $val: value)
Event(source == “ETH OLD SENSOR”, $oldval: value)
then
double val = Double.parseDouble($val.toString());
double oldval = Double.parseDouble($oldval.toString());
if(val>oldval)
{execute.command(“ETHTREND UP”);}
{execute.command(“ETH OLD”, $val.toString());}
end
rule “down”
timer (cron: 0 0/1 * * * ?)
when
eval(true)
Event(source == “ETH SENSOR”, $val: value)
Event(source == “ETH OLD SENSOR”, $oldval: value)
then
double val = Double.parseDouble($val.toString());
double oldval = Double.parseDouble($oldval.toString());
if(val<oldval)
{execute.command(“ETHTREND DOWN”);}
{execute.command(“ETH OLD”, $val.toString());}
end