indigodomo / HomeKit-Bridge

Enabled HomeKit integration via Homebridge for Indigo Home Automation
The Unlicense
46 stars 13 forks source link

virtual on/off device as homekit garage door opener #111

Closed bonfireva closed 6 years ago

bonfireva commented 6 years ago

Status of virtual on/off device is not displayed properly when its configured as a garage door opener in homekit

The virtual on/off device is using a status variable to determine the state of the garage door. The garage door opener updates this variable with "open", "closed", and "offline". The virtual device in Indigo indicates it is "on" when the status variable is set to "open", and "off" when set to "closed" (offline is just an error state if the opener lost connection).

Expected Behavior

When the indigo status variable is set to "open" the homekit garage door device should also report open, and when the variable is set to "Closed" home kit should report that the door is closed. If possible when the variable is set to "offline" or any other error state, homekit should show that the device is not available

Current Behavior

Homekit reports that the door is open when the status variable is set to "closed" and closed when set to "open"

Steps to Reproduce (for bugs)

Homebridge Log / Command Output

 HomeKit Bridge                  [2018-7-12 19:33:20] Loaded plugin: homebridge-camera-ffmpeg
[2018-7-12 19:33:20] Registering platform 'homebridge-camera-ffmpeg.Camera-ffmpeg'
[2018-7-12 19:33:20] ---
[2018-7-12 19:33:20] Loaded plugin: homebridge-indigo2
[2018-7-12 19:33:20] Registering platform 'homebridge-indigo2.Indigo2'
[2018-7-12 19:33:20] ---
[2018-7-12 19:33:20] Loaded config.json with 0 accessories and 1 platforms.
[2018-7-12 19:33:20] ---
[2018-7-12 19:33:20] Loading 1 platforms...
[2018-7-12 19:33:20] [HomeKit Bridge Server] Initializing Indigo2 platform...
[2018-7-12 19:33:20] [HomeKit Bridge Server] HomeKit Bridge base URL is http://127.0.0.1:8558
[2018-7-12 19:33:20] [HomeKit Bridge Server] HomeKit Bridge serverId is 394794701
[2018-7-12 19:33:20] Loading 0 accessories...
Load homebridge-camera-ffmpeg.Camera-ffmpeg
[2018-7-12 19:33:20] [HomeKit Bridge Server] Listening on port 8445
[2018-7-12 19:33:20] [HomeKit Bridge Server] HomeKit Bridge request: http://127.0.0.1:8558/HomeKit?cmd=deviceList&serverId=394794701
[2018-7-12 19:33:20] [HomeKit Bridge Server] Discovered Device MotionSensor (ID 039574575daa3f2c649ae2c5e5b0da636b8071b22361ee67fb3d48459cf9017e):  Kitchen Motion Sensor
[2018-7-12 19:33:20] [HomeKit Bridge Server] Discovered Device Lightbulb (ID 042dbf5ac1a5e04252ac8d05f3c7d35ba47f3009dd4f75badbee85e39c563f38): Dinning Table Light
[2018-7-12 19:33:20] [HomeKit Bridge Server] Discovered Device Thermostat (ID 0a3927afe99d7d93fd1398f775fb7ff3b6cb98f6d58fb32554179c69f8ffdb1d): Downstairs Thermostat
[2018-7-12 19:33:20] [HomeKit Bridge Server] Downstairs Thermostat: Overriding min value for TargetTemperature to 10
[2018-7-12 19:33:20] [HomeKit Bridge Server] Downstairs Thermostat: Overriding max value for TargetTemperature to 38
[2018-7-12 19:33:20] [HomeKit Bridge Server] Downstairs Thermostat: Overriding min value for CurrentTemperature to -100
[2018-7-12 19:33:20] [HomeKit Bridge Server] Downstairs Thermostat: Overriding max value for CurrentTemperature to 500
[2018-7-12 19:33:20] [HomeKit Bridge Server] Downstairs Thermostat: Overriding min value for HeatingThresholdTemperature to 0
[2018-7-12 19:33:20] [HomeKit Bridge Server] Downstairs Thermostat: Overriding max value for HeatingThresholdTemperature to 38
[2018-7-12 19:33:20] [HomeKit Bridge Server] Downstairs Thermostat: Overriding min value for CoolingThresholdTemperature to 10
[2018-7-12 19:33:20] [HomeKit Bridge Server] Downstairs Thermostat: Overriding max value for CoolingThresholdTemperature to 38
[2018-7-12 19:33:20] [HomeKit Bridge Server] Discovered Device Lightbulb (ID b71daaa8e8302886a59b1aae71af7877e69196458c0c5090b536c042e8f97025): Family Room Overhead
[2018-7-12 19:33:20] [HomeKit Bridge Server] Discovered Device Fanv2 (ID 99c344214f4d8c57bd0c209d44c0c2c209d143a43b6eb94d90f6190ed060d9f8): Fan
[2018-7-12 19:33:20] [HomeKit Bridge Server] Discovered Device Lightbulb (ID 71201f01579ebc93de1d583568b944a6faf5553b534e21ed02385a0306e6979f): Garage Front Light
[2018-7-12 19:33:20] [HomeKit Bridge Server] Discovered Device Lightbulb (ID 7f8e6d42b3b2ebfaa2716435c40f03a0a6a9a7958eca4e3359fa31a20fe6f82b): Goose Necks
[2018-7-12 19:33:20] [HomeKit Bridge Server] Discovered Device Thermostat (ID 555cb47acb38f669f010c64452932bbe16cbc1ab912b2e3115732f49d4f0cffb): Hallway - Thermostat
[2018-7-12 19:33:20] [HomeKit Bridge Server] Hallway - Thermostat: Overriding min value for TargetTemperature to 10
[2018-7-12 19:33:20] [HomeKit Bridge Server] Hallway - Thermostat: Overriding max value for TargetTemperature to 38
[2018-7-12 19:33:20] [HomeKit Bridge Server] Hallway - Thermostat: Overriding min value for CurrentTemperature to -100
[2018-7-12 19:33:20] [HomeKit Bridge Server] Hallway - Thermostat: Overriding max value for CurrentTemperature to 500
[2018-7-12 19:33:20] [HomeKit Bridge Server] Hallway - Thermostat: Overriding min value for HeatingThresholdTemperature to 0
[2018-7-12 19:33:20] [HomeKit Bridge Server] Hallway - Thermostat: Overriding max value for HeatingThresholdTemperature to 38
[2018-7-12 19:33:20] [HomeKit Bridge Server] Hallway - Thermostat: Overriding min value for CoolingThresholdTemperature to 10
[2018-7-12 19:33:20] [HomeKit Bridge Server] Hallway - Thermostat: Overriding max value for CoolingThresholdTemperature to 38
[2018-7-12 19:33:20] [HomeKit Bridge Server] Discovered Device Lightbulb (ID 6ab63685fa6fc6b4223fc5311817ffdc7b0315941f4d62df8b94b4cfddb21225): House Front Light
[2018-7-12 19:33:20] [HomeKit Bridge Server] Discovered Device GarageDoorOpener (ID 26a3feb7ce384658dea9f48661618e86be3eee887bcc41fef71d7d350e9ce857): testGD
[2018-7-12 19:33:20] [HomeKit Bridge Server] Created 10 accessories
[2018-7-12 19:33:20] [HomeKit Bridge Server] Initializing platform accessory ' Kitchen Motion Sensor'...
[2018-7-12 19:33:20] [HomeKit Bridge Server] Initializing platform accessory 'Dinning Table Light'...
[2018-7-12 19:33:20] [HomeKit Bridge Server] Initializing platform accessory 'Downstairs Thermostat'...
[2018-7-12 19:33:20] [HomeKit Bridge Server] Initializing platform accessory 'Family Room Overhead'...
[2018-7-12 19:33:20] [HomeKit Bridge Server] Initializing platform accessory 'Fan'...
[2018-7-12 19:33:20] [HomeKit Bridge Server] Initializing platform accessory 'Garage Front Light'...
[2018-7-12 19:33:20] [HomeKit Bridge Server] Initializing platform accessory 'Goose Necks'...
[2018-7-12 19:33:20] [HomeKit Bridge Server] Initializing platform accessory 'Hallway - Thermostat'...
[2018-7-12 19:33:20] [HomeKit Bridge Server] Initializing platform accessory 'House Front Light'...
[2018-7-12 19:33:20] [HomeKit Bridge Server] Initializing platform accessory 'testGD'...
Setup Payload:
X-HM://0023ISYWY8COK
Scan this code with your HomeKit app on your iOS device to pair with Homebridge:

