benzman81 / homebridge-http-webhooks

A http plugin with support of webhooks for Homebridge: https://github.com/nfarina/homebridge
GNU General Public License v3.0
180 stars 57 forks source link

Switch activity not correctly recognised in the Home app #7

Closed jaquesp closed 7 years ago

jaquesp commented 7 years ago

Pardon what may be a stupid question, but can I use this with an IFTTT maker channel to change the status of any of my existing accessories in homebridge?

I have a number of ESP8266 devices which I'd like to include in an existing IFTTT recipe to turn everything off when I leave home. At the moment I can only achieve this for the Hue and Wemo lights there are IFTTT channels for. If I could achieve this I'd be super happy!

Thanks in advance.

Paul

benzman81 commented 7 years ago

No, this plugin creates new accesesorries that can be triggered by a webhook, i.e. IFTTT. Existing accesesorries can not be changed as these are not known by other plugins.

jaquesp commented 7 years ago

Thanks for this reply - this makes sense to me now and I realise how I can make this work within my system. I have therefore created a virtual switch in the web hooks configuration which when activated I will have homekit react to by turning everything off: { "platform": "HttpWebHooks", "webhook_port": "51828", "switches": [ { "id": "ifttt_switch1", "name": "IFTTT Switch 1" } ] }, However when I test changing that state within the home app itself it seems to hang. I get a message of the form: Jan 15 17:35:40 raspberrypi homebridge[8954]: [1/15/2017, 5:35:40 PM] Switch state for 'ifttt_switch1'...

within the app itself but it doesn't make the change, and then seems to hang homebridge (can't control any other accessory) until the operation has complete. Restarting the home app seems to reset things but is not ideal. Have you seen this before? Is there something wrong with my configuration? Startup lines for your information:

Jan 15 17:29:56 raspberrypi homebridge[8954]: [1/15/2017, 5:29:56 PM] Loaded plugin: homebridge-http-webhooks Jan 15 17:29:56 raspberrypi homebridge[8954]: [1/15/2017, 5:29:56 PM] Registering platform 'homebridge-http-webhooks.HttpWebHooks' Jan 15 17:29:56 raspberrypi homebridge[8954]: [1/15/2017, 5:29:56 PM] Registering accessory 'homebridge-http-webhooks.HttpWebHookSensor' Jan 15 17:29:56 raspberrypi homebridge[8954]: [1/15/2017, 5:29:56 PM] Registering accessory 'homebridge-http-webhooks.HttpWebHookSwitch' Jan 15 17:30:11 raspberrypi homebridge[8954]: [1/15/2017, 5:30:11 PM] Initializing HttpWebHooks platform... Jan 15 17:30:11 raspberrypi homebridge[8954]: [1/15/2017, 5:30:11 PM] Initializing platform accessory 'IFTTT Switch 1'... Jan 15 17:30:11 raspberrypi homebridge[8954]: [1/15/2017, 5:30:11 PM] Started server for webhooks on port '51828'.

Thanks in advance!

jaquesp commented 7 years ago

Additionally, if I call the web hook triggers, the actions seem to occur within homebridge, but there is no update within the Home app until I restart the app - is this expected:

curl -X POST "http://192.168.0.56:51828/?accessoryId=ifttt_switch1&state=false" {"success":true} curl -X POST "http://192.168.0.56:51828/?accessoryId=ifttt_switch1&state=true" {"success":true}

Jan 15 18:14:56 raspberrypi homebridge[9280]: [1/15/2017, 6:14:56 PM] Change HomeKit state for switch to 'false'. Jan 15 18:14:56 raspberrypi homebridge[9280]: [1/15/2017, 6:14:56 PM] Switch state for 'ifttt_switch1'... Jan 15 18:15:13 raspberrypi homebridge[9280]: [1/15/2017, 6:15:13 PM] Getting current state for 'ifttt_switch1'... Jan 15 18:15:25 raspberrypi homebridge[9280]: [1/15/2017, 6:15:25 PM] Change HomeKit state for switch to 'true'. Jan 15 18:15:25 raspberrypi homebridge[9280]: [1/15/2017, 6:15:25 PM] Switch state for 'ifttt_switch1'... Jan 15 18:15:42 raspberrypi homebridge[9280]: [1/15/2017, 6:15:42 PM] Getting current state for 'ifttt_switch1'...

