snowdd1 / homebridge-knx

KNX platform shim for homebridge
https://github.com/nfarina/homebridge
GNU General Public License v2.0
97 stars 56 forks source link

PulseLight #142

Closed coxfrederic closed 5 years ago

coxfrederic commented 5 years ago

Hi,

Please see https://github.com/snowdd1/homebridge-knx/pull/141 where I attempted (first attempt at this) to create a custom add-in which sends the same pulse value to KNX. I use it for a wire connected to my remote control which sends a 433Mhz code to my kitchen hood. I know it's a bit of a hack but the only thing that works.

I got it to work now via my PulseLight.js addin in the way that it is a light in Homekit that shows on/off correctly based on Homekit memory (since I can not read the actual status from the hood). When I switch the light the hood light is switched also so that is working as expected.

One issue I'm having now is when I include the light in the automation. When at 23:59 I like to turn the light OFF, the issue is that if the light is already OFF then the pulse seems to be send either way, turning the light back on again. Homekit (or homebridge?) does not seem to ignore the fact that the light is already out.

How can I cover this in the PulseLight.js ? I tried adjusting to:

onHKValueChange(field, oldValue, newValue) {
        log('INFO: onHKValueChange(' + field + ", "+ oldValue + ", "+ newValue + ")");
        if(field === "On" && oldValue !== newValue){
            this.myAPI.knxWrite(field, 1);
        }
    } // onHKValueChange

But that does not seem to work. I only want the automation to switch the light if the status is different than the current status. Because both the on and off signal off the light trigger the pulse to KNX effectively switching the hood light on and off.

Any help or pointers would be greatly appreciated!

coxfrederic commented 5 years ago

I managed to find a way to get this working, see https://github.com/snowdd1/homebridge-knx/pull/141/commits/19b3739765a43180a3654da3678084f873d464b7

Don't know if this is "the way to go" but it works for me. Now when the scenario plays to set the light to the same state it is already in, no pulse will be sent so all works as expected.

snowdd1 commented 5 years ago

You need to set some ( ) around the boolean operators. Like in ((a === b) && ( c !== d)) otherwise strange precedence happens.