Or enter this code with your HomeKit app on your iOS device to pair with Homebridge:

    ┌────────────┐     
    │ 031-45-154 │     
    └────────────┘     

[2018-7-12 19:33:20] Homebridge is running on port 51827.
[2018-7-12 19:34:23] [HomeKit Bridge Server] testGD: get(ObstructionDetected) => false
[2018-7-12 19:34:23] [HomeKit Bridge Server] testGD: get(CurrentDoorState) => 1
[2018-7-12 19:34:23] [HomeKit Bridge Server] testGD: get(TargetDoorState) => 1
[2018-7-12 19:34:23] [HomeKit Bridge Server] Downstairs Thermostat: get(CurrentHeatingCoolingState) => 0
[2018-7-12 19:34:23] [HomeKit Bridge Server] Downstairs Thermostat: get(CurrentTemperature) => 19.444444444444443
[2018-7-12 19:34:23] [HomeKit Bridge Server] Downstairs Thermostat: get(CoolingThresholdTemperature) => 23.333333333333332
[2018-7-12 19:34:23] [HomeKit Bridge Server] Downstairs Thermostat: get(TargetHeatingCoolingState) => 0
[2018-7-12 19:34:23] [HomeKit Bridge Server] Downstairs Thermostat: get(TargetTemperature) => 23.333333333333332
[2018-7-12 19:34:23] [HomeKit Bridge Server] Downstairs Thermostat: get(HeatingThresholdTemperature) => 17.77777777777778
[2018-7-12 19:34:23] [HomeKit Bridge Server] Dinning Table Light: get(On) => false
[2018-7-12 19:34:23] [HomeKit Bridge Server] Hallway - Thermostat: get(HeatingThresholdTemperature) => 17.22222222222222
[2018-7-12 19:34:23] [HomeKit Bridge Server] Hallway - Thermostat: get(CurrentTemperature) => 23.333333333333332
[2018-7-12 19:34:23] [HomeKit Bridge Server] Hallway - Thermostat: get(TargetTemperature) => 23.333333333333332
[2018-7-12 19:34:23] [HomeKit Bridge Server] Hallway - Thermostat: get(CoolingThresholdTemperature) => 23.333333333333332
[2018-7-12 19:34:23] [HomeKit Bridge Server] Hallway - Thermostat: get(CurrentHeatingCoolingState) => 0
[2018-7-12 19:34:23] [HomeKit Bridge Server] Hallway - Thermostat: get(TargetHeatingCoolingState) => 2
[2018-7-12 19:34:23] [HomeKit Bridge Server]  Kitchen Motion Sensor: get(StatusLowBattery) => 0
[2018-7-12 19:34:23] [HomeKit Bridge Server]  Kitchen Motion Sensor: get(MotionDetected) => true
[2018-7-12 19:34:23] [HomeKit Bridge Server] Goose Necks: get(On) => false
[2018-7-12 19:34:23] [HomeKit Bridge Server] Fan: get(Active) => 0
[2018-7-12 19:34:23] [HomeKit Bridge Server] Family Room Overhead: get(On) => false
[2018-7-12 19:34:23] [HomeKit Bridge Server] Garage Front Light: get(On) => false
[2018-7-12 19:34:23] [HomeKit Bridge Server] House Front Light: get(On) => false
[2018-7-12 19:34:30] [HomeKit Bridge Server] testGD: set(TargetDoorState) 1 -> 0
[2018-7-12 19:34:30] [HomeKit Bridge Server] HomeKit Bridge request: http://127.0.0.1:8558/HomeKit?objId=674173313&serverId=394794701&jkey=26a3feb7ce384658dea9f48661618e86be3eee887bcc41fef71d7d350e9ce857&cmd=setCharacteristic&TargetDoorState=0
[2018-7-12 19:34:30] [HomeKit Bridge Server] testGD: updateCharacteristicValue(TargetDoorState): 0 -> 1
[2018-7-12 19:34:30] [HomeKit Bridge Server] POST update request for device ID 26a3feb7ce384658dea9f48661618e86be3eee887bcc41fef71d7d350e9ce857
[2018-7-12 19:34:30] [HomeKit Bridge Server] testGD: updateCharacteristicValue(TargetDoorState): 1 -> 0
[2018-7-12 19:34:30] [HomeKit Bridge Server] testGD: updateCharacteristicValue(CurrentDoorState): 1 -> 0
[2018-7-12 19:34:34] [HomeKit Bridge Server] testGD: set(TargetDoorState) 0 -> 1
[2018-7-12 19:34:34] [HomeKit Bridge Server] HomeKit Bridge request: http://127.0.0.1:8558/HomeKit?objId=674173313&serverId=394794701&jkey=26a3feb7ce384658dea9f48661618e86be3eee887bcc41fef71d7d350e9ce857&cmd=setCharacteristic&TargetDoorState=1
[2018-7-12 19:34:34] [HomeKit Bridge Server] testGD: updateCharacteristicValue(TargetDoorState): 1 -> 0
[2018-7-12 19:34:35] [HomeKit Bridge Server] POST update request for device ID 26a3feb7ce384658dea9f48661618e86be3eee887bcc41fef71d7d350e9ce857
[2018-7-12 19:34:35] [HomeKit Bridge Server] testGD: updateCharacteristicValue(TargetDoorState): 0 -> 1
[2018-7-12 19:34:35] [HomeKit Bridge Server] testGD: updateCharacteristicValue(CurrentDoorState): 0 -> 1
[2018-7-12 19:34:48] [HomeKit Bridge Server] POST update request for device ID 039574575daa3f2c649ae2c5e5b0da636b8071b22361ee67fb3d48459cf9017e
[2018-7-12 19:34:48] [HomeKit Bridge Server]  Kitchen Motion Sensor: updateCharacteristicValue(MotionDetected): true -> false
[2018-7-12 19:34:53] [HomeKit Bridge Server] POST update request for device ID 039574575daa3f2c649ae2c5e5b0da636b8071b22361ee67fb3d48459cf9017e
[2018-7-12 19:34:53] [HomeKit Bridge Server]  Kitchen Motion Sensor: updateCharacteristicValue(MotionDetected): false -> true

