[SOLVED] OpenHAB2 exec Binding

You’d probably want a rule to do something with your exec linked Items, when you send Power_Plug_Socket_B a command.

thks for the reply this is my rules

rule “Poweroutlet B”
when
Item Power_Plug_Socket_B received command
then
if(receivedCommand == ON) Remote_Send_Args.postUpdate(“00001 3 1”)
else Remote_Send_Args.postUpdate(“00001 3 0”)

Remote_Send.sendCommand(ON)

// wait for the command to complete
while(Remote_Send.state != ON) Thread::sleep(100)

logInfo(“Power_Plug”, "Resuts are: " + Remote_Send_Out.state)
end

That won’t work.
To send parameter data to Exec binding, you must send as command to the ‘input’ channel Item.

The docs weren’t very clear on this, and have been updated recently.

If you are going to trigger execution with the ‘run’ channel, you do not want autorun to be true in your Thing config. That is about triggering from the input channel.

A better way to do this without waiting is to have a separate rule

rule “Poweroutlet B responds”
when
   Item Remote_Send_Out received update
then
   logInfo(“Power_Plug”, "Results are: " + Remote_Send_Out.state.toString)
end

Thanks for your reply i find an other posts with rf433 and exec command i have updated my files with your post for 2s$

powerplugs.rules
import java.util.concurrent.locks.ReentrantLock

val ReentrantLock transmitter = new ReentrantLock

rule “Single Plug”
when
Member of Gplugs received command
// Item Power_Plug_Socket_1 received command or
// Item Power_Plug_Socket_2 received command or
// Item Power_Plug_Socket_3 received command or
// Item Power_Plug_Socket_4 received command
then

logInfo("Power_Plug", "Member " + triggeringItem.name + " to " + receivedCommand)

try {
  // Lock transmitter so other executed rules dont't use it at the same time.
  // Concurrent calls of the rule will wait till the resource is free again.
  transmitter.lock()

  // Get the item which triggered the rule
  // Split the name and get the second part, the number to set as command.
  val num = triggeringItem.name.toString.split("Power_Plug_Socket_").get(1)

  // Set the command which should be executed to the output channel
  // Auto trigger will then execute the Thing.
  if(receivedCommand == ON){
    Remote_Send_Args.sendCommand("00001 " + num +" 1")
  }else{
    Remote_Send_Args.sendCommand("00001 " + num +" 0")
  }

  // Wait for the command to complete
  while(Remote_Send.state != OFF){
    Thread::sleep(100)
  }

  // Mulltiple trigger do not work if there is no break here
  // maybe external skript needs some time to properly free resources.
  Thread::sleep(400)
  logInfo("Power_Plug", Remote_Send_Out.state.toString.replaceAll("\r|\n"," ") )
}catch(Throwable t) {}
finally {
    // Free the resource for the next call.
    transmitter.unlock()
}

end

powerplugs.sitemap
sitemap powerplugs label=“Wireless Poweroutlets”
{
Frame label=“Poweroutlets”
{
Switch item=Gplugs label=“All Power Plugs”
Text item=PlaceHolder label=“” icon=“none”
Switch item=Power_Plug_Socket_1 label=“Power Plug A”
Switch item=Power_Plug_Socket_2 label=“Power Plug B”
Switch item=Power_Plug_Socket_3 label=“Power Plug C”
Switch item=Power_Plug_Socket_4 label=“Power Plug D”
}
}

powerplugs.items
// RF Socket Items
Group:Switch:OR(OFF, ON) Gplugs

Switch Power_Plug_Socket_1 (Gplugs)
Switch Power_Plug_Socket_2 (Gplugs)
Switch Power_Plug_Socket_3 (Gplugs)
Switch Power_Plug_Socket_4 (Gplugs)
String PlaceHolder “”

Switch Remote_Send { channel=“exec:command:remote-send:run” }
String Remote_Send_Args { channel=“exec:command:remote-send:input” }
String Remote_Send_Out { channel=“exec:command:remote-send:output” }

