HTTPd Plugin (useful for IFTTT Maker integration)

Posted on
Fri Oct 25, 2019 3:58 am
DrLove offline
Posts: 260
Joined: Dec 12, 2014
Location: Sweden

Re: HTTPd Plugin (useful for IFTTT Maker integration)

I have looked at the logs and they are actually empty between time for failure and next start after forced reload, no errors :/
I have now went back to monitoring status of our dishwasher via energy consumption (Fibaro Wallplug) and the physical sensor I have installed in the cabinet for the door.
Right now I'm not using the plugin but I might enable it again later, I have upgraded to High Sierra (can't go higher) and Indigo 7.4, maybe that helpes.

Best regards, L

Love Kull (yes it's my name)
Blog (in Swedish)
Sweden

Posted on
Tue Jan 21, 2020 6:49 pm
JaceJenkins offline
Posts: 52
Joined: Oct 16, 2015

Re: HTTPd Plugin (useful for IFTTT Maker integration)

Hello FD,

Love your plugin, been using it since it came out.

I have a need to run 2 instances of HTTPd on separate ports. I am using Geofency for presence awareness. It has a built-in feature to define a webhook when you pass through different geofences and can make direct GET's to HTTPd. Having said that, GEOFency is being run on two phones at the same time and I need a way for each phone to have its own instance of HTTPd to post to. Timing issues arise if both phones try to make calls to the same HTTPd at the same time. They step all over each other, so having an HTTPd per phone will solve my issues.

One issue would be each HTTPd instance would need its own variable prefix's so they don't mix with each other. Attached is a screenshot of all the variables one event can post to HTTPd. And there is no way to specify a prefix for each phone.

Thoughts?
Attachments
Screen Shot 2020-01-21 at 6.54.52 PM.png
Screen Shot 2020-01-21 at 6.54.52 PM.png (81.52 KiB) Viewed 3261 times

Posted on
Tue Jan 21, 2020 8:04 pm
FlyingDiver offline
User avatar
Posts: 7213
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: HTTPd Plugin (useful for IFTTT Maker integration)

I can do that. If I support multiple "instances", then it's just as easy to put the values into device states rather than variables. That is, you would create a device for http on port 5555 (for example), and another on port 5577. Then instead of having multiple sets of variables, each device would have their own states, which would replace the variables. Would that work?

Add any additional comments on what you need to this enhancement request: https://github.com/FlyingDiver/Indigo-HTTPd/issues/4

joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177

Posted on
Tue Jan 21, 2020 8:43 pm
JaceJenkins offline
Posts: 52
Joined: Oct 16, 2015

Re: HTTPd Plugin (useful for IFTTT Maker integration)

Yeah, that would be perfect. I assume the states are dynamically created based values in the POST? So when GeoFency posts all the values to the webhook, those would all get created as states if they don't already exist?

You are awesome btw. :)

Posted on
Tue Jan 21, 2020 8:46 pm
FlyingDiver offline
User avatar
Posts: 7213
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: HTTPd Plugin (useful for IFTTT Maker integration)

JaceJenkins wrote:
Yeah, that would be perfect. I assume the states are dynamically created based values in the POST? So when GeoFency posts all the values to the webhook, those would all get created as states if they don't already exist?


Yes, exactly. I already do that in several other plugins.

joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177

Posted on
Thu Jan 23, 2020 4:09 pm
FlyingDiver offline
User avatar
Posts: 7213
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: HTTPd Plugin (useful for IFTTT Maker integration)


joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177

Posted on
Sat Feb 01, 2020 5:19 am
LSpad offline
Posts: 30
Joined: Oct 01, 2018

Re: HTTPd Plugin (useful for IFTTT Maker integration)

Hi Joe,

Many thanks for a great plugin.

I'm having a little bit of difficulty with the webhook proxy device setup: when I try and create an instance of a proxy I get a settings pane with no options (just save or cancel). On pressing save I get an error:

Code: Select all
HTTPd                           dbell: Starting proxyDevice Device 1518360974
HTTPd Error                     Error in plugin execution ServerReplacedElem:

Traceback (most recent call last):
  File "/Library/Application Support/Perceptive Automation/Indigo 7.4/IndigoPluginHost.app/Contents/Resources/PlugIns/plugin_base.py", line 1179, in deviceUpdated
  File "plugin.py", line 395, in deviceStartComm
AttributeError: 'NoneType' object has no attribute 'get'

