HTTPd 2 plugin

User avatar
FlyingDiver
Posts: 7830
Joined: Sat Jun 07, 2014 10:36 am
Location: Southwest Florida, USA

HTTPd 2 plugin

Post by FlyingDiver »

This is a NEW plugin that's not backward compatible with the original HTTPd plugin.

HTTP servers are now devices, so multiple servers can be created. 'setvar' now uses device states instead of Indigo variables.

https://github.com/FlyingDiver/Indigo-H ... /tag/2.0.0

You'll need to create devices for each HTTPd server you want running, and you'll need to change your triggers and scripts to get values from the device states instead of Indigo variables. Since this is so different from the original HTTPd plugin, this plugin installs separately and you can run both versions simultaneously.

This is a Pre-Release!
joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177
User avatar
FlyingDiver
Posts: 7830
Joined: Sat Jun 07, 2014 10:36 am
Location: Southwest Florida, USA

Re: HTTPd 2 plugin

Post by FlyingDiver »

https://github.com/FlyingDiver/Indigo-H ... /tag/2.0.1

Persistant states

States and last values now saved across restarts.
joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177
User avatar
FlyingDiver
Posts: 7830
Joined: Sat Jun 07, 2014 10:36 am
Location: Southwest Florida, USA

Re: HTTPd 2 plugin

Post by FlyingDiver »

Official release - https://github.com/FlyingDiver/Indigo-H ... /tag/2.0.3

Pending in the Plugin Store.

Some of the device states have changed names. Proxy devices need to specify the http(s) server they're associated with.

Proxy devices now work as intended. I'll update the Wiki soon. In the meantime, here's the short form:
Set up an http(s) server device.
Create a proxy device and specify the server it's associated with.
Copy the "hook_url" device state and use it to set up the webhook on the server (IFTTT or whatever).
Set up a trigger for "Proxy Request Received" for that Proxy Device.

If you're using a webhook instead of the old setvar method, then the server must me sending you complex data. So you'll need a script to handle it. Here's a command I tested with:

Code: Select all

curl -k -X POST -d "{u'go': u'back', u'foo': u'bar'}" "https://username:[email protected]:5556/webhook-1413643748?foo=bar&go=back"
I put this code in a script action in the trigger:

Code: Select all

import json

hookdata_json = indigo.devices[1413643748].states["hookdata_json"] 
hookdata = json.loads(hookdata_json)
indigo.server.log("request from {} for {}, vars = {}".format(hookdata['request']['client'], hookdata['request']['path'], hookdata['vars']))
indigo.server.log("payload = {}".format(hookdata['payload']))
And got this in the log:

Code: Select all

   Trigger                         Webhook trigger
   Script                          request from 127.0.0.1 for /webhook-1413643748, vars = {u'go': u'back', u'foo': u'bar'}
   Script                          payload = {u'go': u'back', u'foo': u'bar'}
That should get you started.
joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177
User avatar
FlyingDiver
Posts: 7830
Joined: Sat Jun 07, 2014 10:36 am
Location: Southwest Florida, USA

Re: HTTPd 2 plugin

Post by FlyingDiver »

I should probably also give some guidance on how to use the plugin. If the service gives you complete control of the webhook URL, and you only need to submit a smallish number of data values to Indigo, then use the "setvar" action and store the data in Indigo variables. That's the simplest solution, and works for things like IFTTT.

If the service doesn't let you control the "payload" of the request, and only lets you specify the base URL, or you have a LOT of data to transfer and it would be unwieldy to use variables, then use the webhook and Proxy method. But remember that the data received by webhook is stored in the device state as a JSON string, so you're going to HAVE to use a Python script to do anything useful with it.
joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177
petematheson
Posts: 847
Joined: Sun Sep 14, 2014 9:51 am
Location: Southampton, UK

Re: HTTPd 2 plugin

Post by petematheson »

Having my first go at this plugin after discovering that gmail no longer works from IFTTT - thank you!

So I've created the device, and the proxy. I'm using the local IP for now.

I test using cmd prompt:
HTTPd 2 Debug logLevel = 5
HTTPd 2 Debug MyRequestHandler: GET to port 5555 from 192.168.0.10:49629 for /setvar?LocationErica360=Home
HTTPd 2 Debug MyRequestHandler: auth_map = {'username': 'indigo', 'password': '1nd1g0'}
HTTPd 2 Debug Myrequesthandler: basic authorization valid
HTTPd 2 Debug IFTTT: MyRequestHandler: updating device
HTTPd 2 Threaddebug IFTTT: MyRequestHandler: saved_states = {u'LocationErica360': u'Home'}
HTTPd 2 Threaddebug IFTTT: MyRequestHandler: new_states = {'LocationErica360': 'Home'}

Except the variables never actually change.
Am I missing something?
petematheson
Posts: 847
Joined: Sun Sep 14, 2014 9:51 am
Location: Southampton, UK

Re: HTTPd 2 plugin

Post by petematheson »

FYI Just installed v1 of the plugin (httpd) and it works fine, httpd2 doesn't actually change the variable for me.
User avatar
FlyingDiver
Posts: 7830
Joined: Sat Jun 07, 2014 10:36 am
Location: Southwest Florida, USA

Re: HTTPd 2 plugin

Post by FlyingDiver »

Read the instructions for V2 again. It doesn’t write to Indigo variables. It writes to device states.


