Calculate percent of all rollershutter (in .rules file)

Hello to all! :sunny:

I need to calculate the average position of all rollershutter and then make a decision (if > or < about values).

Here the .items

Rollershutter Rollershutter1 "First [%d %%]" .... { knx = .... }
Rollershutter Rollershutter2 "Second [%d %%]" .... { knx = .... }
…etc…

This is a first step and work correctly (.rules):

if ( Rollershutter1.state > 50 ) {
  #ok!
}

but I need something like this:

if  (((Rollershutter1.state +  Rollershutter2.state + Rollershutter3.state + Rollershutter4.state) /10) > 50 ) {
  #???
}

I’ve tested different syntax without results :frowning:

Is is possibile?

Best regards


Sim

I think the easiest way to do this is through a Group.

Group:Rollershutter:AVG gAllShutters

The state of gAllShutters will be the average of the states of all its members.

In the Rules, I think your specific problem is that you may need to cast the state to a DecimalType before you can do math with it.

So your math would look like:

val total = ((Rollershutter1.state as DecimalType) + (Rollershutter2.state as DecimalType) + ...

You should be seeing errors in the logs. That should always be the first place to look when you encounter problems.

Hello,

There is no need to do maths with your single items. If you need to compare all your shutter items against a threshold just use the gAllShutters.

if ( (gAllShutters.state as DecimalType) > 20)
{
  // in average all shutters are above 20 (percent)
}

Andreas

Thank you for the tips!

I will try this way!

Regards

Sim