OH3 [SOLVED] Exec Binding does not execute script

As a matter of fact, this topic is only conceptually a migration issue, as I completely developed a new solution migrating from OH2 to OH3.
I have some Python scripts activated by Exec Things/Channels/Items. They are similar but one of these is not executed without any error, simply it is not executed and I do not understand why, I tried many different Thing parameter settings, and also using exec commandline, but always the same behaviour, no errors, no results.
The Thing definitions are the following:

Bridge mqtt:broker:MqttMain [ host="192.xxx.xxx.xxx", secure=false ]
{
    Thing topic MqttSpeakersVolume "Mqtt Speakers Volume" {
    Channels:
        Type string: SpeakersVolumeChannel "Speakers Volume Channel" [ stateTopic="house/speakers/volume" ]
    }
    Thing topic MqttSpeakersMusic "Mqtt Speakers Music" {
    Channels:
        Type string: SpeakersMusicChannel "Speakers Music Channel" [ stateTopic="house/speakers" ]
    }
    Thing topic MqttSpeakersSong "Mqtt Speakers Song" {
    Channels:
        Type string: SpeakersSongChannel "Speakers Song Channel" [ stateTopic="house/speakers/song" ]
    }
}
Thing exec:command:change_volume [command="python3 /etc/openhab/scripts/play_speakers_volume.py %2$s",  interval=0, timeout=15, autorun=true]
Thing exec:command:play_music [command="python3 /etc/openhab/scripts/play_speakers_music.py %2$s",  interval=0, timeout=15, autorun=false]
Thing exec:command:play_song [command="python3 /etc/openhab/scripts/play_speakers_song.py %2$s",  interval=0, timeout=15, autorun=false]type or paste code here

The first two scripts work fine, the third does not work, Items of the last thing (the others are similar):

tyString Song300 "Mqtt Speakers Song" { channel="mqtt:topic:MqttMain:MqttSpeakersSong:SpeakersSongChannel"}
String RF300args { channel="exec:command:play_song:input" }
Switch RF300switchrun { channel="exec:command:play_song:run", autoupdate="false" }
String RF300out{ channel="exec:command:play_song:output" }pe or paste code here

The rules:

rule "Set song on speakers"
when
    Item Song300 received update
then
    logInfo ("inizio:  ", "Set song on speakers")
    logInfo ("prima di esecuzione ", Song300.state.toString)
    createTimer(now.plusSeconds(300),  [ |
    	RF300args.sendCommand(Song300.state.toString)
    ])

    //var result=executeCommandLine("nohup", "-u", "/usr/bin/python3", "/etc/openhab/scripts/play_speakers_song.py", Song300.state.toString)
    logInfo ("after the input command ", "AAA  A RF300args : " )		//+result)
end

rule "Begin play song execution"
when
   Item RF300args received command
then
    logInfo ("inizio: ", "Begin play song execution")
      // Separately triggering RUN allows subsequent executions with unchanged parameter %2
      // which autorun does not.
	if (RF300switchrun.state != ON) {
            		RF300switchrun.sendCommand(ON)
      		logInfo("Your command non ON: ", "RF300args.state")
         		// the Run indicator state will go ON shortly, and return OFF when script finished
   		}else{
      		logInfo("Your command exec", "Script already in use, skipping execution.")
   }
end

rule "Play song results"
when
   Item RF300out received update
then
   logInfo ("inizio ", "Play song results")
   logInfo("comando di esecuzione musica ", "risultato: " + RF300out.state.toString )
end

//---------------------------------------------------------------------------------------------------------------------------------------------------------------
//-----------------------------------------------------------------------------------------------------------------------
rule "Set music on speakers"
when
    Item Music30 received update
then
    logInfo ("prima di esecuzione ", Music30.state.toString)
    logInfo ("prima di esecuzione2 ", " dddddddddd")
    RF30args.sendCommand(Music30.state.toString)
//    RF33args.sendCommand("1.0")
    logInfo ("dopo di esecuzione ", "AAAAAAAAAABBBBBBBB ")
end
rule "Begin play music execution"
when
   Item RF30args received command
then
      // Separately triggering RUN allows subsequent executions with unchanged parameter %2
      // which autorun does not.
   if (RF30switchrun.state != ON) {
      RF30switchrun.sendCommand(ON)
      logInfo("Your command non ON: ", "RF30args.state")
         // the Run indicator state will go ON shortly, and return OFF when script finished
   }else{
      logInfo("Your command exec", "Script already in use, skipping execution.")
   }