Device Simulation Report

Simulation while door is in Open state:
##### DEVICE SIMULATION DATA #####

    Service : 
        alias : testGD
        model : 
        subModel : 
        indigoType : indigo.RelayDevice
        pluginType : indigo.RelayDevice.com.perceptiveautomation.indigoplugin.devicecollection.pseudoRelay
        type : GarageDoorOpener
        desc : Garage Door Opener
        objId : 674173313
        serverId : 394794701
        invertOnState : False
        convertFahrenheit : False
        required : (List)
            ObstructionDetected : False
            TargetDoorState : 1
            CurrentDoorState : 1
        optional : (List)
            LockTargetState
            Name
            LockCurrentState
        native : True
        requiresPlugin : (List)
        actions : (List)
            Action : (HomeKitAction)
                Characteristic : TargetDoorState
                When : equal
                Value : 0 (int)
                Value2 : 0 (int)
                Command : device.turnOff
                Arguments : [674173313]
                monitors : {674173313: 'attr_onState'}
            Action : (HomeKitAction)
                Characteristic : TargetDoorState
                When : equal
                Value : 1 (int)
                Value2 : 0 (int)
                Command : device.turnOn
                Arguments : [674173313]
                monitors : {674173313: 'attr_onState'}
            Action : (HomeKitAction)
                Characteristic : CurrentDoorState
                When : equal
                Value : 0 (int)
                Value2 : 0 (int)
                Command : device.turnOff
                Arguments : [674173313]
                monitors : {674173313: 'attr_onState'}
            Action : (HomeKitAction)
                Characteristic : CurrentDoorState
                When : between
                Value : 1 (int)
                Value2 : 4 (int)
                Command : device.turnOn
                Arguments : [674173313]
                monitors : {674173313: 'attr_onState'}
        loadOptional : False
        characterDict : (Dict)
            ObstructionDetected : False
            TargetDoorState : 1
            CurrentDoorState : 1
    [/code]

Simulation while door is in closed state:
##### DEVICE SIMULATION DATA #####

    Service : 
        alias : testGD
        model : 
        subModel : 
        indigoType : indigo.RelayDevice
        pluginType : indigo.RelayDevice.com.perceptiveautomation.indigoplugin.devicecollection.pseudoRelay
        type : GarageDoorOpener
        desc : Garage Door Opener
        objId : 674173313
        serverId : 394794701
        invertOnState : False
        convertFahrenheit : False
        required : (List)
            ObstructionDetected : False
            TargetDoorState : 0
            CurrentDoorState : 0
        optional : (List)
            LockTargetState
            Name
            LockCurrentState
        native : True
        requiresPlugin : (List)
        actions : (List)
            Action : (HomeKitAction)
                Characteristic : TargetDoorState
                When : equal
                Value : 0 (int)
                Value2 : 0 (int)
                Command : device.turnOff
                Arguments : [674173313]
                monitors : {674173313: 'attr_onState'}
            Action : (HomeKitAction)
                Characteristic : TargetDoorState
                When : equal
                Value : 1 (int)
                Value2 : 0 (int)
                Command : device.turnOn
                Arguments : [674173313]
                monitors : {674173313: 'attr_onState'}
            Action : (HomeKitAction)
                Characteristic : CurrentDoorState
                When : equal
                Value : 0 (int)
                Value2 : 0 (int)
                Command : device.turnOff
                Arguments : [674173313]
                monitors : {674173313: 'attr_onState'}
            Action : (HomeKitAction)
                Characteristic : CurrentDoorState
                When : between
                Value : 1 (int)
                Value2 : 4 (int)
                Command : device.turnOn
                Arguments : [674173313]
                monitors : {674173313: 'attr_onState'}
        loadOptional : False
        characterDict : (Dict)
            ObstructionDetected : False
            TargetDoorState : 0
            CurrentDoorState : 0
    [/code]
bonfireva commented 6 years ago

I also tried the "invert on/off" option when adding the device into homekit bridge, didn't make a difference.

Colorado4Wheeler commented 6 years ago

First, the simulation reports are incomplete, there should have been full device dumps with them too but it’s a non issue I think because, literally, everything I’m seeing says it’s working fine. I can see that the garage door state in the simulation data is correct for open and closed and I can see in the logs that open and closing the garage door is working as intended. I can also see in the logs when the door command are sent to indigo they are processed and the status updates are being transmitted to HomeKit. In all, if you didn’t say it wasn’t working I would swear from this data that absolutely nothing is wrong!

I’ll try to reproduce the conditions and see if I see anything but absolutely all data you sent says it’s working.

Colorado4Wheeler commented 6 years ago

Ok, I cannot reproduce the issue you are having. I created a virtual on/off device that fired an action group to open and close my garage door and tied it to a variable that uses open and closed for its status and it works fine.

My primary test was simply changing the variable to see if that, which should toggle the virtual device to turn on and off, would do that and then update HomeKit and it does. Honestly that alone tells me everything seems to be working. I then turned on/off the device to physically open and close the door and that worked flawlessly. I then used HomeKit to open and close the door and it opens and closes the door.

The only issue I found is that the virtual group doesn't update the status properly in that when I open the door it sticks on 'opening' and when I close it sticks on 'closing' but that's not unexpected since a garage door as a virtual device isn't specifically supported but rather supported generically as on/off.

I'll add to the list to possibly add support for this scenario but until I directly support variable manipulation I cannot do that 'any other error state, homekit should show that the device is not available' because that's far too specific to your needs and requires HKB to utilize a device AND the variable it references and that is unnecessarily complicated.

But, in the end, the thing you say is not working seems to be working for me - the device state in Indigo is properly reflected in HomeKit.

bonfireva commented 6 years ago

