Jump to content
C4 Forums | Control4

Realtime Event Webhook Driver


harper

Recommended Posts

I just released an alpha version of a driver I have been using privately for awhile: http://c4drivers.com/realtime-event-webhook

It uses the control4 device events to push event payloads to a webhook URL. 

Effectively - you can get event notifications at any URL you specify as soon as the event triggers. 

For example: If you change the light level - it will immediately send a light level event to the URL specified. 

This is very a alpha release - and I would love feedback. 

 

Let me know if you have questions

Link to comment
Share on other sites


5 hours ago, TheWizard said:

Actually, I have a suggestion. Could you do a device selector property with all of the proxy types your registering events for? That way the dealer can quickly pick and choose from the device selector list?

That is a good idea. I am trying to figure out the best way to handle choosing the proxy types. Right now it is hard coded - but should be easy to make an interface for it. I will work on it for the next release. 

Link to comment
Share on other sites

5 hours ago, msgreenf said:

Very cool idea!  What system are you using it to integrate with?

I am using this to integrate with some external logging. I also do a lot of hacking on home assistant - and this will be used to integrate with it. 

Link to comment
Share on other sites

I currently am using the Chowmain Generic TCP driver to control some LED light strip controllers that don't have C4 drivers - to do that I have to have Apache running on an Ubuntu VM (or at times an RPi) to catch the URL GET commands.  I have set these lights up as generic lights in C4 using the Chowmain Generic IR driver and when the state of a light changes it sends something like the following URL:

HTTP GET 192.168.1.88/cgi-bin/led_control.py?ip=192.168.1.211&command=toggle

Could I use this Webhook driver for this purpose?  What would be the advantage to using Webhook vs my current methodology?  I am guessing that I wouldn't have to send the command argument as that and other info would come across in the JSON payload, correct?

The other thing that would be useful, at least to me, is to go the other way and have a better method to pass information into C4.  I use RyanE's WebEvents driver but that only lets you pass a command.  It would be great to be able to pass more information into C4, kind of like your Webhook but be a receiver rather than a sender.  For example, I change a keypad LED depending on the charge state of my car and there are multiple charge states such as:  unplugged, stopped, starting, charging, and completed.  I have to set each of these up as a different command that is sent to Webevents - it would be nice to just send charge_state with a payload with the actual state and even values such as current battery %.

Link to comment
Share on other sites

12 hours ago, zaphod said:

I currently am using the Chowmain Generic TCP driver to control some LED light strip controllers that don't have C4 drivers - to do that I have to have Apache running on an Ubuntu VM (or at times an RPi) to catch the URL GET commands.  I have set these lights up as generic lights in C4 using the Chowmain Generic IR driver and when the state of a light changes it sends something like the following URL:

HTTP GET 192.168.1.88/cgi-bin/led_control.py?ip=192.168.1.211&command=toggle

Could I use this Webhook driver for this purpose?  What would be the advantage to using Webhook vs my current methodology?  I am guessing that I wouldn't have to send the command argument as that and other info would come across in the JSON payload, correct?

The other thing that would be useful, at least to me, is to go the other way and have a better method to pass information into C4.  I use RyanE's WebEvents driver but that only lets you pass a command.  It would be great to be able to pass more information into C4, kind of like your Webhook but be a receiver rather than a sender.  For example, I change a keypad LED depending on the charge state of my car and there are multiple charge states such as:  unplugged, stopped, starting, charging, and completed.  I have to set each of these up as a different command that is sent to Webevents - it would be nice to just send charge_state with a payload with the actual state and even values such as current battery %.

Probably not. It is primarily for sending events from control4 to an external source. 

Right now you receive *all* events for lights, fans, security, motion, locks, and switches. This is overkill for what you are doing. 

FWIW i use the generic TCP driver for basically the same thing that you are. I haven't found a better solution - but there should be. 

Link to comment
Share on other sites

Zaphod, would you use a generic http lightv2 driver?

IE: 4 properties (toggle, on, off, set level) where you just put the HTTP URI to invoke when the proxy gets the command.

Toggle: "/cgi-bin/led_control.py?ip=192.168.1.211&command=toggle"

