It would be nice if there was something like a http notification channel, so you can trigger HTTP Requests as notifications (for example for calling HTTP-APIs like https://ntfy.sh/).
At the moment this is only possible by creating a http device for every message that should be sent via HTTP and using this in if-then or logical rules.
A notification channel that always uses the same URL and different notification messages in POST or GET Parameters would simplify that.
HTTP Notification channel
-
- Posts: 203
- Joined: 02 Mar 2020 22:41
Re: HTTP Notification channel
This response assumes you're familiar with python.
Have you looked at the HTTPGet app? It will make a user-defined HTTP request whenever any device changes state. Using this app, I'm able to process any Z-Way device status changes inside a single python CGI script, where the CGI script can be used to send a device-specific HTTP request. This approach eliminates the need to create individual HTTP devices in Z-Way. Just set the HTTPGet URL to something like:
To process the HTTPGet app request, I run /usr/bin/python3 -m http.server --cgi 8000 as a daemon to execute my CGI script where the script does whatever I want (such as making a device-specific HTTP request). Here's a starting point for your python CGI script:
To reduce the number of CGI calls made by the HTTPGet app, I modifiied the HTTPGet index.js file as shown below.
Since this approach is much more complicated than relying on Z-Way's internal logic, it may not be the answer you're looking for.
Have you looked at the HTTPGet app? It will make a user-defined HTTP request whenever any device changes state. Using this app, I'm able to process any Z-Way device status changes inside a single python CGI script, where the CGI script can be used to send a device-specific HTTP request. This approach eliminates the need to create individual HTTP devices in Z-Way. Just set the HTTPGet URL to something like:
Code: Select all
http://127.0.0.1:8000/cgi-bin/zway.py?device=%DEVICE%&state=%VALUE%
Code: Select all
#!/usr/bin/python3
# Python script to listen on port 8000 as an HTTP server
# Run server command: python3 -m http.server --bind localhost --cgi 8000
# This will run the CGIHTTPServer python module which expects the current working directory to have a cgi-bin subdirectory
# where this file exists
# Curl command for testing: curl --globoff '127.0.0.1:8000/cgi-bin/zway.py?device=XX&state=YY
import os
from urllib.parse import parse_qsl
import re
query = os.environ.get("QUERY_STRING")
params = dict(parse_qsl(query))
if "device" in params:
device = params["device"]
else:
device = "unknown"
if "state" in params:
state = params["state"]
else:
state = "unknown"
print("Content-type: text/html")
print("")
# DEBUG
print ('Request for device=' + device + ', state=' + state)
# Add if/then logic for whatever device and state change you want to process
Code: Select all
HTTPGet.prototype.updateDevice = function (device) {
var self = this;
var value = device.get("metrics:level");
if (device.get("deviceType") == "switchBinary" || device.get("deviceType") == "sensorBinary") {
if (value == 0) {
value = "off";
} else if (value == 255) {
value = "on";
}
}
if (device.get("deviceType") == "switchBinary" || device.get("deviceType") == "switchMultilevel" || device.get("deviceType") == "doorlock") {
self.get_url(device, value);
}
};