interesting, its a pretty simple test, so I am not sure what you could be doing different than what I am doing to get the different results.... I guess Ill just keep using HASSIO/homebridge for my MQTT devices integration into homekit. Thanks for looking into it at least. I am curious about the error state request. What happens with a Zwave or any other commercially available and supported garage door interface when its disconnected? I assume it would be "unavailable" in Indigo, does that state transfer over to homekit, or does the device still show as available and just not work?

Colorado4Wheeler commented 6 years ago

What do you mean when it is disconnected?

Does the MQTT device have an Indigo plugin that it operates with? If so and if MQTT is exclusively a garage door then I could simply add support for that instead of doing the roundabout way of using virtual on/off devices.

bonfireva commented 6 years ago

by "disconnected" i simply mean unplugged, or not in communication with Indigo. I have tested both of the current MQTT plugins to Indigo, and I have had issues with stability on one (plugin needs to be reset often) and the other had issues when MQTT broker authentication was enabled. I am very happy with the stability of Node Red for supporting the MQTT transmissions, and it has no issue updating status variables in Indigo via the RESTApi.

I recorded a short video that shows my issue, I couldn't attach it here, so I uploaded it to my AWS S3 bucket, link below. Notice that the status variable"gdtest" and the virtual device "gdtest" states are "open" or "on" respectively when homekit says the garage door is "closed", and vise versa. I just needed to share so you didn't think I was crazy :)

https://bonfireva.s3.amazonaws.com/IMG_2406.MOV

-Eric

Colorado4Wheeler commented 6 years ago

Ok, so the issue is that it is opposite of what it should be represented as. I've re-read your post and I'm still under the impression that it wasn't changing HomeKit at all and there was no communication whatsoever, which is why I said the logs said everything was fine and the testing showed everything as fine. I didn't dive deep into mine but I had similar issues when using a virtual device for a garage door.

Now that I have a better understanding of what the core issue is then I'll see about fixing that in HKB.

bonfireva commented 6 years ago

Sorry for any confusion. So the functional communication always worked, in other words the device that shows up in Homekit, when pressed, would toggle the garage door, the issue was always with the status in HK. Originally the status never changed at all, it always showed that it was "open". After removing the plugin, restarting the server, and re-installing the plugin, the state in HK now changes, it is just the opposite of what it should be. Also if I change the HK device type to "switch" instead of "garage door opener" the status is reported correctly in HK.

Thanks again, -Eric

Colorado4Wheeler commented 6 years ago

Got it, that shouldn't be too hard to fix, hopefully the next update. I'm guessing that it wasn't removing the plugin that fixed the other issue it was that when you did that you also updated it to a newer version because there was a point in time a while back where what you described was an issue but it was resolved in an update (I would have to go through release notes to know when that happened).

Colorado4Wheeler commented 6 years ago

In doing some testing I found that inverting the value works on my side: variable is closed and HomeKit shows closed, variable is open and HomeKit shows open.

In this case it would have to be inverted because HomeKit is a bit opposite on how it deals with garage doors - typically 0 is closed and 1 is open but for garage doors it is reversed and since False = 0 you would have to invert it so that False = 1 to show the proper state.

This still doesn't fix the issue of the virtual device hanging on when you use HomeKit to open/close but can you try testing that again because that does work on my end using 1.0.1. Make sure you give the server time to reload AND you may need to quit your home app and restart it (or create a second blank home and switch to that and back, which is what I do in testing) because that change may not show up in HomeKit after you make it for a good several minutes because HomeKit is confused since the server just restarted.

bonfireva commented 6 years ago

ok, so I was not able to get the original virtual device to work but I created a copy of it (so it had a new device ID in Indigo), renamed it, and then added it to homekit bridge with the "invert On/Off" option selected and that worked! Thanks for the help!

-Eric

Colorado4Wheeler commented 6 years ago

You likely couldn't get the original to work because you needed to force HomeKit to refresh in the app, which requires killing the app in iOS and starting it back up or creating a second empty home and switch to that home and back to your real home to force a refresh. By deleting you forced that issue because you forced a new ID to be sent to Home.

Colorado4Wheeler commented 6 years ago

Full testing of this shows that virtual devices work fine as garage door openers when defined with the invert on/off, including full control of the garage door from HomeKit without hangs or errors. Closing this out.