My log
==> /var/log/openhab2/events.log <==
2019-09-22 10:56:53.291 [ome.event.ItemCommandEvent] - Item ‘Power_Plug_Socket_1’ received command ON
2019-09-22 10:56:53.336 [ome.event.ItemCommandEvent] - Item ‘Power_Plug_Socket_2’ received command ON
2019-09-22 10:56:53.390 [ome.event.ItemCommandEvent] - Item ‘Power_Plug_Socket_3’ received command ON
2019-09-22 10:56:53.485 [ome.event.ItemCommandEvent] - Item ‘Power_Plug_Socket_4’ received command ON
2019-09-22 10:56:53.935 [GroupItemStateChangedEvent] - Gplugs changed from ON to OFF through Power_Plug_Socket_1
2019-09-22 10:56:53.978 [vent.ItemStateChangedEvent] - Power_Plug_Socket_1 changed from OFF to ON
2019-09-22 10:56:54.030 [vent.ItemStateChangedEvent] - Power_Plug_Socket_2 changed from OFF to ON
2019-09-22 10:56:54.063 [vent.ItemStateChangedEvent] - Power_Plug_Socket_3 changed from OFF to ON
2019-09-22 10:56:54.087 [vent.ItemStateChangedEvent] - Power_Plug_Socket_4 changed from OFF to ON
2019-09-22 10:56:54.113 [GroupItemStateChangedEvent] - Gplugs changed from OFF to ON through Power_Plug_Socket_4
2019-09-22 11:04:46.486 [ome.event.ItemCommandEvent] - Item ‘Gplugs’ received command ON
2019-09-22 11:04:46.583 [ome.event.ItemCommandEvent] - Item ‘Power_Plug_Socket_1’ received command ON
2019-09-22 11:04:46.647 [ome.event.ItemCommandEvent] - Item ‘Power_Plug_Socket_2’ received command ON
2019-09-22 11:04:46.745 [ome.event.ItemCommandEvent] - Item ‘Power_Plug_Socket_3’ received command ON
2019-09-22 11:04:46.836 [ome.event.ItemCommandEvent] - Item ‘Power_Plug_Socket_4’ received command ON
2019-09-22 11:04:48.112 [ome.event.ItemCommandEvent] - Item ‘Gplugs’ received command OFF
2019-09-22 11:04:48.159 [ome.event.ItemCommandEvent] - Item ‘Power_Plug_Socket_1’ received command OFF
2019-09-22 11:04:48.229 [ome.event.ItemCommandEvent] - Item ‘Power_Plug_Socket_2’ received command OFF
2019-09-22 11:04:48.280 [ome.event.ItemCommandEvent] - Item ‘Power_Plug_Socket_3’ received command OFF
2019-09-22 11:04:48.385 [ome.event.ItemCommandEvent] - Item ‘Power_Plug_Socket_4’ received command OFF
2019-09-22 11:04:48.853 [vent.ItemStateChangedEvent] - Power_Plug_Socket_1 changed from ON to OFF
2019-09-22 11:04:48.909 [vent.ItemStateChangedEvent] - Power_Plug_Socket_2 changed from ON to OFF
2019-09-22 11:04:49.017 [vent.ItemStateChangedEvent] - Power_Plug_Socket_3 changed from ON to OFF
2019-09-22 11:04:49.063 [vent.ItemStateChangedEvent] - Power_Plug_Socket_4 changed from ON to OFF
2019-09-22 11:04:50.585 [ome.event.ItemCommandEvent] - Item ‘Power_Plug_Socket_3’ received command ON
2019-09-22 11:04:50.743 [vent.ItemStateChangedEvent] - Power_Plug_Socket_3 changed from OFF to ON

This is going to become difficult if you change the question every time someone offers an answer.

What are you trying to do now, and what is the problem that you see?

Add some temporary logInfo() to your rule so that you can see progress.

Hi sorry and thanks for your time
i have four power outlet with rf
I can switch them with send command and wiring pi in the terminal with user openhab
When i put this the rule i can switch off or on power outlets maybe a problem with regex ?

