[SOLVED] Exec autorun item not working when input updated from rule

This a weird problem that I can’t figure out. My simple config is:

Thing exec:command:monitor [command="/packages/OpenHAB/scripts/monitor.sh %2$s", interval=0, timeout=30, autorun=true]

Switch Monitor_Run      { channel="exec:command:monitor:run" }
String Monitor          { channel="exec:command:monitor:input" }

Switch Test

rule "Test"
when
    Item Test received command
then
    Monitor.sendCommand(receivedCommand)
end

If I send ON to the item Monitor via curl it works fine:

13:25:19.966 [INFO ] [smarthome.event.ItemCommandEvent     ] - Item 'Monitor' received command ON
13:25:19.995 [INFO ] [smarthome.event.ItemStateChangedEvent] - Monitor changed from OFF to ON
13:25:20.030 [INFO ] [smarthome.event.ItemStateChangedEvent] - Monitor_Run changed from OFF to ON
13:25:20.049 [INFO ] [smarthome.event.ItemStateChangedEvent] - Monitor_Run changed from ON to OFF

If I send ON to the item Test the Monitor item gets updated to it but the autorun (& hence the script) doesn’t fire:

13:25:33.721 [INFO ] [smarthome.event.ItemCommandEvent     ] - Item 'Test' received command ON
13:25:33.750 [INFO ] [smarthome.event.ItemStateChangedEvent] - Test changed from OFF to ON
13:25:33.772 [INFO ] [smarthome.event.ItemCommandEvent     ] - Item 'Monitor' received command ON

What am I doing wrong?

Shoudn’t it be

Monitor_Run.sendCommand(receivedCommand)

No, it needs to be the input item to set the ON or OFF argument for the %2$s in the run item. Also, as I mentioned sending ON/OFF directly to the Monitor item via curl works fine and triggers the Monitor_Run item via autorun.

Than try

Monitor.sendCommand(receivedCommand.toString)

That fixed it - thanks!

So what’s the difference between ON and “ON” (as a string)? The event log shows the same thing for both:

Item 'Monitor' received command ON

ON is of an openhab ONOFFType
“ON” is a String

The problem here is the parser (interpreter of the rules language). In your case it has not enough information about what to pass in the sendCommand as an argument. To force the issue, because sendCommand always accepts a string, you need to apply the .toString method to clarify the instruction for the parser.

Thanks. It would be helpful if the event log showed this, like:

Item 'Monitor' received command ON
Item 'Monitor' received command "ON"

That way I would have been able to see that there was a difference and identify the problem.