I'm currently using a bespoke windows app to harvest values from Velbus networks and append a CSV file (one file per sensor).
These files are then uploaded once an hour to a webserver, where a JSCanvas script creates interactive graphs.
http://www.cuedup.biz/VGraphing/demoui/
I'd like to migrate everything to a slim Linux server and host the JSCanvas scripts locally. Assuming the OR webserver supports the JSCanvas scripts.
(Which will also save the FTP transfer every hour, resulting in more up to the minute graphs)
So my question today is...
If an Echo command like :-
Echo $date,$sensor_value >> energy1.csv
Was used in a SH file, could a rule in OR be used to pass a sensor value to the SH script (whenever the sensor changed?)
I might take it a bit further and use a regex query so that the name of the sensor is used to determine which SH script is used.
Examples :-
Sensor name :- electric_current
SH script :- electric_current.sh
CSV file :- electric_current.csv
Sensor name :- electric_total
SH script :- electric_total.sh
CSV file :- electric_total.csv
Sensor name :- water_current
SH script :- water_current.sh
CSV file :- water_current.csv
Sensor name :- GP01
SH script :- GP01.sh
CSV file :- GP01.csv
Just for reference, I've tried getting the RRD4J graphs to work, but I have the following issues
The sensors aren't being consistently recognised. (Each reboot works with different sensors. Of 4 I'm testing with, it never works with all 4 at the same time)
The graphs that are created are static PNG files, rather than interactive graphs that JSCanvas creates.
Any ideas?
I've read this tutorial and I think I can follow it... With one minor detail..
http://openremote.org/display/docs/OpenRemote+2.0+How+To+-+Execute+Shell+commands
There doesn't appear to be an example of a SH file which accepts the param values.
That really helped :-)
I've created this script and it works, right up until the last line, where I'm trying to get the output appended into a file as defined by the --file variable.
while [ "$#" -gt 0 ]; do
case "$1" in
-v) value="$2"; shift 2;;
-f) file="$2"; shift 2;;
-t) text="$2"; shift 2;;
--value=*) value="${1#*=}"; shift 1;;
--file=*) file="${1#*=}"; shift 1;;
--text=*) text="${1#*=}"; shift 1;;
--value|--file|--text) echo "$1 requires an argument"
>&2; exit 1;;
-*) echo "unknown option: $1" >&2; exit 1;;
*) handle_argument "$1"; shift 1;;
esac
#echo $value
#echo $file
#echo $text
echo $(date +%y%m%d%H%M),$value
#echo $(date +%y%m%d%H%M),$value >> $file
done
Command line might be
./script --value=12344 --file=test.csv
My idea is to create an OR command with the $param feature and then a rule that pushes a sensor's value and name in.
So an energy monitoring sensor might be called electric.csv with a value of 661.65
The resulting command line from the rule would become
script --value=661.65 --file=energy.csv
It turns out that it's much easier than that..
>>$file
Didn't work...(ambiguous output)
However..
>> ${file}.csv
Does :-)
I've got a heap of JSCanvas graphs working with the OR webserver, using old data from the windows app.
So next...
Is to create the elements in OR to get the data pushed into some csv files....
I'm going to try this rule to harvest the data sources from any sensor that matches the pattern
*.graph
The idea is to create command lines like this :-
csvmaker.sh --value=123445 --file=electric_instant.graph
The OR command has this line
--value=${param}
###################
package org.openremote.controller.protocol;
global org.openremote.controller.statuscache.CommandFacade execute;
import java.util.*;
import java.util.regex.*;
// JSCanvas
// the aim of this rule is that any device can have it's output graphed
// by mapping it to a Custom Sensor, where any numeric value is passed, or a text value is mapped to a given number
rule "any .graph sensor"
when
$evt:Event(source matches "^.*.graph\\d+$", $source : source)
then
// This next line will extract the value of the sensor and hold it in a string
String Status = $evt.getValue().toString();
System.out.println("JSCanvas Graph datasource Status Change '" + $source + "': " + Status);
try {
execute.command("csvmaker", Status + " --file=" + source);
} catch (Exception e) {
System.out.println("############## JSCanvas datasource error : " + e.getMessage() + " #################");
return;
}
end
There's an error in that rules :-(
What does.... "Source can not be resolved to a variable" mean ?
execute.command("csvmaker", Status + " --file=" + source)
Should be: -
execute.command("csvmaker", Status + " --file=" + $source)
By creating a regex rule I now have all the csv files I need to use with JSCanvas graphing code.
Or I can pull the csv files into a spreadsheet if I want to analyse them.
Okay....
I'm going to try this rule to harvest the data sources from any sensor that matches the pattern*.graph
The idea is to create command lines like this :-
csvmaker.sh --value=123445 --file=electric_instant.graph
The OR command has this line
--value=$param
Sorry, my apologies.
There is a tiny tweak that I haven't amended in these posts.
The correct format for $param is to enclose it.
So it should read --value=${param}
That applies to any use of ${param} in OpenRemote
For reference, this topic was expanded in another thread...
ule "Get WT Factors"no-loop truetimer(cron: 5 0/30 8-18 * * ?)// duration 990when$wt_factors: Water_Tank_Factors()CustomState( source == "Roof_Temp_Sensor", $val_T: value)CustomState( source == "Roof_Brightness_Sensor", $val_L: value)then$wt_factors.setAcc_temp ($wt_factors.getAcc_temp() + Float.valueOf($val_T.toString()));update ( $wt_factors );$wt_factors.setAcc_light ($wt_factors.getAcc_light() + Float.valueOf($val_L.toString()));update ( $wt_factors );$wt_factors.setAcc_sigma ($wt_factors.getAcc_sigma() + (Float.valueOf($val_T.toString() * 1400 )+ Float.valueOf($val_L.toString());update ( $wt_factors );System.out.println ( _TimeStamp()+ ": Daily Temp accomulation: " + $wt_factors.getAcc_temp());System.out.println ( _TimeStamp()+ ": Daily Light accomulation: " + $wt_factors.getAcc_light());System.out.println ( _TimeStamp()+ ": Daily Light + Temp accomulation: " + $wt_factors.getAcc_sigma());// execute.command("Write Light and Temp Coefficient", String.format(java.util.Locale.US,"%.1f", $wt_factors.getAcc_sigma()));execute.command("Write Light and Temp Coefficient", String.valueOf($wt_factors.getAcc_sigma()));end
It's great to see that you want to use this.
Unfortunately I'm not a coder, so what you're doing with the rules is beyond me.
Using my electrical head, I'd ask if you've halved the setup to confirm that the ${param} part is working?
If you just link the command to a slider it should pass the slider value to the script.
One thing to be aware of is that there is a bizarre bug that requires the whole machine to be rebooted before any changes to command line things get activated.
I hope this helps.
I just reboot the machine as it's only ever running OpenRemote and a Velbus server ;-)
@Nir,
I'm glad it's all working for you.
Maybe it was something to do with restarting the controller between edits of the shell execution command.
Good luck with adding your other components.