Update displayed picture depending sensors values

Here is my problem, I 'uses a I/O card. The easiest way to see this card would be like an alarm system.

I’m able to get the binary value ouput as: 1 1 1 0 1 1 1 1

For the need of my project, these values will be converted to: On On On Off On On On On

Into the Building Modeler section:

I would like to graphically display the results of those values.

So I set 8 sensors of type switch (On | Off).

I also set a shell command that retrieves these 8 values and filters to return a output of the type On On On Off On On On On.

Here are the details of this command:

Polling interval: 1s

RegularExpression: (on|off)\s(on|off)\s(on|off)\s(on|off)\s(on|off)\s(on|off)\s(on|off)\s(on|off)\s

Sensor names: sensor1;sensor2;sensor3;sensor4;sensor5;sensor6;sensor7;sensor8

Into the UI Designer section:

I have an image for each sensor.

These are typical details for each sensor:

Sensor: sensor1

Sensor State

on: PictureOn.png

off: PictureOff.png

I also have a button to start the process that is connected to the shell command.

This is my understanding: When the shell command is executed it get the values.

These values will change the status of the sensors.

Then depending on the value of the sensor on / off the displayed image change to the value associated with the On / Off.

Obviously there’s missing some things some where because the displayed images don’t change.

Does anyone can give me some help.

Hi,

I wouldn't use shell command for 8 sensors. Personally, I never succeed to drive more than one sensor through a shell command. Moreover, they are very resources heavy. Anyway, here is how I would do this:

1. Create sensor which returns the binary format message.
2. Create 8 in-memory virtual commands of type status and link them with 8 switch sensors.
3. Create a rule which takes the binary value, splits it and sets the 8 in-memory commands.

Kind regards,
Michal

Hi Michal,

I am experiencing a bit the same problems like the topic starter. I have multiple sensors which are updated via shell polling. When I have 2 sensors the system seems to handle well. As soon as I have more the system seems to flip. I tried multiple ways; having 1 status command with all sensors, or multiple status command with each 2 sensors. No succes to get it stable. So I think I’m going for the direction as you suggest.

But do you (or anyone else, willing to help:)) have maybe a suggestion on how to develop the rule for splitting the bin value to the in-mem commands. I have no knowledge of drools or java. All rules I have now are very simple “when sensor = on, then execute command” and only based on examples on the web. So any hints on how to put the value of the sensor to a internal value, split and parse to other sensor are very welcome! I did already some googling but could not find a good example.

Many thanks!!

Hi

I don't know if this helps you...

I've collected some rules and put them on a GitHub page, https://github.com/openremote/Documentation/wiki/OpenRemote-Rules-examples

Cheers,

Stuart

Hi Stuart,

didn’t see that page yet. Very helpful, thx!

I think I can use your example with the RGB LED channels.

I will create 3 virtual commands with command “status” and address a, b and c (when it works more of course). And then each their own sensor, type custom. I think I do not need to put custom state items on them. I will just populate them with the relevant binary value.

Next, I believe following rule should do the trick;

rule “split binary to virtual sensors”

when

$evt:Event( source == “my_binary_sensor”, $val : value)

//my_binary_sensor is splitted by space

//we use when here in fact to capture the change and push the value itself to a variable

then

String valStr = $val.toString();

//probably not needed in my case, but just to be sure

//this if should always be true

if (valStr != null && valStr.length() == 6) {

  String aStr = valStr.substring(0,1);

  String bStr = valStr.substring(2,3);

  String cStr = valStr.substring(4,5);

execute.command(“virtual sts cmd a”; aStr);

execute.command(“virtual sts cmd b”; bStr);

execute.command(“virtual sts cmd c”; cStr);

}

end

rule “do sth when change of a”

when

$evt:Event(source == “virtual sensor a”, value == “1”)

then

execute.command(“do something”);

end

``

Hopefully no syntax or other errors (is there an easy way to do a syntax check for this btw?)

Will try it one of the coming days.

Hello
I only made that GitHub page live last week, so I'm not surprised you haven't seen it :wink:

I'm very glad that it is of use to you.

Please do let me / us know if that rule works for you and if you'd be happy for me to include it in the GitHub page.

Good luck,

Stuart

Hey Stuart,

that explains it:)

just tried the rule. But there is something wrong. Not sure what. Do I miss a package in the start? I tried some different combinations, but no result. The boot log gives a huge error , which starts like this:

ERROR 2017-03-04 09:18:00,690 : Error in rule definition ‘modeler_rules.drl’ : wrong class format

java.lang.RuntimeException: wrong class format

at org.drools.commons.jci.compilers.EclipseJavaCompiler$2.findType(EclipseJavaCompiler.java:260)

at org.drools.commons.jci.compilers.EclipseJavaCompiler$2.findType(EclipseJavaCompiler.java:204)

at org.eclipse.jdt.internal.compiler.lookup.LookupEnvironment.askForType(LookupEnvironment.java:102)

Caused by: org.eclipse.jdt.internal.compiler.classfmt.ClassFormatException

at org.eclipse.jdt.internal.compiler.classfmt.ClassFileReader.(ClassFileReader.java:372)

at org.drools.commons.jci.compilers.EclipseJavaCompiler$2.findType(EclipseJavaCompiler.java:254)

… 54 more

ERROR 2017-03-04 09:23:31,691 : Cannot start event processor ‘Drools Rule Engine’ : null

java.lang.NullPointerException

at org.drools.rule.EvalCondition.equals(EvalCondition.java:169)