rule “Poweroutlet B”
when
Item Power_Plug_Socket_B received command
then
var String results = “”
if (receivedCommand==ON ) {
results = executeCommandLine(“sudo /home/pi/src/433Utils/RPi_utils/send 00001 1 1”, 5000)
}
else if (receivedCommand==OFF ) {
results = executeCommandLine(“sudo /home/pi/src/433Utils/RPi_utils/send 00001 1 0”, 5000)
}
logInfo(“Power_Plug”, "Results are: " + results)
end

Well, that is yet another way to do it. What do you want to happen next?

What regex?

the openhab-transformation-regex because when i try

thing exec:command:remote-send [
command=“sudo /home/pi/src/433Utils/RPi_utils/send %2$s”,
interval=0,
autorun=false]

It doesn’t work with %2$s

Okay, exec works for other people so it probably is something about your setup rather than a fault in openHAB regex. Let’s find out.

Which rule, using exec Things, are we concentrating on for now? I would suggest the simpler one to begin with. I already pointed out a fault in it that would definitely stop that working, but we didn’t find out if it then worked for you.

What does openhab.log have to say, when you expect a command to be run?

Ok i understand let’s go simpler when i look ar the log i see no update when i use the switch
Can you put the config you wxant i use please i have deleted the old one thx

I’m not writing it for you, you gave us your setup in your post #20 and following

ok i understand
I will put the older files

So here the log
==> /var/log/openhab2/openhab.log <==
2019-09-22 18:54:27.866 [INFO ] [rest.core.internal.item.ItemResource] - Received HTTP POST request at ‘items/Power_Plug_Socket_B’ for the unknown item ‘Power_Plug_Socket_B’.
2019-09-22 18:54:29.284 [INFO ] [rest.core.internal.item.ItemResource] - Received HTTP POST request at ‘items/Power_Plug_Socket_B’ for the unknown item ‘Power_Plug_Socket_B’.

==> /var/log/openhab2/events.log <==
2019-09-22 18:45:36.298 [ome.event.ItemCommandEvent] - Item ‘Power_Plug_Socket_4’ received command ON
2019-09-22 18:45:36.753 [GroupItemStateChangedEvent] - Gplugs changed from ON to OFF through Power_Plug_Socket_1
2019-09-22 18:45:36.813 [vent.ItemStateChangedEvent] - Power_Plug_Socket_1 changed from OFF to ON
2019-09-22 18:45:36.871 [vent.ItemStateChangedEvent] - Power_Plug_Socket_2 changed from OFF to ON
2019-09-22 18:45:36.921 [vent.ItemStateChangedEvent] - Power_Plug_Socket_3 changed from OFF to ON
2019-09-22 18:45:36.969 [GroupItemStateChangedEvent] - Gplugs changed from OFF to ON through Power_Plug_Socket_4
2019-09-22 18:45:37.009 [vent.ItemStateChangedEvent] - Power_Plug_Socket_4 changed from OFF to ON
2019-09-22 18:48:44.259 [temChannelLinkRemovedEvent] - Link ‘Remote_Send_Out => exec:command:remote-send:output’ has been removed.
2019-09-22 18:48:44.379 [temChannelLinkRemovedEvent] - Link ‘Remote_Send_Args => exec:command:remote-send:input’ has been removed.
2019-09-22 18:48:44.416 [temChannelLinkRemovedEvent] - Link ‘Remote_Send => exec:command:remote-send:run’ has been removed.

powerplugs.sitemap
sitemap powerplugs label=“Wireless Poweroutlets”
{
Frame label=“Poweroutlets”
{
Switch item=Power_Plug_Socket_B label=“Power Plug B”
}
}

items
> Switch Power_Plug_Socket_B
> Switch Remote_Send { channel=“exec:command:remote-send:run” }
> String Remote_Send_Args { channel=“exec:command:remote-send:input”}
> String Remote_Send_Out { channel=“exec:command:remote-send:output” }

Things
Thing exec:command:remote-send [
command=“sudo /home/pi/src/433Utils/RPi_utils/send %2$s”,
interval=0,
autorun=false]

