How to use EasyScripting?

Discussions about Z-Way software and Z-Wave technology in general
Post Reply
shaldi
Posts: 3
Joined: 11 May 2020 12:38

How to use EasyScripting?

Post by shaldi »

Hi

I'm quite new to the Z-Way stuff. I saw the announcement of the EasyScripting App that I'm very interested in to bind two systems.

So I would like to use the EasyScripting Module to call a web hook of another system via HTTP POST request. The Javascript code to call the request I got from the example documentation of the App.

But how can I integrate the Script within a (automation) rule? I would like to trigger the script only if a sensor value has reached a specific threshold.

Can I use the EasyScript for automation (rules) or do the scripts has to be "selfcontained" including trigger, conditions and actions (if-then-else)?

Thanks!

User avatar
PoltoS
Posts: 5524
Joined: 26 Jan 2011 19:36

Re: How to use EasyScripting?

Post by PoltoS »

Please have a look on the Easy Scripting app - in Chrome it should help you to write the code with a helper.

shaldi
Posts: 3
Joined: 11 May 2020 12:38

Re: How to use EasyScripting?

Post by shaldi »

Thanks for your reply!

What I don't understand is WHEN the Script is being triggered/called?

How can I add a Trigger Condition (e.g. Pseudo Code: If (rainSensor.value() > 0))?

ridewithstyle
Posts: 114
Joined: 02 Jan 2016 01:20

Re: How to use EasyScripting?

Post by ridewithstyle »

it is explained in the the app documentation, the script gets triggered on a value update you can specify (even multiple triggers). In you case, it is rainSensor's value. Find the ID of the sensor reading by browsing to in in ZWay and in the browser link you see something like 192.168.0.255:8083/smarthome/#/element/ZWayVDev_zway_50-0-49-1. Take the Device Identifier into your easy scripting app

### ZWayVDev_zway_50-0-49-1

and everytime the value gets updated by ZWay, your script gets called.

shaldi
Posts: 3
Joined: 11 May 2020 12:38

Re: How to use EasyScripting?

Post by shaldi »

Thanks for your hints!

Currently my script looks like this:

Code: Select all

var req = {method: "POST", async: true}
if (vdev("ZWayVDev_zway_2-0-49-12").value() > 0) {
    req.url = "http://<hostname>:<port>/api/webhook/rain"
}
else {
    req.url = "http://<hostname>:<port>/api/webhook/norain"
}
http.request(req)
The rain rate value has multiple times be over 0.
But the web hooks are not called :( ...
Am I missing something? How can I debug this? Is there a log file or something?

ridewithstyle
Posts: 114
Joined: 02 Jan 2016 01:20

Re: How to use EasyScripting?

Post by ridewithstyle »

Because you are missing the event trigger

Code: Select all

//Trigger this script every time that ZWayVDev_zway_2-0-49-12 gets updated
### ZWayVDev_zway_2-0-49-12

var req = {method: "POST", async: true}
if (vdev("ZWayVDev_zway_2-0-49-12").value() > 0) {
    req.url = "http://<hostname>:<port>/api/webhook/rain"
}
else {
    req.url = "http://<hostname>:<port>/api/webhook/norain"
}
http.request(req)
at the beginning of your script. If your script has multiple values it shall react to you can add additional trigger lines starting with ###.

To simply select those trigger events from all those available on your system, call the easy app code editor from a chrome browser and you see extended support

Post Reply