Modeling something that can abstract commands to my projector?

So I have a number of rules that end up in wanting to turn my projector on or off. Right now, they’re sending commands such as “PWR%20OFF%0D” through a GC100. I am also playing with the Epson projectors binding (which models the actual projector, but has other limitations like hogging the telnet connection to my GC100).

I wonder if I can create some sort of item that my rules could send a command to / trigger somehow, and have that item in term act on the projector. I’m pretty sure I’ve read about things like that, but I have no idea if I can set them up in the OH3 UI (or should). I also wonder if I would need to create say, an EpsonProjector_PowerOn and an EpsonProjector_PowerOff object, or if it’s also possible to just create something that can see what command what sent to it and decide what to do with it (using, say, JS or Rules DSL).

Any pointers are appreciated. Thanks!

Yes, this is what openHAB Items are for.

Not directly, no.
Items are abstract and isolated from the real world.

Linkages to the real world are provided through bindings and channels, generally a command to an Item passes along a link to a binding’s channel and that’s where the real world communication will be done, by the binding.

There are bindings to do simple tasks, like sending some HTTP message or executing some external script in response to an Item command, this is generally how people cobble something functional for oddball cases that do not justify creating a specialized binding for.

Although it’s just as viable to carry out those tasks as Actions in rules triggered by Item commands.

So I guess what I meant is today I have a rule that looks either like:

when Denon changed to OFF then Projector_Power.sendCommand(OFF) end

or

when Denon changed to OFF then GC100_Serial1_mapped.sendCommand(“POWER_OFF”) end

depending on what I use to control my projector (the Epson projector binding or the GlobalCache binding). Both bindings have their pros and cons so I am playing with both.

I have a few rules like this that sync events with projector commands. What I’d like to do is be able to write my rules like:

when Denon changed to OFF then MyProjectorController.sendCommand(OFF) end

and define that MyProjectorController to do the right thing (using either of the bindings I mentioned). Then all my rules would send commands (or whatever it is I’d need to do) to that MyProjectorController, and that MyProjectorController would abstract the actual physical connection.

I don’t even it MyProjectorController to be able to receive commands with variable arguments. I could have a MyProjectorController_PowerOn and a MyProjectorController_PowerOff etc. if that’s better. As long as its action can be triggered somehow.

I may be describing the wrong mechanism too, and I it’s fine if OH has a way to achieve that abstraction that looks nothing like this. I just want to be able to have the abstraction, so that my rules don’t all need to know how exactly the projector is controlled. Just like one can send ON/OFF to a light bulb without worrying about the bindings that actually will turn it on and off.

You seem to be describing an ordinary openHAB Item.

Well, I want an item that can retarget another item, but have my rules only address that first item. How do I do that with an ordinary openHAB item in the UI? Are you saying just pick a name and change that item definition as needed? (E.g. the channel it is linked to?)

Since I’ve been only creating Points in the UI when creating equipment and then using those, I guess I didn’t think of changing the item’s link, is that the idea?

Well, generally you’d configure an Item permanently to link to whatever binding / technology / real device you wanted.

If you want to be changing this daily, it is probably easiest with rules.

Put Item X on your UI, link it to nothing.
Have Item Y linked to technology YY for some device, have Item Z firing a complicated set of your rules that do whatever actions are needed to some other device.
Have rules that listen for commands to Item X from your UI, decide if it is tuesday or thursday, pass on command to Item Y or Z as you choose.

…and, an Item can be linked to more than one Thing Channel - presumably the two bindings you’re using expose Thing Channels: you can hook the relevant ones from both to a single Item.

And configure the Things online/offline as required.