rules

rule “Poweroutlet B responds”
when
Item Remote_Send_Out received update
then
logInfo(“Power_Plug”, "Results are: " + Remote_Send_Out.state.toString)
end

You don’t have an Item called Power_Plug_Socket_B

So probably your items file didn’t load. There will be a clue about that in openhab.log

You don’t have any rule to send commands to your exec Items.

Ok you’re right my rules wasn’t save i have to reboot my raspberry
And i have always this log

==> /var/log/openhab2/openhab.log <==
2019-09-22 20:18:00.051 [INFO ] [rest.core.internal.item.ItemResource] - Received HTTP POST request at ‘items/Power_Plug_Socket_B’ for the unknown item ‘Power_Plug_Socket_B’.
2019-09-22 20:18:04.176 [INFO ] [rest.core.internal.item.ItemResource] - Received HTTP POST request at ‘items/Power_Plug_Socket_B’ for the unknown item ‘Power_Plug_Socket_B’.

And my exec things

Thing exec:command:remote-send [
command=“sudo /home/pi/src/433Utils/RPi_utils/send %2$s”,
interval=0,
autorun=false]

It cannot be made much plainer. Whatever you think you have, your system has no Item called Power_Plug_Socket_B
(Your UI is probably trying to send it commands, because you told the UI in your sitemap that an Item was called Power_Plug_Socket_B)

So if you think you have defined that Item in an Items file, the likelihood is that your Items file is failing to load. There will be a log in openhab.log if it tries.

OK i have modified
the rule
r> ule “Poweroutlet B”

when
Item Remote_Send_Out received update
then
logInfo(“Power_Plug”, "Results are: " + Remote_Send_Out.state.toString)
end

and the log

==> /var/log/openhab2/openhab.log <==

2019-09-22 21:12:14.308 [INFO ] [el.core.internal.ModelRepositoryImpl] - Refreshing model ‘powerplugs.sitemap’
2019-09-22 21:24:48.485 [WARN ] [el.core.internal.ModelRepositoryImpl] - Configuration model ‘powerplugs.rules’ has errors, therefore ignoring it: [1,6]: no viable alternative at input ‘“’

2019-09-22 21:40:22.941 [WARN ] [el.core.internal.ModelRepositoryImpl] - Configuration model ‘powerplugs.rules’ has errors, therefore ignoring it: [5,12]: no viable alternative at input ‘“’
[5,13]: no viable alternative at input ‘Power_Plug’
[5,74]: extraneous input ‘)’ expecting ‘end’

2019-09-22 21:41:43.609 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model ‘powerplugs.rules’
2019-09-22 21:43:45.166 [INFO ] [el.core.internal.ModelRepositoryImpl] - Refreshing model ‘powerplugs.rules’

==> /var/log/openhab2/events.log <==
2019-09-22 21:42:09.878 [ome.event.ItemCommandEvent] - Item ‘Power_Plug_Socket_B’ received command ON
2019-09-22 21:42:10.017 [vent.ItemStateChangedEvent] - Power_Plug_Socket_B changed from OFF to ON
2019-09-22 21:42:10.348 [ome.event.ItemCommandEvent] - Item ‘Power_Plug_Socket_B’ received command OFF
2019-09-22 21:42:10.459 [vent.ItemStateChangedEvent] - Power_Plug_Socket_B changed from ON to OFF
2019-09-22 21:44:08.349 [ome.event.ItemCommandEvent] - Item ‘Power_Plug_Socket_B’ received command ON
2019-09-22 21:44:08.453 [vent.ItemStateChangedEvent] - Power_Plug_Socket_B changed from OFF to ON
2019-09-22 21:44:09.502 [ome.event.ItemCommandEvent] - Item ‘Power_Plug_Socket_B’ received command OFF
2019-09-22 21:44:09.597 [vent.ItemStateChangedEvent] - Power_Plug_Socket_B changed from ON to OFF
2019-09-22 21:44:10.479 [ome.event.ItemCommandEvent] - Item ‘Power_Plug_Socket_B’ received command ON
2019-09-22 21:44:10.582 [vent.ItemStateChangedEvent] - Power_Plug_Socket_B changed from OFF to ON

