[Exec] Question about autorun and Exec

Let’s see if I can describe my problem… I’m not quite sure if it’s a bug somewhere or if I’m doing something wrong.

This is about the exec binding under OH3M5. I have a command (or really, a shell script) for sending SMS. I have a Thing that’s configured like this:

UID: exec:command:sendsms
label: Send SMS
thingTypeUID: exec:command
configuration:
  interval: 0
  autorun: true
  command: /usr/local/bin/sendnexmosms %2$s
  timeout: 15

…and I have an Item connected to the input channel, with an Expire timer that updates the state to UNDEF after one second.

Thing is that everything works the first time I change the value of my Item. The command is called and I get my SMS. It also works if I change the value to something different, I get a new SMS. What doesn’t work is if I want to send the same SMS again, then nothing gets triggered.

ie:

  1. The value of the Items is UNDEF
  2. I set the Item to “FIRE!” and everything works
  3. After one second the Item is returned to UNDEF
  4. Sometime later I set the Item to “FIRE!” again. Nothing happens.

Anyone can spot the problem? Shouldn’t the autorun on the Thing make the command run every time the value of the Item changes, even when it actually has had the same value earlier?

Is the change to UNDEF being reflected in the lastexecution channel ?
What about a change to “” or " " and not sending an sms in these cases ?
What about adding e.g. date time to the input string to make it unique and cutting of date time in the script that is being executed ?

No, read the exec binding docs.
Autorun does not care about state of input channel at all, ignores it.
Autorun responds to commands to input channel.
Autorun only responds to different commands, ignores repeated duplicate commands.

That’s a bit counter-intuitive if you ask me. If the state is UNDEF and it gets a command with a value it feels like it should react on this. But I can confirm that changing the expire to not just update the state but send a command makes it work. Problem of course is that it now instead calls my script with no arguments at all when it changes to UNDEF. Guess I’ll simply handle that in the script :stuck_out_tongue:

I’ve no idea why the binding works this way, but it is working as documented.

A common solution is to not use things/channels, but instead have a rule acting on command that in turn does your thing using Exec Action. Action does not care how many times you tell it to do the same thing.

1 Like