I've got my server set up on the default port (5555) and can confirm it is receiving data using the setvar test. Others may wish to note that if they are using the new zsh script shell in OSX you need to escape character the ? so the command is best quoted like this:
Code: Select all
curl -X POST "http://192.168.1.100:5555/setvar?hello=world"
{that took me an embarrassingly long time to figure out}

I've set up a trigger action as per previous posts on this page - HTTPd event -> proxy request received , proxy device dbell, set up to trigger the following script:
Code: Select all
httpPlugin = indigo.server.getPlugin("com.flyingdiver.indigoplugin.httpd")
if httpPlugin.isEnabled():
    hook_data = httpPlugin.executeAction("getWebhookData", deviceId=1518360974)
    indigo.server.log("Webhook Payload:\n{}".format(hook_data))

and send a curl command like:
Code: Select all
curl  -d '{"deviceid":"HSL-XXX-XXXX", "alias":"Home doorbell", "action": "HTTP Hook"}' -H "Content-Type: application/json" http://192.168.1.100:5555/webhook-1518360974

I can see that the json data is received:
Code: Select all
HTTPd Debug                     RequestHandler: POST from 192.168.1.100:57404 to /webhook-1518360974
HTTPd Debug                     RequestHandler: No password specified in plugin preferences, skipping authentication
HTTPd Debug                     POST Webhook to httpd_webhook-1518360974 = {'request': {'path': '/webhook-1518360974', 'client': '192.168.1.100', 'command': 'POST', 'headers': {'host': '192.168.1.100:5555', 'content-type': 'application/json', 'content-length': '75', 'accept': '*/*', 'user-agent': 'curl/7.64.1'}}, 'payload': {u'action': u'HTTP Hook', u'alias': u'Home doorbell', u'deviceid': u'HSL-XXX-XXXX'}, 'vars': {}}

... but the proxy does not trigger any actions - I suspect related to the error above when trying to create the proxy? I've restarted the plugin a number of times, and tried to create different proxies all with the same result.

Any advice very gratefully received!

Posted on
Sat Feb 01, 2020 6:46 am
FlyingDiver offline
User avatar
Posts: 7213
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: HTTPd Plugin (useful for IFTTT Maker integration)

I think I noticed some issues with Proxy devices when I was revising that code for the HTTPd 2 plugin. I'll try to take a look at it again this weekend.

joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177

Posted on
Sat Feb 01, 2020 2:52 pm
FlyingDiver offline
User avatar
Posts: 7213
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: HTTPd Plugin (useful for IFTTT Maker integration)

OK, a couple of things. First, I can't replicate the error you're seeing when you initially save the Proxy device. The blank settings dialog is expected. I really should put a label in there saying so. The only thing I can think of that might cause that error is something weird in the plugin configuration. Please confirm you're on the latest version (1.4.2) and make sure the plugin config is correct. You should have 5555 in the http field and 0 in the https field.

Second, I don't think the Proxy devices are going to do what you want. They were intended for use by external (long running) Python scripts. Python scripts can't use the indigo.server.subscribeToBroadcast() method needed to get notifications about web hooks directly. So the Proxy device was intended to be used to "capture" the web hook data in a way that an external script could fetch later. The trigger is meant to be used to notify the external script that there was webhook data waiting for them. I actually had this all running on my development system before I shelved it.

So, why don't you tell me what you're actually trying to accomplish and maybe I can point you in the right direction. Which, BTW, might be to change to the HTTPd-2 plugin. ;)

joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177

Posted on
Sat Feb 01, 2020 9:33 pm
FlyingDiver offline
User avatar
Posts: 7213
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: HTTPd Plugin (useful for IFTTT Maker integration)

So, I was mistaken before. I never actually finished the Proxy implementation. It worked for the specific case I was using it for, but not the general case.

I've got it pretty much working, but it's in the HTTP-2 plugin. So check out that thread on converting to the new plugin, and I'll post the version with the changes tomorrow.

joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177

Posted on
Mon Feb 03, 2020 2:34 pm
LSpad offline
Posts: 30
Joined: Oct 01, 2018

Re: HTTPd Plugin (useful for IFTTT Maker integration)

Thanks Joe,

I'm simply trying to catch a webhook that is sent from my doorbell (https://www.dbell.ca) when the button is pressed. I've got two of these low cost door cams (front and back of the house)- they have a reasonably good picture performance, support ONVIF so you can record the streams, and have webhook capability to (hopefully) integrate with Indigo. So far so good.