On: "/cgi-bin/led_control.py?ip=192.168.1.211&command=on"

Off: "/cgi-bin/led_control.py?ip=192.168.1.211&command=off"

I can add some sort of format string to automatically input things like the IP.

Link to comment
Share on other sites

16 hours ago, harper said:

Probably not. It is primarily for sending events from control4 to an external source. 

Right now you receive *all* events for lights, fans, security, motion, locks, and switches. This is overkill for what you are doing. 

FWIW i use the generic TCP driver for basically the same thing that you are. I haven't found a better solution - but there should be. 

I'm actually working on a project that would be that "better solution"....if I can ever find enough spare time to finish it.

Link to comment
Share on other sites

16 hours ago, TheWizard said:

Zaphod, would you use a generic http lightv2 driver?

IE: 4 properties (toggle, on, off, set level) where you just put the HTTP URI to invoke when the proxy gets the command.


Toggle: "/cgi-bin/led_control.py?ip=192.168.1.211&command=toggle"

On: "/cgi-bin/led_control.py?ip=192.168.1.211&command=on"

Off: "/cgi-bin/led_control.py?ip=192.168.1.211&command=off"

I can add some sort of format string to automatically input things like the IP.

Yes I would use that.  What parameters would you have?  URL, IP and command?  I have written some python code that catches the command and then calls the API and this runs in Python  on Ubuntu - Apache2. In this instance I am controlling LED light strips based on an unofficial "Flux LED" API using code adapted from here.   The other thing you could add to this is a color command so rather than command=on you could pass color=red.  But then you need a "colors" library to convert color names to RGB  like the python webcolors package. @msgreenf said that he may look at writing a driver for these lights if he gets the time.

But I am also using other commands on other parts of my system to kick off other options, like turn on the climate system or start charging for my car.  In an ideal world there would also be direct C4 drivers for that.

Link to comment
Share on other sites

On 22/11/2017 at 2:29 PM, Joshua Pressnell said:

I'm actually working on a project that would be that "better solution"....if I can ever find enough spare time to finish it.

Care to elaborate?  Either in public or private?

Link to comment
Share on other sites

  • 3 months later...
On 11/20/2017 at 9:47 PM, harper said:

That is a good idea. I am trying to figure out the best way to handle choosing the proxy types. Right now it is hard coded - but should be easy to make an interface for it. I will work on it for the next release. 

@harper, did you have a chance to take a look on how to implement choosing the proxy types?

I would like to use your driver to send events to a Smartthings hub and having the status of my TVs, Apple TVs, Receivers and so on would be nice (on top of what you offer today). I won't mind entering the proxy types manually.

Link to comment
Share on other sites

  • 2 weeks later...
Quote

If the driver doesn’t receive a Status Code: 200 from the webhook URL it will deregister the events.

 

I am curious what this means. Any retry functionality?

I use AWS lambdas through API Gateway a lot. There are occasional hicups in their services over time. Curious what is built in to handle timing and retries.

Link to comment
Share on other sites

1 hour ago, Pounce said:

 

I am curious what this means. Any retry functionality?

I use AWS lambdas through API Gateway a lot. There are occasional hicups in their services over time. Curious what is built in to handle timing and retries.

I did this to not overwhelm the box with unnecessary 404 or 500s if the service went down. I could build in a back off and retry algorithm or something and deregister after a number of failures. that seems like a good idea. 

Link to comment
Share on other sites

2 hours ago, harper said:

I did this to not overwhelm the box with unnecessary 404 or 500s if the service went down. I could build in a back off and retry algorithm or something and deregister after a number of failures. that seems like a good idea. 

Yea, I think without some way of managing typical occurrences of internet outages and endpoint fussiness a person might be having to re-register things. 

Thanks for creating this driver. Seems like an obvious value add that should be part of control4.

Link to comment
Share on other sites

Just now, Pounce said:

Yea, I think without some way of managing typical occurrences of internet outages and endpoint fussiness a person might be having to re-register things. 

Thanks for creating this driver. Seems like an obvious value add that should be part of control4.

You might want to try it and see if you run into issues. I have had it hit both a docker instance and lambda with no issues. 

