User management / User access to Rules Scenes Apps

Discussions about Z-Way software and Z-Wave technology in general
manueldiasmanuel
Posts: 14
Joined: 10 Aug 2023 18:08

Re: User management / User access to Rules Scenes Apps

Post by manueldiasmanuel »

Hi seattleneil ,

You are right, and i am aware how easy it is to get the correct HTTP for physical devices. Zway is very friendly/Strong on that aspect.

My problem is diffrent , I am using the App Timer Switch to Switch ON a Motor of Fan ( physical device) , for let’s say 15 minutes and Switch off the the Motor Fan for 60 minutes, this being trigger by rules.

What I need is having a User Role to be able to change the time that the Motor Fan is ON and OFF.

The way I am doing ;


1- Install APP Timer Switch
2- Create Timer for Switch Off Motor Fan
3- Create timer for Switch On Motor Fan
4- Set time parameters for both Timers : Maximum time and change to minutes.
5- The two timers become available in Zway UI.
6- Create rules using Both Timers
7- All works very well.
8- Problem – How to adjust Timers Maximum Time without being having administrator rights ? In PIC-2 there is the API and the value i want to change is "max":120. Changing the level value works , but not the "max value.



I am learning a lot with your comments, thank you.

As curiosity , In attachment a Pic with POST method i use to change value on Node-RED.

Regards,

MD
Attachments
TimerSwitchPic-1.JPG
TimerSwitchPic-1.JPG (76.14 KiB) Viewed 1666 times
TimerSwitchiPic-2.JPG
TimerSwitchiPic-2.JPG (80.29 KiB) Viewed 1666 times
TimerSwitch3.JPG
TimerSwitch3.JPG (33.28 KiB) Viewed 1666 times
Node-RedPostHTTPToZway.JPG
Node-RedPostHTTPToZway.JPG (24.56 KiB) Viewed 1666 times
seattleneil
Posts: 172
Joined: 02 Mar 2020 22:41

Re: User management / User access to Rules Scenes Apps

Post by seattleneil »

Oops. I did not understand you wanted to change a parameter that's part of an app. What you want to do can be done, but it's a bit more complicated since the expert UI does not provide API information for virtual devices and the smarthome UI does not provide low-level API information for apps. To make it easier to understand, I'll give you the answer first and then I'll explain how you can change a parameter for any app.

Here's an example curl command to change the maxTime parameter to 30 in the TimerSwitch app that you can run on your Pi to do what you want:

Code: Select all

curl --include --request PUT --header "Content-Type: application/json" --data-binary '{"moduleId":"TimerSwitch","active":"true","title":"Timer Switch","params":{"unit":"minutes","maxTime":30}}' -u admin:[ADMIN PASSWORD] --globoff 'http://127.0.0.1:8083/ZAutomation/api/v1/instances/30'
For Node-RED, use the URL shown above in the http request node, choose the PUT method and pass in the following msg:
msg.payload = '{"moduleId":"TimerSwitch","active":"true","title":"Timer Switch","params":{"unit":"minutes","maxTime":30}}';

You will also need to add a Header for Content-Type with value application/json. You can either do this in the http request node UI or I think you can also add the header by passing in the following msg:
msg.headers = {};
msg.headers['Content-Type:'] = 'application/json';

The general approach for figuring out the correct HTTP request to change an app parameter takes 2 steps. First, you first need to determine the instance ID of the app you want to change. To fetch all instances of the TimerSwitch module, run the following curl command on your Pi:

Code: Select all

curl  -u admin:[ADMIN PASSWORD] --globoff 'http://127.0.0.1:8083/ZAutomation/api/v1/instances/TimerSwitch'
Next, fetch the instance information using the instance ID by running the following curl command on your Pi:

Code: Select all

curl  -u admin:[ADMIN PASSWORD] --globoff 'http://127.0.0.1:8083/ZAutomation/api/v1/instances/30'
I'm pretty sure these curl commands will work on your Pi because your PIC-2 API displayed the module ID as "TimerSwitch" and the instance ID as "30" (separated by "_" character).

Make sense?
manueldiasmanuel
Posts: 14
Joined: 10 Aug 2023 18:08

Re: User management / User access to Rules Scenes Apps

Post by manueldiasmanuel »

seattleneil ,

It works. You make magic happen :)


Regarding your question .... a litlle ;)



Thank you.
seattleneil
Posts: 172
Joined: 02 Mar 2020 22:41

Re: User management / User access to Rules Scenes Apps

Post by seattleneil »

Credit for the magic goes to the Z-Way developers.

