Now I do have a device which has no interface like serial, wifi etc. but I can switch it On/Off via a batch file. This is working with a rule in OH without problem. Now I would like to have a “Switch Item” which switch On/Off this device.
How can I do that if there is no “batch binding” to create such Item? Is there a workaround or…? For sure there is an easy way but at the moment I have no idea to do that.
If there is a binding I can use it afterwards for a widget, rules etc…
Check out the Exec binding. Note that you need some extra configuration compared to other bindings, you need to manually add an exec.whitelist file with all shell commands that should be allowed to run. It’s all explained in the binding docs.
If it helps, I had the use case of wanting to suspend a workstation machine regardless of whether it’s running Windows or Linux, with a OH switch.
I decided to install some software on both OSes to react to a message on a MQTT topic (connecting to a MQTT broker that I have on the network anyways).
I would recommend to use the network binding to create a pingdevice thing for your computer. Then you could link your switch item to the Online channel of the pingdevice to have the switch showing you the current state of the device.
Depending on the startup time of your computer you might observe that the switch goes from ON (after you manually switched it) to OFF again (because it takes the pingdevice a couple of moments to get online) and back to ON when it finally is able to answer the ping requests.
I think there is a misunderstanding. Correct I do have a rule but WITHOUT trigger function at the moment. I only used this rule to check the batch file.
Now, I would like to “link” such batch file (with exec binding) to a switch. This means when I set the switch to ON it shall call the batch file “On” and when the switch is set to OFF it calls the batch file “Off”.
In other words, the question is how do I link such batch file to an empty switch item??
If you want yo use the Exec binding you might need two items, since the input-channel only accepts a string. But if you have activated autorun on the Thing it will automatically run whenever this the Item linked to it gets a command. It might be possible to create a switch widget in the UI for this Item directly, otherwise you will need a second Switch item that sends a command to the input-Item when it’s changed.
Edit: the rule approach would probably be simpler in your case, especially since you already have a rule in place.