Exec command issues

I’m having a few issues with my exec commands?


String system_comfort "Restart comfort" {channel="exec:command:system_comfort:run", autoupdate="false"}


Thing exec:command:system_comfort [command="sudo systemctl restart comfort2.service", interval=15, timeout=5, autorun=false]


rule "Restart Comfort"
	Item system_comfort changed to ON or
	Item system_comfort changed to OFF
	if (system_comfort.state == ON)
	system_comfort.sendCommand("sudo systemctl restart comfort2.service")	


sudo systemctl restart comfort2.service

It worked before? i’m not too sure whats going on ?

Any help will be much appreciated

First some easy stuff.

Why trigger the rule when system_comfort changes to OFF if you’re just going to ignore that case and only do something when it’s ON?

Secondly, I don’t think the Exec binding work the way you think it does. Looking at the docs, each Exec Thing has five channels: input, output, exit, run, and lastrun. You’ve linked your Item to the run Channel, but the run Channel needs to be linked to a Switch Item, not a String Item. When you want to pass a String to the script, as a command line argument, you would use a String Item linked to the input Channel and in your command that String would replaced %2$s with the String. You are not passing a String to the command as an argument so you shouldn’t have a String Item at all, just a Switch Item.

So with those changes we get

Switch system_comfort "Restart comfort" {channel="exec:command:system_comfort:run", autoupdate="false"}
rule "Restart Comfort"
	Item system_comfort changed to ON

But what is this whole contraption doing? system_comfort will only ever change to ON when it’s been updated or commanded to be ON. It will only be commanded to be ON if you’ve somewhere sent it a command, such as from the UI or from another rule.

But you’ve got autoupdate=false so the Item won’t change to ON when it receives the command. However, per the binding docs, the Item will be updated to ON when the Exec binding is running the script and as configured, that will happen every 15 seconds. When the script stops running, the Exec binding will update the Switch to OFF.

So the flow will be:

  1. Exec kicks off the script
  2. Exec updates the Switch Item to ON
  3. Rule is triggered
  4. Rule sends ON command to the Switch Item
  5. Exec binding tries to run the script again while it’s still already running the script from step 1
  6. Eventually the script exits or times out and the Exec binding updates the Item to OFF

So you end up running the same script twice at the same time. The second one almost certainly fails because systemctl creates a lock to prevent two commands on the same service from executing at the same time I think.

In other words, your Rule i not accomplishing anything at all and just might be causing problems. Get rid of it. If it worked before (which I doubt it worked without some sort of complaints in the log) it was a fluke related to the fact that sudo systemctl... is meaningless as a command sent to a Channel expecting a Switch command.

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.