Skip to content

Latest commit

 

History

9 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Universal HTTP Sender - Control4 Driver v2

Download

universal_http_sender.c4z

System requirements:

1.     OS 2.10.5+

The Universal HTTP sender is a revision of the DriverWorks generic_http driver. It is designed to send GET, POST, PUT or DELETE commands to one of five pre-defined URLs (set in Properties) or a manually defined URL (set in the Command parameters). Variable and events are provided for basic handling of any response. These commands are available for use in the programming section of Composer by selecting “Universal HTTP Sender” in the Actions menu.

Properties

Debug Mode:

When set to On, prints out on the Lua tab the URL being requested and the response from the remote server (or in case of an error, the error message)

URL Timeout:

The time (in seconds) that the URL engine will wait for a response before timing out and returning an error.

Preset URL [1-9]

Enter a URL here (including the leading http:// or https://) for later access in programming

Commands

GET Preset: [PRESET, JSON_HEADER]

Send a HTTP GET command to the URL predefined on the Properties page in Preset [PRESET] with an optional header [JSON_HEADER]

GET Manual: [URL, JSON_HEADER]

Send a HTTP GET command to the URL specified in [URL] with an optional header [JSON_HEADER]

POST Preset: [PRESET, DATA, JSON_HEADER]

Send a HTTP POST command to the URL predefined on the Properties page in Preset [PRESET] with attached data as specified in [DATA] and an optional header [JSON_HEADER]

POST Manual: [URL, DATA, JSON_HEADER]

Send a HTTP POST command to the URL specified in [URL] with attached data as specified in [DATA] and an optional header [JSON_HEADER]

PUT Preset: [PRESET, DATA, JSON_HEADER]

Send a HTTP PUT command to the URL predefined on the Properties page in Preset [PRESET] with attached data as specified in [DATA]and an optional header [JSON_HEADER]

PUT Manual: [URL, DATA, JSON_HEADER]

Send a HTTP PUT command to the URL specified in [URL] with attached data as specified in [DATA] and an optional header [JSON_HEADER]

DELETE Preset: [PRESET, JSON_HEADER]

Send a HTTP DELETE command to the URL predefined on the Properties page in Preset [PRESET] with an optional header [JSON_HEADER]

DELETE Manual: [URL, JSON_HEADER]

Send a HTTP DELETE command to the URL specified in [URL] with an optional header [JSON_HEADER]

Variables

HTTP_ERROR(string)

The error string returned from the URL engine, or an empty string if there was no error.

HTTP_RESPONSE_CODE(number)

The HTTP response code returned from the HTTP server, or 0 if there was an error.

HTTP_RESPONSE_DATA(string)

The data returned from the HTTP server, or an empty string if there was an error.

Events

Success

Fires when the HTTP command was successfully sent to the server and an HTTP response code was returned. The HTTP_RESPONSE_DATA and HTTP_RESPONSE_CODE variables will be populated with the data from the URL call.

Note that an HTTP 400 or 500 response will still result in the Success event but indicates either a client or server error.

Error

Fires when the URL engine returns an error.  The HTTP_ERROR variable will be populated with the error code from the URL engine.

Example Use Cases

Webhooks

Use this driver to send a HTTP command to a webhook created with an external device/service. Enter the webhook URL into the URLfield and run a GET command.

Home Assistant

Send API calls to Home Assistant to control devices that are not compatible with Control4 or require a driver that you do not have.

See https://developers.home-assistant.io/docs/api/rest/ for all REST API commands you can send from this driver to Home Assistant.

E.g. Running a Home Assistant Script from Control4:

1.      From the Home Assistant Sidebar go to Profile > Security and scroll to ‘Long-lived access tokens.’

2.      Select ‘Create Token’, set a name, and copy the generated token.

3.      In Composer use one of the POST commands via an action in the programming section or by the driver’s action tab in system design (for testing).

4.      Paste your token into the JSON_HEADER field using the format below and replace 'TOKEN_HERE' with your Home Assistant Access Token:

{ “Authorization": "Bearer TOKEN_HERE" }

5.      In the URL field enter your home assistant URL and PORT followed by the script path like the example below:

http://192.168.x.x:8123/api/services/script/my-script

6.      If your script requires fields, add these to the DATA field in JSON format like the example below:

{ "entity_id":"media_player.my_media_player" }

7.      Execute the script to send the HTTP Command to Home Assistant.

8.      Turn on debugging in the driver’s properties to print output/error messages to the Lua tab.

Changelog

v2

Updated to utilise the newer C4:url() URL interface which is better supported by the more recent X4 OS.

About

No description, website, or topics provided.

Resources

Stars

9 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages