ZWD API


 ZWD API




There are 3 types of API interfaces
  • Hue Emulation - appears to App and other devices as if it were a Hue Hub - see our Hue emulation documentation
  • ZWD API transmit - this is how a user script can send lighting control commands
  • ZWD API receive - this is how a user script can receive commands from the lighting bus



user script to ZWD API

Python Example of the API for ZWD  (see AL-DALI-HAT datasheet for details)
-----------------------------------------------------------------------------
# first set all to 50%
# then to off
# then to 100%
# then to off
# then read level from the device at address 1

import requests
import time

headers = {
    'Content-type': 'application/json',
}

# set all to 50% D_on80 = '{"channel":0,"commands":["hFE80"]}'

# set all to 100% D_on = '{"channel":0,"commands":["hFEFE"]}'

# set all to 0% D_off = '{"channel":0,"commands":["hFF00"]}'

# read back the current level of address 1 D_query = '{"channel":0,"commands":["h03A0"]}'
# multicommand ( all off, all on, all off ) D_OffOnOff = '{"channel":0,"commands":["hFE00","h0AFE","hFE00"]}'
----------------------------------

# send a command string response = requests.post('http://localhost/dali/api/send-raw', headers=headers, data=D_on) if response.status_code == 200 : print("Success, result data %s"%response.text)
# response would be 
{"ok":true,"responses":["N","N","N"]}



from ZWD to user script API




#!/usr/bin/env python3
# This is an example script for the ATX-LED streaming event API.
# This code waits for messages from the ZWD server, which are triggered
# in the Schedule or Macro pages. To use this code, set up a scheduled
# event or a macro, and select 'Send a message to a script' in the Action # dropdown. You can choose to specify a string of characters to send to
# this script (as specified in the above action). This message will be sent # to this script (in the form of a UTF-8 encoded string of bytes), and the
# code within main() below can decide what to do based on the message.

# the variable [DALI1] and [DALI2] if found in the string, will be replaced by the first and 2nd
# bytes of the DALI command that triggered the Macro, thus one script can service many
# buttons in a 8B, 010v or DR2-nWay

# do not create a file or directory "api-events"
import os
import socket
SOCKET_PATH = '/home/pi/atxled/api-events'

def main():
    for message in listen_for_messages():
        # Application logic goes here!
        # You can parse the message and do whatever you want here.
        print('Got a message: %s' % message)
# This generator function waits for messages. You probably don't need to modify it.
def listen_for_messages():
    sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
    try:
        sock.bind(SOCKET_PATH)
        sock.listen(0) # queue 0 responses
        while True:
            [conn, addr] = sock.accept()
            message = conn.recv(64)
            yield message
            conn.close()
    finally:
        os.unlink(SOCKET_PATH)
if __name__ == '__main__':
    main()


TriggerAPI

Important notes on this trigger - the trigger is sent when a 0 -> 1 transition occurs, multi "On" with no intermediate "Off" will not create a trigger event.

API-Hello






     RSS of this page