I’ve been trying to understand how to attach a command to a thing in a rule. My understanding is that I should be able to use a channel in a thing once it is created in Paper UI. However, some of the posts are saying that an item still needs to be created and associated to the respective channel and then leveraging the .sendcommand. The particular instance I’m trying to solve is to power a WiFiled switch. The channel I want to control is “wifiled:wifiled:A020A61CFD53:power”
The rule did not like it when I replaced the colons with underscores.
Can I avoid creating an switch item in the .item file? If so, what is the naming context?
The only time you can use a Thing’s Channel directly in a Rule is as a trigger to a Rule. And the only time these are uses is when you have a momentary event such as sunrise or a Dash button was pressed.
To control and keep track of the state of a WiFi switch, you must use an Item. To control the device, you must sendCommand to the Item.
It may seem like a hassle, but Items are important. They normalize all the devices that might be connected to OH into a small and fixed set of types. This allows OH a way to interact with all the technologies and devices you might integrate seamlessly. Also, Items allow you the opportunity to model your home automation. What does wifiled:wifiled:A020A61CFD53:power mean? If you have more than two you will have to maintain a spreadsheet just to figure out which Thing controls which light. But, if you create a BedroomLamp Item linked to wifiled:wifiled:A020A61CFD53:power then it’s obvious to you what that device controls. Furthermore, should you change the wifi switch at some point, all you do is relink it to the Item and all the rest of OH will remain unchanged.
It just seems like an extra step. In the past, we just dealt with .items, .rules, and .sitemaps. I thought .things would remove the need for .item definition. For instance, I have a WiFi LED Device and it has six channels defined. I can use the channels in the .rule file for triggers but not for commands. So now, it is an extra step where I have to assign a channel to an .item entry before using it in rules.
Things were created so the binding config could be created automatically. In the old 1.x bindings, there is no way to automatically discover and save devices. Everything has to be configured on an Item by Item basis. Things were created as a way to allow for the automatic creation of these configs (i.e. Things and Channels). They also allow for some opportunities that are impossible in 1.x type bindings. For example, look at the Exec binding. Because you have a separate Thing which Channels, you can now have one Item to kick off the script, another Item to pass arguments to the script, a third Item to get the result of the script, and a fourth that gets the return value of the command. With Exec 1 all you can do is assign the Item the result from running the script on command.
So Things were never intended to replace Items. They were and are intended to make it possible to automatically discover that connection information so that it’s simpler to link devices to Item.