[SOLVED] Use switch and Exec binding to trigger python scripts

Hi,
At the moment I am working on a solution to control SR-201 ethernet relays during my testing I ran into some thing which raise questions.Eventually I want to publish some kind of tutorial with working examples, so I already started to store some of my files and code in a Github repository [github SR-201.

My scripts expects two parameters, an IP address for the relay board to control and a integer as command.
When I create switches on my sitemap I can use a rule with Execute commandline to call the python scripts with the required parameters. Execute commandline does not feel really nice, I’d rather solve this with the 2.0 Exec binding.

  1. Can I call/trigger Exec things directly from rules? The documentation suggests that things become available to the rules engine but I cannot find a working example which triggers the exec binding.
  2. Is it worth the effort to trigger my scripts through the Exec binding or should I just keep using excute commandline?

I was hoping to be able to trigger one thing with parameters based on which switch was toggled e.g.
Switch1 ON would trigger the Exec input with IP xx.xx.xx.xx and COMMAND 11 to turn on Relay 1. Switch 2 would then trigger for the same IP but with 12 as command to turn on relay 2.

Mappings basically allow me to this without using any rules whatsoever, but mappings with values other than ON or OFF cannot use a standard toggle switch. So I am hoping someone can point me in the right direction efficiency and manageability wise.

  1. No. You can link one of the Thing’s channels to an Item and sendCommand to that Item in the Rules. For what it sounds like you are after you will need at least two Items, maybe three for each script.
  • Switch to execute the script
  • String to pass arguments
  • String to receive result of the script.
  1. If you will only ever trigger this from rules I would stick to the executrCommandLine Action.

Thanks for your reply, I will start using executeCommandLine and mess around with the scripts for the exec binding on my test VM.
I already had a somewhat working setup with multiple items, things and rules but it felt inefficient, I can always switch over at a later stage when I run into limitations or issues with the executecommandline setup.