Nothing happen sorry but i don’t understand all english isn’t my fluent langage

Something is wrong with your rules file syntax.

There is obviously something wrong with that, but perhaps it is just a fomatting issue in this forum.

What are you using to edit your files? You need to save them in UTF-8 format.

You also need to take care about quote marks " " especially if you copy-paste from the forum.

If you look closely at this part of your rule

logInfo(“Power_Plug”, "Results are: "

you can see there are two different sorts of " marks.
The ones around Power_Plug are the wrong sort, and will not work.

Once you have fixed your rules file, you will also want to think about including the rule from your own post #22

thanks you are right past of the forum give ``instead " for the quotes

Hi again
i have modified my rules :

rule “Poweroutlet B”
when
Item Power_Plug_Socket_B received command
then
if(receivedCommand == ON) Remote_Send_Args.postUpdate(“00001 3 1”)
else Remote_Send_Args.postUpdate(“00001 3 0”)
when
Item Remote_Send_Out received update
then
logInfo(“Power_Plug”, "Results are: " + Remote_Send_Out.state.toString)
end

Log.

==> /var/log/openhab2/openhab.log <==
2019-09-22 23:53:29.620 [INFO ] [.dashboard.internal.DashboardService] - Started Dashboard at https://192.168.0.160:8443
2019-09-22 23:53:36.756 [INFO ] [arthome.ui.paper.internal.PaperUIApp] - Started Paper UI at /paperui
2019-09-23 20:29:05.189 [INFO ] [el.core.internal.ModelRepositoryImpl] - Refreshing model ‘powerplugs.sitemap’
2019-09-23 20:32:44.216 [INFO ] [el.core.internal.ModelRepositoryImpl] - Refreshing model ‘powerplugs.items’
2019-09-23 20:41:33.289 [INFO ] [el.core.internal.ModelRepositoryImpl] - Refreshing model ‘exec.things’
2019-09-23 20:54:36.259 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model ‘powerplugs.rules’
2019-09-23 20:54:39.917 [INFO ] [el.core.internal.ModelRepositoryImpl] - Refreshing model ‘powerplugs.rules’
2019-09-23 20:59:03.731 [WARN ] [el.core.internal.ModelRepositoryImpl] - Configuration model ‘powerplugs.rules’ has errors, therefore ignoring it: [7,1]: no viable alternative at input ‘when’
[8,6]: no viable alternative at input ‘Remote_Send_Out’

==> /var/log/openhab2/events.log <==
2019-09-23 20:56:24.066 [ome.event.ItemCommandEvent] - Item ‘Power_Plug_Socket_B’ received command OFF
2019-09-23 20:56:24.159 [vent.ItemStateChangedEvent] - Power_Plug_Socket_B changed from ON to OFF
2019-09-23 20:56:47.542 [ome.event.ItemCommandEvent] - Item ‘Power_Plug_Socket_B’ received command ON
2019-09-23 20:56:47.648 [vent.ItemStateChangedEvent] - Power_Plug_Socket_B changed from OFF to ON
2019-09-23 20:56:48.796 [ome.event.ItemCommandEvent] - Item ‘Power_Plug_Socket_B’ received command OFF
2019-09-23 20:56:48.904 [vent.ItemStateChangedEvent] - Power_Plug_Socket_B changed from ON to OFF
2019-09-23 20:59:07.378 [ome.event.ItemCommandEvent] - Item ‘Power_Plug_Socket_B’ received command ON
2019-09-23 20:59:07.471 [vent.ItemStateChangedEvent] - Power_Plug_Socket_B changed from OFF to ON
2019-09-23 20:59:10.596 [ome.event.ItemCommandEvent] - Item ‘Power_Plug_Socket_B’ received command OFF
2019-09-23 20:59:10.697 [vent.ItemStateChangedEvent] - Power_Plug_Socket_B changed from ON to OFF

I see error in log do you know what’s wrong with my rules ?