benzman81 commented 7 years ago

Could you try it with an off and on url? Might be a bug. I use it daily and it works like a charm, but I have on off urls set.

jaquesp commented 7 years ago

Sure - let me give that a go! Out of interest, when i click the switch in the app, would I expect to see the "Change homekit switch" message in homebridge also? Thanks for your quick response, I'll try this evening!

jaquesp commented 7 years ago

Apologies, could you give me an example of on and off url's? I can't seem to get this to work when I use them....

jaquesp commented 7 years ago

I tried this, but ended up in some kind of infinite loop!:

"on_url": "http://192.168.0.56:51828/?accessoryId=ifttt_switch1&state=true", "off_url": "http://192.168.0.56:51828/?accessoryId=ifttt_switch1&state=false"

benzman81 commented 7 years ago

Well, what are you actually trying to do? The switches can be used to turn on/off some other http enabled devices. Therefore you should enter the url of those devices for on/off. Additionally those devices can push their new state via webhook to the plugin.

jaquesp commented 7 years ago

Essentially, what I'm looking for is a virtual switch that can be triggered remotely from IFTTT and am not looking to trigger any other http devices internally. I would like homekit to recognise the state change and then act accordingly (switching of all my other homebridge bridged devices not natively switchable from IFTTT). If i call the URL (using CURL as above) the state change seems to work (and the log suggests the Homekit state is being changed - but it doesn't reflect in the app immediately without a restart. When I test triggering the switch within the app, the state never changes (always see a small progress circle in the corner of the button in the app - again, this doesn't change until I restart the app and hangs homekit for some reason). Thanks for your help in advance.

jaquesp commented 7 years ago

testing it further - making the curl calls while the app is closed and then opening the app results in the correct state being shown. looks like the "Getting current state" activity is not being called immediately in the app? No further luck with using the switch in the app tho

benzman81 commented 7 years ago

If you dont want to "switch" a device, I would use a contact sensor. States are reflected live in my environment.

jaquesp commented 7 years ago

Thanks again for your quick responses. I switched the configuration to using a contact sensor and can recreate the same issue in the home app. setting the state to false by calling the URL is reflected in an immediate change in homebridge:

Jan 15 23:28:00 raspberrypi homebridge[15033]: [1/15/2017, 11:28:00 PM] Change HomeKit state for contact sensor to 'false'.

However there is not an immediate change in the home app. i'd expect switching screens in the app, or coming out of the app and going back in (not closing) would remedy this but it does not. I have to kill the app and re-launch for the state to be reflected. Alternatively, I can keep home open and launch another homekit app (e.g.: eve or home) which checks the status, then go back into home and the status updates. Is there any way to force whatever operation takes place when homebridge logs the following:

Jan 15 23:32:55 raspberrypi homebridge[15033]: [1/15/2017, 11:32:55 PM] Getting current state for 'ifttt_sensor1'...

Thanks again for all your help!

benzman81 commented 7 years ago

I just double checked, but its working lika a charm with all my three sensors. Just a last idea, could you activate notifications for the sensor and additionally add an automation. This way you might be able to check if the state changes occurs and only the device icon doesnt update.

jaquesp commented 7 years ago

Well this is weird! I enabled notifications and they worked perfectly, as expected. when closing/opening the sensor the notifications popped up as expected. Opened the home app, tried again, and both the notifications showed up AND the status changed in home app in real time. Then turned the notifications off and the sensor STILL updates in realtime in the app! I'm not sure what happened there but enabling notifications seems to have kicked it into life! Thanks ever so much for all of your assistance - you've been more than helpful!

benzman81 commented 7 years ago

No problem.

benzman81 commented 7 years ago

There also was a bug if not on or off URL was set which makes the switch not changing ist state. This is fixed now.