steilerDev / homebridge-openhab2-complete

A homebridge plugin for openHAB, that has the expectation to fully support all Services offered by Apple's Homekit Accessory Protocol (HAP)
GNU General Public License v3.0
52 stars 16 forks source link

Understanding a simple light concept #42

Closed Tazintosh closed 4 years ago

Tazintosh commented 4 years ago

Hi there, Well, it's not really a bug, since I don't know, thus it's isn't either a feature request. I just want to check if I'm missing something on the concept here. Let's take the example of a light (in my case, a LED strip with RGB + physical white lights)

I've my LED strip as Thing on OpenHab. It has 5 channels Power (switch), Color (color), White (dimmer), White2 (dimmer, not used), Program (string) and Program speed (dimmer).

Following home bridge-openhab2-complete documentation, I've added on my homebridge config the related items created on OpenHab.

My (kind of) surprise is that I end up in HomeKit with 4 accessories (string is not supported), which makes sense based on the documentation, but doesn't to me and based on HomeKit accessory description where everything should be merged in one unique accessory. (For instance, with a native HomeKit light, I've never had to first toggle an accessory switch on to power it, then to use another one to set it's color, another one to set it's white, and so forth).

Is there a way to "merge" those (or at least power, color and white) in one unique accessory or is my only way is to program everything on openhab (ie. if brightness != 0 then power ON, etc.)?

Thanks in advance for your bright light ;)

steilerDev commented 4 years ago

HI @Tazintosh,

what you are trying is not something that can be achieved in this plugin. I just introduced a communication layer, showing items from openHAB in HomeKit, but since you have four different items in openHAB those are shown as 4 items in HomeKit as well.

Preface: I hope I understand your setup correctly and I did not directly test all of those rules (there might be syntax errors in there), since I don't have access to your environment, just trying to give you an understanding, so you can go and find the best way for you. Since this is at it's core an openHAB question, feel free to contact the nice folks over at the openHAB community

I would suggest creating a proxy item in one of your item files without specifying any binding (The other three items should already be defined with your respective binding, not sure just guessing here): led.items

Color myLEDProxyItem
Switch myLEDPower {<<yourbinding>>}
Color myLEDColor {<<yourbinding>>}
Dimmer myLEDBrightness {<<yourbinding>>}

(The myLEDProxyItem would be the one item you would add to your home bridge configuration)

Then you would create a rule, that monitors incoming commands to your proxy item and push them to your other items, while changing your proxy item if your other items are changed.

led.rules

import java.lang.Integer
import java.lang.NumberFormatException

rule 'incoming proxy request'
when
    Item myLEDProxyItem received command
then
    if (receivedCommand == "ON" || receivedCommand == "OFF") {
        myLEDPower.sendCommand(receivedCommand);
    } else {
        try {
            val int num = Integer.parseInt(receivedCommand)
            myLEDBrightness.sendCommand(receivedCommand);
            // not sure if your accessory is 'smart enough' to also trigger the switch on, when a brightness is set, if not you would need something like this:
           if(receivedCommand > 0) {
                myLEDPower.sendCommand("ON");
            } else {
                myLEDPower.sendCommand("OFF");
            }
        } catch (NumberFormatException e) {
            // String is not a number
            //now this should be a color couple, as mentioned above, if your items are not 'smart enough', you would need to parse the 'receivedCommand' and perform brightness and power settings as well, I am a little bit lazy at the moment, therefore I would suggest you to give it a try, feel free to post if you can't find a solution :P
            myLEDColor.sendCommand(receivedCommand);
        }
end

rule "brightness led changed"
when
    myLEDBrightness changed
then
    myLEDProxyItem.postUpdate(myLEDBrightness.state);
end

rule "power led changed"
when
    myLEDPower changed
then
    myLEDProxyItem.postUpdate(myLEDPower.state);
end

rule "color led changed"
when
    myLEDColor changed
then
    myLEDProxyItem.postUpdate(myLEDColor.state);
end

As said earlier, I did this quickly while on the train without really checking it, but it should give you an idea how to create and keep proxy items in sync. I hope that helped.

Tazintosh commented 4 years ago

Hi @steilerDev, I'm happy you did not put much time into this but still, I'm sure it will help some other people that were in my case. The proxy concept is cool, I was clearly missing this.

Anyway, since more than 2 weeks, my configuration has much evolved. In fact, I've dropped Openhab for now. The learning curve was way to long, for unsatisfying results (sadly) an big needs (need to learn new language to write rules etc.) I've installed Node-RED and the overall experience is immensely better (not speaking writing rules were functions are just javascript). The HomeKit palette "node-red-contrib-homekit-bridged" is a real pleasure, producing a "native" HomeKit device with all expectations.

Thanks @steilerDev