Rule to resend states

I have rule which should resend some states and it looks like

gMapDB.members.forEach(s | s.sendCommand(s.state) )
But unfortunately I get this ERROR.

2016-08-31 19:20:16.089 [ERROR] [o.o.c.s.ScriptExecutionThread ] - Error during the execution of rule 'Init Routine': Could not invoke method: org.openhab.model.script.actions.BusEvent.sendCommand(org.openhab.core.items.Item,java.lang.Number) on instance: null
Does anybody know, why this won’t work?
Is there a better way to realize a resend of items within a group?

What type of Item is in gMapDB? There is an edge case where the way the inheritance is set up for State types confuses OH. Try using

s.sendCommand(s.state.toString)

If this is indeed the problem, the toString will resolve it.

1 Like

Hi Rich,
thanks for your quick reply. When I start the rule, unfortunately I don’t see any member of the gMapDB group in the events.log, which should respond on the sendCommand.There must be something wrong with my loop. Do you see any obvious?
Regards,
Michael

If the sendCommand is failing then you would not see anything in your events.log. That is why I suggested using toString.

There is nothing I can tell wrong with your loop. You can add a logInfo to the loop to see it executing. Given the error I’m certain the problem is with the sendCommand.

I used .toString …
gMapDB.members.forEach(s |
s.sendCommand(s.state.toString)
logInfo(“Info”, s.state.toString)
)
Even logInfo doesn’t output anything. It seems, that the loop is ignored.
gMapDB contains at least 30 members …

Any further idea?

Put the logInfo before the sendCommand. The first error encountered with sendCommand will cause the rule to exit.

Doesn’t work either … anyway, thanks for your help.
I think I’ll give up. I don’t want to waste your time!

The last thing it could be as far as I can see is if gMapDB doesn’t exist or it has no members. Look for typos in your Items file is all I can think of. Good luck.

Rich,
thanks a lot for patience. Now it works, and of course, it was my fault.
The rule wasn’t triggered, but the toString addition was necessary, too.
Have a nice evening.

Good to hear it is working; maybe you want to close this thread and select a solution… and even share some love. :slight_smile:

The final solution to resend a command for members of a group is:

gMapDB.members.forEach(s | 
       s.sendCommand(s.state.toString)
)