I've set the hardware to transmit the http hook to the HTTPd server at http://192.168.1.100:5555/webhook?name=dbell

I'm trying to catch the hook that looks like this:
Code: Select all
POST /dbell HTTP/1.1
User-Agent: curl/7.21.0 (arm-unknown-linux-gnu) libcurl/7.21.0 OpenSSL/0.9.8g zlib/1.2.11
Host: 192.168.1.21:5000
Accept: */*
Content-Length: 79
Content-Type: application/json
{"deviceid":"HSL-XXX-XXXX", "alias":"Home doorbell", "action": "HTTP Hook"}

At the moment I'm just trying to get the plugin to dump the info to the log as proof of concept, but ultimately I'd like to create variables for each of the 3 keys in the hook so I can trigger events on a state change.

So I think my use case is pretty basic - perhaps I don't need to use a proxy for this after all?

Posted on
Mon Feb 03, 2020 2:41 pm
FlyingDiver offline
User avatar
Posts: 7213
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: HTTPd Plugin (useful for IFTTT Maker integration)

LSpad wrote:
I've set the hardware to transmit the http hook to the HTTPd server at http://192.168.1.100:5555/webhook?name=dbell

I'm trying to catch the hook that looks like this:
Code: Select all
POST /dbell HTTP/1.1
User-Agent: curl/7.21.0 (arm-unknown-linux-gnu) libcurl/7.21.0 OpenSSL/0.9.8g zlib/1.2.11
Host: 192.168.1.21:5000
Accept: */*
Content-Length: 79
Content-Type: application/json
{"deviceid":"HSL-XXX-XXXX", "alias":"Home doorbell", "action": "HTTP Hook"}

At the moment I'm just trying to get the plugin to dump the info to the log as proof of concept, but ultimately I'd like to create variables for each of the 3 keys in the hook so I can trigger events on a state change.

So I think my use case is pretty basic - perhaps I don't need to use a proxy for this after all?


Do you have complete control of the URL that it will use for the webhook, or will it only take the server info and it adds it's own path string after that? Your example shows it using POST and sending the device-specific information in the payload. If you set the complete URL to something like this, then you don't need a proxy.

Code: Select all
 http://192.168.1.100:5555/setvars?dbell=front


If you can't, then you need a proxy, because that's the only way to capture the payload data.

joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177

Posted on
Mon Feb 03, 2020 2:43 pm
FlyingDiver offline
User avatar
Posts: 7213
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: HTTPd Plugin (useful for IFTTT Maker integration)

Actually, I'm pretty sure you'll need to use a Proxy. Your capture has this:

Code: Select all
POST /dbell HTTP/1.1


Which means it used a URL ending in /dbell. Which isn't what you told it to send. But maybe. Set it up using the URL above and let me know what happens. Put the plugin in debug log mode so you see everything that it receives.

joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177

Posted on
Mon Mar 09, 2020 2:48 pm
petematheson offline
Posts: 847
Joined: Sep 14, 2014
Location: Southampton, UK

Re: HTTPd Plugin (useful for IFTTT Maker integration)

Sorry for using the wrong version! Misunderstood :)
So I'm using this version to modify variables for presence detection using IFTTT and Life360.

When I manually run the following cmd:
curl http://username:password@192.168.0.10:5 ... ca360=Home

I get:

HTTPd Debug getWebhookInfo, info = {u'hook_name': u'httpd_webhook-1662899611', u'http': 'http://username:password@192.168.0.10:5555/webhook-1662899611'}
HTTPd Debug RequestHandler: GET from 192.168.0.10:49995 for /setvar?LocationErica360=Home
HTTPd Debug RequestHandler: auth_map = {'username': 'username', 'password': 'password'}
HTTPd Debug Requesthandler: basic authorization valid
HTTPd Debug RequestHandler: setting variable httpd_LocationErica360 to 'Home'

But the variable doesn't change ??

Posted on
Mon Mar 09, 2020 6:37 pm
FlyingDiver offline
User avatar
Posts: 7213
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: HTTPd Plugin (useful for IFTTT Maker integration)

What variable are you looking at? The log says it’s updating httpd_LocationErica360. Is that not happening?


Sent from my iPhone using Tapatalk

joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177

Who is online

Users browsing this forum: No registered users and 0 guests