Link to comment
Share on other sites

I use api gateway at a pretty large scale. Millions of calls. It just has hiccups guaranteed over time. AWS isn't 100%. Sure, nothing mission critical here most of the time. Connectivity to the internet is also not going to be 100%. I'm only thinking about trying to make it stable enough demanding control4 owners. Self healing.

Link to comment
Share on other sites

4 minutes ago, Pounce said:

I use api gateway at a pretty large scale. Millions of calls. It just has hiccups guaranteed over time. AWS isn't 100%. Sure, nothing mission critical here most of the time. Connectivity to the internet is also not going to be 100%. I'm only thinking about trying to make it stable enough demanding control4 owners. Self healing.

makes sense. I will work that in for the next release. 

Link to comment
Share on other sites

  • 6 months later...

@harper, I'm trying to use this to see the alarm motion sensors in Home Assistant (sensor.http), but I guess I need to build a kind of translator, right? So I'm using a web server to get the webhooks, extract what I need and then send it to HA's API. 

Is there a better (more direct) way?

Thanks for the great work!

Link to comment
Share on other sites

The easiest way to connect them together is to run nodered as the "conduit."

Control4 Webhooks -> NodeRED -> HASS

You can use nodered to transform the webhooks payload into MQTT that hass can understand. 

Let me know if this makes sense. 

 

NodeRed is pretty nice and should allow you to get what you want done. You can also transform the webhook from control4 into a different formed webhook that would be nearer what the sensor.http expects. 

 

Let me know how it works out

 

Link to comment
Share on other sites

On 3/26/2018 at 1:29 AM, harper said:

I am thinking about this as well. I will make a section where you can enter the proxy types manually. 

<property>
  <name>Device Selector</name>
  <type>DEVICE_SELECTOR</type>
  <items>
    <item>tv.c4i</item>
    <item>media_player.c4i</item>
    <item>dvd.c4i</item>
  </items>
  <multiselect>true</multiselect>
</property>


The above would let you select drivers using TV, DVD, and Media Player proxies. Add this for the proxy types you're using and just let the dealer select the actual devices they want to monitor.

I've included an example of a device selector searching for remotes:

image.png.df6094d7a7984389572b66044be7a743.png

<property>
  <name>Remote</name>
  <type>DEVICE_SELECTOR</type>
  <items>
    <item>control4_sr260.c4i</item>
    <item>control4_sr250.c4i</item>
  </items>
  <multiselect>false</multiselect>
</property>

 

Link to comment
Share on other sites

On 10/8/2018 at 5:46 AM, harper said:

Let me know how it works out

Thanks for the help. The little php script I did serves the translation purpose for now, while I look into Nose RED (which is new to me).

+1 for the retry functionality, as hiccups happen and when traveling I don't have access to Composer to reset the driver.

One little thing: even though events are registered, the properties screen always says 'false':

image.png.b473e0c962f15f2f9df16d0439d8f25e.png

And here too:

image.png.3b870d3cbbe1be8ba86dd39addf4490a.png

Is this correct?

Thanks for this great little gem!

Link to comment
Share on other sites

On 10/10/2018 at 12:14 PM, TheWizard said:

<property>
  <name>Device Selector</name>
  <type>DEVICE_SELECTOR</type>
  <items>
    <item>tv.c4i</item>
    <item>media_player.c4i</item>
    <item>dvd.c4i</item>
  </items>
  <multiselect>true</multiselect>
</property>


The above would let you select drivers using TV, DVD, and Media Player proxies. Add this for the proxy types you're using and just let the dealer select the actual devices they want to monitor.

I've included an example of a device selector searching for remotes:

image.png.df6094d7a7984389572b66044be7a743.png


<property>
  <name>Remote</name>
  <type>DEVICE_SELECTOR</type>
  <items>
    <item>control4_sr260.c4i</item>
    <item>control4_sr250.c4i</item>
  </items>
  <multiselect>false</multiselect>
</property>

 

I am still trying to figure out the best way to do this. Just entering the various drivers gets unwieldy - but i will try it out. 

 

In the meantime, I can do a new build with a lot more drivers enabled. Which drivers should i enable? 

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.