I was wondering if someone could look over this code to see if I am using it correctly. Everything works, but I feel like my setup was brute force until it worked. My main goal was to have a switch that I could use with homekit as well as HABPanel that triggered one script for on and another script for off. I installed the homekit and Exec binding. I tried the experimental Rules, but that caused more issues than it helped.
This was the simplest working code I could get running… Simple code for simple people
If this works then I would say you are using this correctly.
I’ve never seen channel used to link an Item without a Thing and proper channel ID. I’m not sure how that part works.
Your rule seems reasonable.
The only thing I would add is some logging to get the output of the script. I’d also be a little more clever with how I create the command, but I wouldn’t expect you to do it this way since you are just learning.
Item SW1 received command
val results = executeCommandLine("python /etc/openhab2/scripts/" +
if(receivedCommand == ON) "on.py" else "off.py",
logInfo("SW", "Results from executing command: " + results)
Another approach which would use the Exec binding, but I’m not sure if it is necessarily simpler to do it that way. You would probably want to change the your python scripts and merge them into one script that takes an ON or OFF as a command line argument.
I agree, I’ve never seen a “dummy” binding config before and it is not necessary.
Also, there is no problem here. The function for the Item is to act as a Proxy or to store a state, both of which represent fine-grained functionality. Storing state is part of automation logic. The main purpose of that statement is to emphasize that Items are not intended to store data structures or lots of data used for lots of purposes. Instead, Items are intended to support a single piece of information or control a single actuator on a device.