Can't retrieve level from vdev

Discussions about RaZberry - Z-Wave board for Raspberry computer
Post Reply
FrankR
Posts: 33
Joined: 23 Nov 2015 22:03

Can't retrieve level from vdev

Post by FrankR »

Hi @all,
I've been playing around with my RaZberry for a few days. Have one Comet Z-Wave heating device running together with some time automation.
Now I want to get a bit deeper into automation stuff. I've been playing around with some scenes, logicalRules and dummy device.

Here is my question: How can I retrive the value of "level" from a virtual device via http and via JS?

My vdev is called "DummyDevice_33".
Using "http://pi2-01:8083/ZAutomation/api/v1/d ... yDevice_33" returns this:
"{"data":{"creatorId":33,"deviceType":"switchMultilevel","h":-1669838527,"hasHistory":false,"id":"DummyDevice_33","location":2,"metrics":{"level":21,"title":"HeizungDummy"},"permanently_hidden":false,"tags":[],"visibility":true,"updateTime":1450030680},"code":200,"message":"200 OK","error":null}"

But what I really want to see is the value of level, in this case: 21

Using "http://pi2-01:8083/ZAutomation/api/v1/d ... ommand/Get" only returns a 404 error. What am I doing wrong?

regards
Frank
AlphaX2
Posts: 110
Joined: 25 Jul 2015 15:03

Re: Can't retrieve level from vdev

Post by AlphaX2 »

Hi,

using vDev API gives you a standard JSON response and it's meant to be used in some kind of frontend/backend logic that can evaluate and/or show the value of level. In your browser you'll not get just "21" that easy. How to send commands and which commands for what elements are available can be found online: http://docs.zwayhomeautomation.apiary.i ... ces/device

It's possible to use commands with VirtualDevices at all as long as it is on the Dashboard and depending on the kind of element your virtual device is. Toogle- and BinaryButton should work with .../command/on and .../command/off for example.

Alternative could be using the JS API, which mirrors the CommandClasses very much, in this case have a look into the developer book (zWayDev.pdf) you can download on razberry page.
FrankR
Posts: 33
Joined: 23 Nov 2015 22:03

Re: Can't retrieve level from vdev

Post by FrankR »

Hi AlphaX2,
thanks for your help.

I should have mentioned that I read both docs you pointetd to. But, sorry to say: all this didn't help.
An example:
Using "http://pi2-01:8083/JS/Run/zway.devices[ ... oint.Set(1, 22)" works perfectly for my physical device. This call returns null and sets the temperature on my thermostat to 22. So far, so good.

But "http://pi2-01:8083/JS/Run/zway.devices[ ... evel.Set(1, 22)" only returns "TypeError: Cannot read property 'SwitchMultilevel' of undefined".
Device #33 is my virtual device named "DummyDevice_33" (from my first posting) which now apperas on the dashboard (I forgot this last time) and is defined as a SwitchMultilevel.

It seems to me that all these commands work perfectly on physical devices but none of them on virtual devices.

Can anybody give an example how to get (or set) the value of level (or even other data) from a virtual device?

regards
Frank
AlphaX2
Posts: 110
Joined: 25 Jul 2015 15:03

Re: Can't retrieve level from vdev

Post by AlphaX2 »

Hi Frank,

the behavior you've described is normal. With the ZWave/JS API you can just control physical devices. The "vDev" API allows you to control also your virtualDevices, but as well the physical.

The question is: what you are using for sending commands? A normal webbrowser is not really meant to do this. The APIs are for usage in a front- or backend, maybe an app, or the web ui. I like running python scripts directly on the Pi to do stuff. :)

Maybe it's a better idea to describe the result you wish and we'll find a solution to do this?
FrankR
Posts: 33
Joined: 23 Nov 2015 22:03

Re: Can't retrieve level from vdev

Post by FrankR »

Hi AlphaX2,

you're right. I should have described better what I wanted to do.

Ok, the first thing is that I just want to check out how devices can be accessed by the commands from the developer docs. As I am not familiar with Python I just used my web browser for a quick access.

I also tried to solve an automation task by using as much of the z-wave.me tools (scenes, schedules scenes, dummy devices etc.) as possible and as little code as possible. I am very familiar with C but I want to use a programming language only if there is no other way.

The automation task goes like this:
There's a room with one heating that can be controlled via z-wave thermostat. The room has two windows, each of them is equipped with a window switch. The thermostat shall be switched to different temperatures througout the day. Each of the window switches shall switch the thermostat to 5° when they are off (window open). When both window switches are on (windows closed) the thermostat shall be switched to the temperature of the last actived scene even if one or both windows were open when the scene was activaed by the time controller.