Sent from my iPhone using Tapatalk
joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177
User avatar
FlyingDiver
Posts: 7830
Joined: Sat Jun 07, 2014 10:36 am
Location: Southwest Florida, USA

Re: HTTPd 2 plugin

Post by FlyingDiver »

Just posted version 2.1.0 to the plugin store.

https://github.com/FlyingDiver/Indigo-H ... /tag/2.1.0

Each server device now has an option to set a timestamp state each time a setvar request is handled.
joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177
dgarozzo
Posts: 132
Joined: Thu Jan 08, 2009 6:26 am
Contact:

Re: HTTPd 2 plugin

Post by dgarozzo »

Have you had any problems with HTTPd 2 locking up? I'm using it for WebHooks for my Bouncie Plugin, and I recently noticed that the WebHooks were getting 500 error/timeout responses back. I couldn't find any log information, but restarting the HTTPd plugin seems to have fixed it.
User avatar
FlyingDiver
Posts: 7830
Joined: Sat Jun 07, 2014 10:36 am
Location: Southwest Florida, USA

Re: HTTPd 2 plugin

Post by FlyingDiver »

dgarozzo wrote:Have you had any problems with HTTPd 2 locking up? I'm using it for WebHooks for my Bouncie Plugin, and I recently noticed that the WebHooks were getting 500 error/timeout responses back. I couldn't find any log information, but restarting the HTTPd plugin seems to have fixed it.
I've seen it, but haven't figured out how to fix it yet. So I reload the plugin on a schedule every night.

Server Actions -> Enable/Disable/Reload Actions -> Reload Plugin

https://github.com/FlyingDiver/Indigo-HTTPd-2/issues/8
joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177
User avatar
FlyingDiver
Posts: 7830
Joined: Sat Jun 07, 2014 10:36 am
Location: Southwest Florida, USA

Re: HTTPd 2 plugin

Post by FlyingDiver »

I've been running a new version of the plugin for the last couple days that does periodic testing of the HTTP server. It hasn't failed yet.
joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177
EagleDTW
Posts: 106
Joined: Thu Apr 30, 2020 5:56 pm

Re: HTTPd 2 plugin

Post by EagleDTW »

Hi Joe,

I'm amazed at how many plugins you've developed! I'm not going to lie - I was reluctantly directed to this HTTPd 2 plugin from the webhooks feature on the Rachio plugin, as I have 3 Home Automation Servers polling the Rachio API and it is rate limiting all the time on me currently.

I'm not immensely familiar with some of the steps to get this up and running, I do have a reflector up and have access through outside by use of Caddy. Would you have a real simple breakdown of the steps to get webhooks working on a "device" connection and how to enable it in Rachio plugin (if that's not too much of a stretch)?

I appreciate any pointers as I don't want to keep disabling the plugin to avoid rate limits on the Rachio.

Thank you,
Daniel
User avatar
FlyingDiver
Posts: 7830
Joined: Sat Jun 07, 2014 10:36 am
Location: Southwest Florida, USA

Re: HTTPd 2 plugin

Post by FlyingDiver »

This plugin does not use the reflector, and I don't know what Caddy is. The plugin requires the use of port forwarding configured on your router. Are you able to do that?

Basic instructions are here: https://github.com/FlyingDiver/Indigo-HTTPd-2/wiki

Once you have that working, the the latest Rachio plugin will find it automatically and enable the webhooks.
joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177
User avatar
FlyingDiver
Posts: 7830
Joined: Sat Jun 07, 2014 10:36 am
Location: Southwest Florida, USA

Re: HTTPd 2 plugin

Post by FlyingDiver »

I take that back. You do need to enable the webhooks in the Rachio plugin config dialog, and select the HTTPd-2 plugin device to use.
joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177
User avatar
FlyingDiver
Posts: 7830
Joined: Sat Jun 07, 2014 10:36 am
Location: Southwest Florida, USA

Re: HTTPd 2 plugin

Post by FlyingDiver »

When it's working, you'll see something like this in the Indigo log:

Code: Select all

   Rachio Sprinklers               webHook received, DEVICE/ZONE_STATUS/ZONE_STARTED/DEVICE_ZONE_RUN_STARTED_EVENT: North Lawn began watering at 07:58 PM (EDT).
   Rachio Sprinklers               VMP Rachio Irrigation Controller: Zone 'North Lawn' Started
   Rachio Sprinklers               webHook received, SCHEDULE/SCHEDULE_STATUS/SCHEDULE_STARTED/SCHEDULE_STARTED_EVENT: Quick Run will run for 1 minutes.
   Rachio Sprinklers               VMP Rachio Irrigation Controller: Schedule 'Quick Run' Started
   Rachio Sprinklers               webHook received, DEVICE/ZONE_STATUS/ZONE_COMPLETED/DEVICE_ZONE_RUN_COMPLETED_EVENT: North Lawn completed watering at 07:59 PM (EDT) for 1 minutes.
   Rachio Sprinklers               VMP Rachio Irrigation Controller: Zone 'North Lawn' Completed
   Rachio Sprinklers               webHook received, SCHEDULE/SCHEDULE_STATUS/SCHEDULE_COMPLETED/SCHEDULE_COMPLETED_EVENT: Quick Run ran for 1 minutes.
   Rachio Sprinklers               VMP Rachio Irrigation Controller: Schedule 'Quick Run' Completed
joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177
Locked

Return to “Other Plugins”