at org.drools.reteoo.EvalConditionNode.equals(EvalConditionNode.java:285)

This is what I have in the rule;

(when I comment this rule, other rules are working fine)

package org.openremote.controller.protocol
//package org.openremote.controller.model.event
global org.openremote.controller.statuscache.CommandFacade execute;
//global org.openremote.controller.statuscache.SwitchFacade switches;

//global org.openremote.controller.statuscache.LevelFacade levels;
//import org.openremote.controller.protocol.;
//import org.openremote.controller.model.event.
;
import java.util.;
import java.util.regex.
;

//import java.lang.Float;
//import java.sql.Timestamp;
//import java.util.Date;

rule “split binary to virtual sensors”
when
$evt:Event( source == “alarmbinairsensor”, $val : value)
//my_binary_sensor is splitted by space
//we use when here in fact to capture the change and push the value itself to a variable
then
String valStr = $val.toString();
//probably not needed in my case, but just to be sure
//this if should always be true
if (valStr != null && valStr.length() == 6) {
String aStr = valStr.substring(0,1);
String bStr = valStr.substring(2,3);
String cStr = valStr.substring(4,5);

execute.command(“virtual_sts_aanw”; aStr);
execute.command(“virtual_sts_afw”; bStr);
execute.command(“virtual_sts_vrdr”; cStr);
}
end

``

``

The error java.lang.RuntimeException: wrong class format indicates that you have probably wrong Java version for the controller binaries. Please check versions you are using.

Not sure if I understand exactly what you mean. I have OR 2.1.0. running on a pi (b2), actually already for several years, with multiple (simple) rules active and working.

How can I check the java version? At the time, I installed jdk-8u65-linux-arm32-vfp-hflt.tar.gz. Is that a clue? Do I need to upgrade anything?

Sorry, probably basic stuff that I am missing, but as I said, I have no experience at all with java or Linux, other than running OR and some other packages.

This is the version I am using.

java -version
java version “1.8.0_65”
Java™ SE Runtime Environment (build 1.8.0_65-b17)
Java HotSpot™ Client VM (build 25.65-b01, mixed mode)
How do I know which one is required to enable full functionality of OR and the rules?

Thanks a lot for any suggestion!

That's interesting.

Can you try a 1.6 or 1.7 version?

My machines all run version 1.6, either Oracle or OpenJDK

I finally took the time to continue with this one. Moved to OR 2.6, integrated new commands and now back to the original problem. I took virtualy the same the rule code as before. But at deploying, this gives me the following message in the dev log at deploying the controller:

2017-05-26 21:18:18,355 ERROR [Controller Definition File Watcher for Default Deployer]: Unable to build KieBaseModel:OpenRemoteKBase

Rule Compilation error : [Rule name=‘split binary to virtual sensors’]

org/openremote/controller/protocol/Rule_split_binary_to_virtual_sensors286797998.java (15:915) : Syntax error on token “;”, , expected

org/openremote/controller/protocol/Rule_split_binary_to_virtual_sensors286797998.java (16:962) : Syntax error on token “;”, , expected

org/openremote/controller/protocol/Rule_split_binary_to_virtual_sensors286797998.java (17:1010) : Syntax error on token “;”, , expected

2017-05-26 21:18:18,358 ERROR [Controller Definition File Watcher for Default Deployer]: Rule definition ‘modeler_rules.drl’ could not be deployed. See errors below.

2017-05-26 21:18:18,358 ERROR [Controller Definition File Watcher for Default Deployer]: Rule Compilation error Syntax error on token “;”, , expected

Syntax error on token “;”, , expected

Syntax error on token “;”, , expected

2017-05-26 21:18:23,937 ERROR [Controller Definition File Watcher for Default Deployer]: Unable to build KieBaseModel:OpenRemoteKBase

Rule Compilation error : [Rule name=‘split binary to virtual sensors’]

org/openremote/controller/protocol/Rule_split_binary_to_virtual_sensors286797998.java (15:915) : Syntax error on token “;”, , expected

org/openremote/controller/protocol/Rule_split_binary_to_virtual_sensors286797998.java (16:962) : Syntax error on token “;”, , expected

org/openremote/controller/protocol/Rule_split_binary_to_virtual_sensors286797998.java (17:1010) : Syntax error on token “;”, , expected

2017-05-26 21:18:23,938 ERROR [Controller Definition File Watcher for Default Deployer]: Rule definition ‘modeler_rules.drl’ could not be deployed. See errors below.

2017-05-26 21:18:23,938 ERROR [Controller Definition File Watcher for Default Deployer]: Rule Compilation error Syntax error on token “;”, , expected

Syntax error on token “;”, , expected

Syntax error on token “;”, , expected

Here is the exact rule code:

rule “split binary to virtual sensors”
when
$evt:Event( source == “alarmbinairsensor”, $val : value)
//my_binary_sensor is splitted by space
//we use when here in fact to capture the change and push the value itself to a variable
then
String valStr = $val.toString();
//probably not needed in my case, but just to be sure
//this if should always be true
if (valStr != null && valStr.length() == 6) {
String aStr = valStr.substring(0,1);
String bStr = valStr.substring(2,3);
String cStr = valStr.substring(4,5);

execute.command(“virtual_sts_aanw”; aStr);
execute.command(“virtual_sts_afw”; bStr);
execute.command(“virtual_sts_vrdr”; cStr);
}
end

``

Anyone got a clue? I compared to the sample rules on the github page, but found no syntax differences.

Inside execute.command() you must replace ; with ,

Great! That was it. Thx!!