Don't stress if these curl commands seem cryptic. I'm guessing the majority of Z-Way user's never get beyond using the smarthome UI. While that can be viewed as a sign of success, it can be limiting and hides a clever software architecture. If you want to gain a better understanding of how the Z-Way software is designed, here's a link to the developer info in the Z-Way manual:

Code: Select all

https://z-wave.me/manual/z-way/Develop_Code_Z_Way.html#
manueldiasmanuel
Posts: 14
Joined: 10 Aug 2023 18:08

Re: User management / User access to Rules Scenes Apps

Post by manueldiasmanuel »

Hi seattleneil ,

I have been navigating in the files content of Z-Way-Server and together with Z-way manual , the understanding looks a bit more clear now and it will very useful.

Regarding APIs the information is very good but is there any information regarding the UI ? A config file to play with ?

Thanks,

MD
seattleneil
Posts: 172
Joined: 02 Mar 2020 22:41

Re: User management / User access to Rules Scenes Apps

Post by seattleneil »

Here's what I do to "see" and understand the automation API commands...

1. I use the Chrome browser and enable Developer Tools where the Network tab shows me the requests and responses sent between the browser and z-way-server process (specifically, the zway/webserver thread). This is useful whenever the web UI does something that I want to do manually/programmatically - Developer Tools shows me the API request and response. Here's a screenshot of what appears when I press the button for a multilevel sensor (which causes the sensor's value to get updated):
Z-Way browser developer tools.jpg
Z-Way browser developer tools.jpg (99.85 KiB) Viewed 1627 times
Developer Tools shows the browser sends an update request to Z-Way. One of the things you'll quickly observe in Developer Tools is that the browser makes a request to Z-Way every 2 seconds asking if any device changes occurred in the previous 2 seconds. I suggest pressing the Stop icon in the Developer Tools after you've taken an action on the web UI since the every 2-second device change messages can obscure the API exchange you're trying to see. Please understand that climbing the Developer Tools learning curve is not a topic for this forum.

2. The Z-Way developers maintain the automation API documentation here:

Code: Select all

https://zwayhomeautomation.docs.apiary.io/
Taking the Developer Tools network trace example for the update request shown above, you can see the API information for sending a command (e.g., the update command for a sensorMultilevel virtual device) here:

Code: Select all

https://zwayhomeautomation.docs.apiary.io/#/reference/devices/devices-commands/send-command-to-device/200?mc=reference%2Fdevices%2Fdevices-commands%2Fsend-command-to-device%2F200
The list of commands that are possible for a virtual device are here (note that different device types will have different commands):

Code: Select all

https://zwayhomeautomation.docs.apiary.io/#/reference/devices/virtual-device
Hopefully you see the only valid command for a sensorMultilevel virtual device is update.

Taking the Developer Tools network trace example for the 2-second device change poll message, you can see the API information here:

Code: Select all

https://zwayhomeautomation.docs.apiary.io/#/reference/devices/devices-collection/list-all-devices/200?mc=reference%2Fdevices%2Fdevices-collection%2Flist-all-devices%2F200
Putting the pieces together... when the button for a multilevel sensor is pressed on the web UI, the browser emits an update command request for the sensor. Then the browser sits there and does nothing until the next 2-second device change request. Z-Way will respond to the device change request (presumably by sending an updated value for the sensor). In the web UI design, the action to update a multilevel sensor is asynchronous with the sensor level change being reported. In other words, the updated display for the sensor level is in response to the device change request and is not tied to the update request (although, the update request triggered the sensor's value to be updated).

Yes, it took me some time to understand the automation API. It's definitely not necessary if the web UI does everything you want/need. For advanced logic, I typically use the HTTP Device app or the EasyScripting app which does not require climbing the automaton API learning curve. If your brain has extra room, note that Z-Way actually has other APIs that you might find useful. Specifically, the expert UI doesn't use the automation API, rather, it uses the Z-Wave Device API (and therefore only understands Z-Wave devices). One effect of having multiple APIs is that Z-Wave devices can be controlled using either the automation API or the Z-Wave device API.

I realize this is a long answer, but I thought answering "no" to your question about playing with a config file would not be instructive.

Good luck.
manueldiasmanuel
Posts: 14
Joined: 10 Aug 2023 18:08

Re: User management / User access to Rules Scenes Apps

Post by manueldiasmanuel »


***** for your answers !!


Thank you very much for such instructive message.

A few weeks ago, I had little knowledge about Z-way and APIs in general , but with your help I feel that I´ve climbed up many steps in my knowledge.


Best regards and good luck for you too.
Post Reply