end

Results in openhab.log

2021-03-11 09:37:06.357 [INFO ] [.openhab.core.model.script.inizio:  ] - Set song on speakers
2021-03-11 09:37:06.361 [INFO ] [re.model.script.prima di esecuzione ] - prove/doorbell.mp3
2021-03-11 09:37:06.367 [INFO ] [odel.script.after the input command ] - AAA  A RF300args : 
type or paste code here

RF300switchrun state remains ON.
I’d be very grateful if someone can help me to solve the issue.

Compare and contrast

Sorry, I copied a rule that is not relevant for the topic, the relevant one is the rule “Begin play song execution” when Item RF300args received command …

You’ve not shown the log that shows this rule triggering, have a look in your events.log for the Item command event.

If your switch has got set ON during editing etc., your rule will never start the exec Thing, so the binding will never update the run switch.
Try setting it OFF by hand.

The behavior is quite strange, I created a switch and a sitemap to force the OFF, but on the UI remained ON, so I restarted Openhab and I had a NULL value, but again the script does not run, and the RF300args remains ON
Here the events.log (the file to be played is repeated three times)

2021-03-11 12:38:55.006 [INFO ] [openhab.event.ItemCommandEvent      ] - Item 'test' received command ON
2021-03-11 12:38:55.019 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'test' changed from OFF to ON
2021-03-11 12:38:56.760 [INFO ] [openhab.event.ItemCommandEvent      ] - Item 'RF300switchrun' received command OFF
2021-03-11 12:39:46.080 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Song300' changed from NULL to prove/doorbell1.mp3
2021-03-11 12:39:51.153 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Song300' changed from prove/doorbell1.mp3 to prove/doorbell2.mp3
2021-03-11 12:39:56.246 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Song300' changed from prove/doorbell2.mp3 to prove/doorbell.mp3
2021-03-11 12:44:46.123 [INFO ] [openhab.event.ItemCommandEvent      ] - Item 'RF300args' received command prove/doorbell.mp3
2021-03-11 12:44:46.185 [INFO ] [penhab.event.ItemStatePredictedEvent] - Item 'RF300args' predicted to become prove/doorbell.mp3
2021-03-11 12:44:46.205 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'RF300args' changed from NULL to prove/doorbell.mp3
2021-03-11 12:44:51.174 [INFO ] [openhab.event.ItemCommandEvent      ] - Item 'RF300args' received command prove/doorbell.mp3
2021-03-11 12:44:51.184 [INFO ] [penhab.event.ItemStatePredictedEvent] - Item 'RF300args' predicted to become prove/doorbell.mp3
2021-03-11 12:44:56.274 [INFO ] [openhab.event.ItemCommandEvent      ] - Item 'RF300args' received command prove/doorbell.mp3
2021-03-11 12:44:56.285 [INFO ] [penhab.event.ItemStatePredictedEvent] - Item 'RF300args' predicted to become prove/doorbell.mp3

But I’ll bet this rule is still not triggered.
I’ve just noticed the trap you fell into - nothing to do with exec.
It turns out it’s a good job you posted the RF30 rule versions too :crazy_face:

Every rule in xxx.rules files must have a system-wide unique “name”.
Otherwise a later
rule "my rule"
replaces an earlier one, without error (maybe you meant to edit it).

I can’t see the duplicate rule name in what you’ve shown us,but I’ll bet there is one?

You mean the system does not recognize that RF300args is different from RF30args or that “Begin play song execution” is different from “Begin play music execution”?

Here the entire .rules file



rule "change to OFF song args"
when
    Item test changed to ON
then
    	logInfo ("test ", "change to OFF song args")
	RF300switchrun.sendCommand(OFF)

end
//-----------------------------------------------------------------------------------------------------------------------
rule "Set song on speakers"
when
    Item Song300 received update
then
    logInfo ("inizio:  ", "Set song on speakers")
    logInfo ("prima di esecuzione ", Song300.state.toString)
    createTimer(now.plusSeconds(300),  [ |
    	RF300args.sendCommand(Song300.state.toString)
    ])

    //var result=executeCommandLine("nohup", "-u", "/usr/bin/python3", "/etc/openhab/scripts/play_speakers_song.py", Song300.state.toString)
    logInfo ("after the input command ", "AAA  A RF300args : " )		//+result)
end

rule "Begin play song execution"
when
   Item RF300args received command
