home-assistant / homebridge-homeassistant

DEPRECATED in favor of native HomeKit support. -  Homebridge plugin for Home Assistant
https://www.home-assistant.io/components/homekit/
Other
683 stars 144 forks source link

Trying to make a "shadow" switch in home assistant that mimics a home kit's state. #259

Closed gabrielca closed 2 years ago

gabrielca commented 6 years ago

It's mostly an experiment, so bear with me but I've got an iHome switch that's attached to Christmas tree, and it's a full blown home kit device.

I was thinking that I might be able to create a switch in Home Assistant using the command line switch (just doing echo's on the turn_on/off for the switch) thinking that it might be a way to control a home kit accessory from within home assistant.

Now it mostly works. When the home kit switch turns on theres an automation to turn on the home assistant on, same deal for off.

There's also two automations in home kit that when the home assistant one changes state it sets the home kit switch to match.

If I flip the home kit switch from the Home app it flips the home assistant one, changes are seen in HassIO's web page. If I flip the Home Assistant switch in the Home App it also works.

BUT if I flip the switch in Home Assistant home kit doesn't see the transition and doesn't trigger the automations. If I restart the Home App, it then sees the change (I'm guessing it's doing a query?) and then triggers the automation...weird but ok.

I set log_level to debug and I see things like:

[2017-12-6 21:42:55] [HomeAssistant] Setting power state on the 'Christmas Light' to off [2017-12-6 21:42:55] [HomeAssistant] Successfully set power state on the 'Christmas Light' to off [2017-12-6 21:42:55] [HomeAssistant] Setting power state on the 'Christmas Light' to off [2017-12-6 21:42:55] [HomeAssistant] Successfully set power state on the 'Christmas Light' to off

In the cases that work. In the case where I set the switch from the overview page in Hassio there's crickets....doesn't seem to be any log activity.

I know there will be some edge case synchronizing issues with this approach (like switches change while hassio is offline or crashes or restarts or whatever) but I can live with them if I can get HomeKit to see changes from Home Assistant.

gabrielca commented 6 years ago

Hmmm....just made my harmony remote switch visible to home kit and even flipping it from the home assistant interface leave home kit in an out of sync state until I restart the home app.

There a general problem with switches not updating their status to home kit when home kit doesn't do the toggle? This a known issue?

schmittx commented 6 years ago

I'd recommend the following approach for the most robustness:

  1. (Home Assistant) Create an MQTT binary sensor which will store the current/target state of the iHome
  2. (Home Assistant) Create an MQTT switch which will use the MQTT binary sensor for it's state and publish a topic to turn on/off the MQTT binary sensor
  3. (Homebridge) Expose that MQTT switch within HomeKit using this plugin
  4. (Home app) Create automation within HomeKit to link the iHome to the Home Assistant MQTT switches (4 automations needed)