For example: at 05:30 switch thermostat to 21°, at 09:00 switch thermostat to 19°, at 15:00 switch thermostat to 21° and at 20:00 switch thermostat to 18°. This is easily solved with 3 LightScenes (21°, 19°, 18°), 4 ScheduledScenes (05:30, 09:00, 15:00, 20:00) and a CodeDevice that contains "zway.devices[3].ThermostatSetPoint.Set(1,%%))" . Another LightScene that switches the thermostat to 5° might be helpful too. A LogicalRule activates this last LightScene if at least one of the switches window1 or window2 is off. If at least one window is opened the thermostat receives 5°. Simple! But what happens when the last open window is closed? Nothing, very sad! The thermostat does of course not return to it's last level. And to make it a bit harder, it does of course not receive the temperature of a scene that was actived while the windows were open.

And here is my solution (keep in mind: maximum use of provided tools, little code!).
The ScheduledScenes do not activate the aboves mentioned LightScenes directly but they activate some "trigger" LightScenes which switch a DummyDevice to the intented level (18, 19, 21). So there's 3 of them. LogicalRules submit the level of this DummyDevice to the thermostat but only if both window switches are on. Rule1 "window1 on AND window2 on AND DummyDevice=21" switches the thermostat to 21. Rule2 "window1 on AND window2 on AND DummyDevice=19" switches thermostat to to 19. Rule3 "window1 on AND window2 on AND DummyDevice=18" switches the thermostat to 18. This works! But it is a very stupid solution. Every rule keeps the temerature twice (in the constraint and in the action) and the LightScenes also keep them to switch the DummyDevice. This will become buggy over the time. Especially when I need to adjust the temperature levels. One simple LogicalRule could do all the stuff like this: "window1 on AND window2 on AND DummyDevice>0" action "zway.devices[3].ThermostatSetPoint.Set(1, ReadTheF***ingLevelOfADummyDevice(33))".

I want to use the DummyDevice as a global variable in a programming language. That's why I need to read it's level.

Gosh! I hope I was able to describe what I want to do.

Regards
Frank
pz1
Posts: 2053
Joined: 08 Apr 2012 13:44

Re: Can't retrieve level from vdev

Post by pz1 »

FrankR wrote:"zway.devices[3].ThermostatSetPoint.Set(1, ReadTheF***ingLevelOfADummyDevice(33))".
I think using ReadTheFuckingLevelOfADummyDevice is your problem.
FrankR
Posts: 33
Joined: 23 Nov 2015 22:03

Re: Can't retrieve level from vdev

Post by FrankR »

pz1 wrote:
FrankR wrote:"zway.devices[3].ThermostatSetPoint.Set(1, ReadTheF***ingLevelOfADummyDevice(33))".
I think using ReadTheFuckingLevelOfADummyDevice is your problem.
Correct, apart from that I forgot a ;-)
Didn't want to sound angry and used some * therefore.
Guenter
Posts: 6
Joined: 15 Dec 2015 20:16

Re: Can't retrieve level from vdev

Post by Guenter »

what's the problem ?

Code: Select all

gms@sirius:~$ PS1=
curl -b cookie.txt "http://localhost:8083/JS/Run/controller.devices.get('DummyDevice_5').get('metrics:level')"
99
curl -b cookie.txt "http://localhost:8083/JS/Run/controller.devices.get('DummyDevice_5').set('metrics:level',42)" 2>/dev/null
{"creationTime":1450517150,"creatorId":5,"deviceType":"switchMultilevel","h":-1577886412,"hasHistory":false,"id":"DummyDevice_5","location":0,"metrics":{"level":42,"title":"Dummy Device"},"permanently_hidden":false,"probeType":"","tags":[],"visibility":true,"updateTime":1450529289}

curl -b cookie.txt "http://localhost:8083/JS/Run/controller.devices.get('DummyDevice_5').get('metrics:level')"
42

FrankR
Posts: 33
Joined: 23 Nov 2015 22:03

Re: Can't retrieve level from vdev

Post by FrankR »

Guenter wrote:what's the problem ?
[/code]
There's no problem anymore ;) Guenter, you made my day! Code works great. The problem in all my attemps was that I ignored "controller" and that I have to "get" the device first :roll:

Now I put "controller.devices.get('DummyDevice_26').set('metrics:level', controller.devices.get('DummyDevice_33').get('metrics:level'))" into a CodeDevice and my DummyDevice_33 controls DummyDevice_26 (which is just for testing and will be replaced by my physical device).

Thanx a lot!
Post Reply