Exec Binding, Homekit and Rules is this the correct setup?

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 :crazy_face:

I have no Thing or Sitemap.

Switch SW1 "SWW" [Switchable] {channel=">[ON] >[OFF]"}
rule "SW"  
 when  
     Item SW1 received command  
 then
 	if(receivedCommand == ON){
 		executeCommandLine("python /etc/openhab2/scripts/on.py")
 	}else{
 		executeCommandLine("python /etc/openhab2/scripts/off.py")
 	}  
       
 end

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.

rule "SW"
when
    Item SW1 received command
then
    val results = executeCommandLine("python /etc/openhab2/scripts/" + 
                                     if(receivedCommand == ON) "on.py" else "off.py", 
                                     5000)
    logInfo("SW", "Results from executing command: " + results)
end

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 still don’t have a great understanding of linking the channels, but after a reboot it did cause issues with my items. I ended up putting in a
{dummy=“nothing”}
instead of:
{channel=">[ON] >[OFF]"}

Once I have a better understanding of the linking I will come back and fix my dummy

http://docs.openhab.org/concepts/index.html

A channel represents a specific sensor or actor on a device (Thing). You link a channel to an Item.

I don’t use Homelkit so wasn’t sure if they do something weird, but in general, a channel like that is nonsensical.

For my understanding, you do not need a channel (or bindingconfig for that matter) at all. I have a bunch of Items like these that work perfectly fine:

// Dummy Items for Alexa
Switch dummyLivingActivity_kodi "Heimkino" (gHarmonyDummy, gHistory) ["Switchable"]
Switch dummyLivingActivity_ps4 "Playstation" (gHarmonyDummy, gHistory) ["Switchable"]

So I don’t understand why the {dummy=“nothing”} part would be necessary.
They do work in Homekit as well as Alexa and any rule btw.

As those Items are not linked to any thing it makes sense for me that they do not have a bindingconfig so I don’t see anything conceptually wrong here either.
The only problem might be this statement:

Items represent (fine-grained) functionality that is used by applications - as user interfaces or automation logic. Items have a state and they can receive commands.

since this item does not have any functionality, if it wasn’t for the rule, except of maybe “storing” a state

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.