Transfer a parameter to a python-script. Item? Script? Widget?

Hey to all openhab’ler,

I am very new to openhab so I am a bit confused about names like Items, Things, Scripts, Rules.

I thought it was easy, what i am trying. I hava a python-script, which i call like this:

python hugo

The script make a folder which is called “hugo” and save 20 pictures of a person. My facerecognition-script uses this file and it will recognize a face.

The script works very well and the user “openhab” got all permissions to it.

Now my question: I was trying, as an exmple, to switch a LED on my GPIO to “ON”. I was using an item, a thing and exec-binding. That worked but not as good as i expected. After that i discovered the “HabPanel”, i was thinking about creating a costum widget, that got a Code like this:

    <form action ="">
        Name of Person:
        <input type="text" name="Person"></input>
        <input typ="submit" value="Make a Photo"> </input>

But how can i give the Value from the input text to the script i want? Should i use an item/thing/rule which uses this to exec the command? Is there a better way?

Further informations:
I’ve got a raspberry pi with an apt-get installation of openhab2. I am a bit familliar with linux and html. But I am learning everyday some new things on it :slight_smile:

I hope you will understand my question and can share an idea with me.

Thanks a lot and greetings,

Please review the Beginner’s Tutorial and the Concepts documents to find a description of how all of these parts and concepts in OH work together.

The way OH works the UI (i.e. HABpanel) works with Items. The Items are linked to Channels on Things. Things are bound to Bindings which communicate with the external world, in your case your script.

So you would appropriately have a widget in HABpanel associated with your Item that is linked to your Exec binding Things.

Thank you for the fast answer. I read the sites you ganve mie an the link here.


`Thing exec:command:cam [command="sudo /etc/commands/facedetection/, %2$s"]` 


String cam "[%s]" {channel="exec:command:cam:output"}
Switch camRunning {channel="exec:command:cam:run"}
Number camExitValue {channel="exec:command:cam:exit"}

and the widget-Code:

      <form action="">
        Name of Person:<br></br>
        <input type="text" name="personName"></input>
        <input type="submit" ng-click="sendCmd(cam, 'name')" value="make Foto"> </input>

But i get this Error:

  [ERROR] [hab.binding.exec.handler.ExecHandler] - An exception occurred while formatting the command line with the current time and input values : 'Format specifier '%2$s''

i was reading some posts in the Forum but nothing helps.
Do you have any ideas?

Thank you very much and greetings,

You don’t have an Item linked to the input channel and therefore the input channel doesn’t have a value.

From the Exec 2 binding readme:

the current State of the input channel (see below, example: %2$s)

To make this work with %2$s you need to create a camInput Item and set that Item to the argument you want to pass to I’m not 100% certain if setting the value is enough to trigger the script to run or whether you need to then switch camRuning to ON to trigger the script to run.

From looking at your widget code, it looks like you are trying to set the cam object with the value of name. But you have the cam Item linked to the output channel. From the Exec 2 Readme:

Output of the last execution of the command

In other words, the output channel and therefore cam will contain the result printed by your script.

Thanks for the answer, i understood it differently in the manual, but your explanation was good!

Now i have an Item, which takes the name, another one, which get this Name and give it to the Input-channel of exec-binding-thing. (maybe its too much, but that works nice)

In the Control i can see, that the Value now is set but nothing happened. So I tried out what you have written and added a switch to the exec:command:cam:run but that always stand on “OFF”. I tried to give him the Value “ON” manually but in the next second, its “OFF”.
I tried it with autrun:true but nothing changed.

did you have an idea whats the problem?

Thank you very much and sorry if i am annoying!

Be aware that Control is primarily intended to be for debug and monitoring. You should create Items and use a sitemap to exercise these events. I’m not sure whether or how the channels work together when you commend them directly using Control in PaperUI.

Beyond that, you need to actually set the Switch linked to the command channel to ON to trigger the script to run, like you did. It turned OFF again because that channel only remains ON while the script is running. Once it completed running the Switch was set to OFF again.

I am so stupid, that make sense!

And i have to apologise, cause i didn’t know a lot of Linux and made a big mistake. I set the wrong permission to user openhab. With a friend i figured it out and we find a solution.

But thank you very much for your help. Its nice that you answer fast and precise!

How did you figure this out, I am also having the same kind of issue and unable to make it work and my use case is pretty similar, all I need is just to execute the python script and I don’t care about the output because it does what it is supposed to do. Maybe you can share the permission fix that you did and if possible the sample code of items and things and sitemap if you used.