Counting active sensors or adding numeric values of sensors

Hi

I'm trying to create an In-Memory numeric value to represent the heating demand within a property.

Is it possible to use rules to either...

Count a regex selection of active sensors and push that number into an In-Memory command.

Or...

Can the numeric values of a regex selection be added together and the total be pushed into an In-Memory commamd?

The resulting value will provide management feedback for heating demand, then they'll decide if or when multiple boilers should be activated via some kind of rule.

Many thanks in advance,

Stuart

Hi,

on both questions the answer is yes. It is all possible and much more with rules. I’ve posted some examples with Smappee integration https://github.com/openremote/Documentation/wiki/Smappee

Look on this rule, which is from the Smappee integration:

rule "--Smappee: active power"
when
  exists SmappeeApplianceCopy()
  Number($power: doubleValue) from accumulate(SmappeeApplianceCopy($p: power>0), sum($p))
  Number($count: intValue) from accumulate($i:SmappeeApplianceCopy(power>0), count($i))
then
  execute.command("VACTIVEPOWER", $power+" W ("+$count+")");
end

``

This rule counts all appliances detected by Smappee which are active at the moment and stores a string in the virtual in-memory variable VACTIVEPOWER. The string looks like “1100 W (3)”, where 1100 is a sum of all appliances power and 3 is number of active appliances.

Kind regards,

Michal

Thanks for that Michal :slight_smile:

The only part I'm not sure about is how does your set of rules know how many Smappee devices to count?

If I (my client) has 11 zones with a thermostat in each, that would equate to 11 Velbus sensors within OpenRemote.

For example:-

Bed1-heatcall
Bed2-heatcall
Bed3-heatcall
WC-heatcall
Bathroom-heatcall
Landing-heatcall
Front-heatcall
Hallway-heatcall
Dayroom-heatcall
Dining-heatcall
Kitchen-heatcall

Should the rule use a regex to compile / count the number of sensors that == "pressed"?

rule "heatcall_count"

when
    $evt:Event(source matches "^.*-heatcall", $source : source)
then

    String buttonStatus = $evt.getValue().toString();
    boolean isActive = buttonStatus != null && buttonStatus.equalsIgnoreCase("pressed");

    System.out.println("Heatcall Status Change '" + $source + "': " + buttonStatus);

//How does the rule count how many sensors == pressed ?

// Would this line work?

  Number($count: intValue) from accumulate($i:buttonStatus, count($i))

    // EXECUTE ANY COMMANDS BY USING THEIR NAME AND VALUE TO SET
    // ADD ADDITIONAL COMMANDS AS REQUIRED

    then
    {
        execute.command("heatdemand", $count);

end

I think that the rule should be (not tested):

rule"heatcall_count"
when
Number($count: intValue) from accumulate($i:Event(source matches “^.*-heatcall$”, value==“pressed”), count($i))
then
execute.command(“heatdemend”,$count);
end

``

Arrrrrrr :slight_smile:

That looks a lot easier on the eye.

I'll run it up and let you know :slight_smile:

Cheers :beer: :smiley:

Thanks Michal,

That rules works like a charm.

Now all I have to do is decode what the client wants to do with the values :wink:

Cheers,

Stuart