General advice on App Development

Discussions about Z-Way software and Z-Wave technology in general
Post Reply
sionp
Posts: 2
Joined: 21 Apr 2023 23:23

General advice on App Development

Post by sionp »

Is there any gereral advice on building apps for Z-Way somewhere? I've read the very concise section in the manual: https://z-wave.me/files/manual/z-way/Sp ... 0000000000, and watched the following YouTube tutorial https://www.youtube.com/watch?v=WehgQUIiFK0&t=103s, which was an useful start. However, none of these provide any guidance on how to test and debug your app when developing it.

E.g. user module code appears to be cached. When I make a change I'm seeing error messages (in z-way-server.log) for code that I have since replaced or deleted. Removing and re-installing the app (from the 'Active Apps' page) doesn't work, nor does stopping and restarting the Z-Way server. The only way around it is rebooting the Pi, but that makes it a very laborious process. Is there any qucker way ro clear and reload the app?

For info, I have done some JS development (mainly jQuery, however) in the past, but that was all browser-based. I have more experiance in PHP / Python / Bash development.

I'd be grateful for any further help anybody could provide.
--
Sion
seattleneil
Posts: 172
Joined: 02 Mar 2020 22:41

Re: General advice on App Development

Post by seattleneil »

Here's 2 tips that helped me develop the LevitonZone app for the VRCZ4-M0Z multi-button scene controller device. Note that I've replaced the Leviton devices with Zooz ZEN32 scene controllers that I highly recommend. Also note that other people have far more Z-Way knowledge than me - take this reply with a grain of salt. I assume you are storing your app in a subdirectory of /opt/z-way-server/automation/userModules/.

1. If you modify your app, reload the app by running the following command:

Code: Select all

curl -s -u admin:[PASSWORD] --globoff '127.0.0.1:8083/ZAutomation/api/v1/modules/reinitialize/[MODULE-ID]
The [MODULE-ID] is the moduleName value in file module.json which should match the name of the subdirectory and _module in index.js.

2. Use the console.log() function in file index.js to write debug statements to the z-way-server.log file. Something like this:

Code: Select all

var value = vDev.get("metrics:level");
var type = vDev.get("deviceType");
console.log("MyApp: received notification for",type,"device",vDev.id,"with value",value);
Depending on what you're trying to do, the Easy Scripting app provides tremendous flexibility for creating complex automation logic in JS. For example, instead of creating an app for controlling the LEDs on a Zooz ZEN32 scene controller (like I did for the Leviton VRCZ4-M0Z), I wrote the ZEN32 LED control logic using the Easy Scripting app. Another very powerful app is the Virtual Device (JavaScript) - it supports a variety of device types that are written in JS. Lastly, because Z-Way does not protect itself from a poorly written app (i.e., it's easy to hang Z-Way the automation engine), my preferred method for extending Z-Way functionality is to put the extended functionality outside of Z-Way. Specifically, I use the HTTP Device app to create a new device, where the new device makes an HTTP call to a python web server running on port 8000 (/usr/bin/python3 -m http.server --cgi 8000) and create a python script in cgi-bin/ to realize the device's functionality. This approach isolates Z-Way from non-Z-Wave oddities.
Post Reply