jamesrodda/homebridge-mihomegateway

Receive Accessory State From API

SmolSoftBoi opened this issue · 10 comments

The accessories' state can be controlled via non HomeKit apps, Alexa, etc. So it would be useful to get the accessory state periodically to reflect its true status. I can't see any web hooks available, but push notifications could potentially be utilised.

This is something I've been looking into implementing for a while but I don't think it's a goer unfortunately. It looks like the Energenie API only works with Google Cloud Messaging (now Firebase Cloud Messaging) but, from what I can see, there isn't a node library for receiving FCM notifications - this is only achievable on the web and mobile.

If you come across anything you think might work, please do let me know as I'd be very keen to get this working.

Thanks @EpicKris - those libraries appear to be for a browser JavaScript environment, not node (please correct me if I'm wrong!)

We'd need messaging support built directly into Homebridge Config UI X (for example) in order to utilise this. Could be worth an ask if it's something they'd entertain? We'd then need to add a generic message receiver to Homebridge itself and finally register this plugin with it.

Seems like a lot of work!

I assumed the JavaScript SDK was compatible with node as the server SDK states If you are interested in using the Node.js SDK as a client for end-user access (for example, in a Node.js desktop or IoT application), as opposed to admin access from a privileged environment (like a server), you should instead follow the instructions for setting up the client JavaScript SDK., though I may have misunderstood.

I was referencing this table: https://firebase.google.com/docs/web/setup#namespace

Is there anything you've seen specifically that contradicts that? I'd love it if we could use FCM here but I'm not sure it's possible :(

You're right, the only other workaround I could think of is to periodically check the accessories state.

If only it was as simple as that :)

So, if the state of the device is changed by anything other than the MiHome api e.g. a physical press of the switch or Alexa) the new state doesn't get reflected in the getSubDeviceInfo call response. I've emailed Energenie support and they've confirmed that there is no realtime monitoring of the switches. They actually pointed me towards the notifications api but, as I said before, I don't think it's possible in a Homebridge context.

After some searching, the only other possible library I found is: https://github.com/MatthieuLemoine/push-receiver - perhaps this could be used to receive the notifications?

Ooh, nice find!

I've managed to wire that into the plugin as a PoC and good news is that I've been able to receive a notification from the FCM test app. Bad news is that I can't get it to work with the MiHome API.

Small steps!

I've messaged Energenie to see if the notifications are working - GCM (which is mentioned in their docs) was deprecated last year in favour of FCM. Hoping they're compatible with each other...

That's great news! Let's hope Energenie come back with a positive response then!