then
    logInfo ("inizio: ", "Begin play song execution")
      // Separately triggering RUN allows subsequent executions with unchanged parameter %2
      // which autorun does not.
	if (RF300switchrun.state != ON) {
            		RF300switchrun.sendCommand(ON)
      		logInfo("Your command non ON: ", "RF300args.state")
         		// the Run indicator state will go ON shortly, and return OFF when script finished
   		}else{
      		logInfo("Your command exec", "Script already in use, skipping execution.")
   }
end

rule "Play song results"
when
   Item RF300out received update
then
   logInfo ("inizio ", "Play song results")
   logInfo("comando di esecuzione musica ", "risultato: " + RF300out.state.toString )
end

//---------------------------------------------------------------------------------------------------------------------------------------------------------------
//-----------------------------------------------------------------------------------------------------------------------
rule "Set music on speakers"
when
    Item Music30 received update
then
    logInfo ("prima di esecuzione ", Music30.state.toString)
    logInfo ("prima di esecuzione2 ", " dddddddddd")
    RF30args.sendCommand(Music30.state.toString)
//    RF33args.sendCommand("1.0")
    logInfo ("dopo di esecuzione ", "AAAAAAAAAABBBBBBBB ")
end
rule "Begin play music execution"
when
   Item RF30args received command
then
      // Separately triggering RUN allows subsequent executions with unchanged parameter %2
      // which autorun does not.
   if (RF30switchrun.state != ON) {
      RF30switchrun.sendCommand(ON)
      logInfo("Your command non ON: ", "RF30args.state")
         // the Run indicator state will go ON shortly, and return OFF when script finished
   }else{
      logInfo("Your command exec", "Script already in use, skipping execution.")
   }
end

rule "Play music results"
when
   Item RF30out received update
then
      // Logging of raw command line result
   logInfo("comando di esecuzione musica ", "risultato: " + RF30out.state.toString )
      // If the returned string is just a number it can be parsed
      // If not, a regex or another transformation could be used
   //YourNumber.postUpdate(Integer::parseInt(yourcommand_Out.state.toString) as Number)
   //RF30args.sendCommand("")
   //RF30switchrun.sendCommand(OFF)
   //Music30.sendCommand("")
end

//---------------------------------------------------------------------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------------------------------------------------------------
rule "Modifica volume speakers"
when
    Item Volume33 received update
then
    logInfo ("inizio  ", "Modifica volume speakers")
    logInfo ("prima di esecuzione ", Volume33.state.toString)
    RF33args.sendCommand(Volume33.state.toString)
//    RF33args.sendCommand("1.0")
    logInfo ("dopo invio arg ", "AAAAAAAAAA ")
end

rule "Begin modifica volume execution"
when
   Item RF33args received command
then
      // Separately triggering RUN allows subsequent executions with unchanged parameter %2
      // which autorun does not.
   if (RF33switchrun.state != ON) {
      RF33switchrun.sendCommand(ON)
      logInfo("Your command non ON: ", Volume33.state.toString)
         // the Run indicator state will go ON shortly, and return OFF when script finished
   }else{
      logInfo("Your command exec", "Script already in use, skipping execution.")
   }
end

rule "modifica volume results"
when
   Item RF33out received update
then
      // Logging of raw command line result
   logInfo("Fine script modifica volume ", "Raw result: " + RF33out.state )
      // If the returned string is just a number it can be parsed
      // If not, a regex or another transformation could be used
   //YourNumber.postUpdate(Integer::parseInt(yourcommand_Out.state.toString) as Number)

end

No, that’s fine of course.

My suspicion is (still) that you have some other rule named “Begin play song execution” (maybe in another file).
I think it works on some hashcode really, but I doubt those two names would give the same hash?

There is very little that can go wrong with

when you know you have the triggering condition

and yet you do not see the log message.
That’s assuming your xxx.rules file loads without error, this will be visible in your openhab.log after editing.

About the only other possibility is that there is some whitespace control character in the rule triggering line, so that what appears to us as RF300args is something else that doesn’t match the Item name,like RF300<CR>args

A test might be to type in a completely new rule, no copy-paste.

rule "test RF300 command"
when
   Item RF300args received command
then
    logInfo ("test", "RF300 commanded")
end

For your information, I changed all the names of the relevant items and all the names of the relevant rules and now the system executes the script (there is a permission error, but this is not related to the original issue).
Sincerely I could not find any hidden characters nor same rule name, anyway this issue is solved, so I put Solved in the topic title

1 Like

Thanks for your support!!