Page 1 of 1

CodeDevice - Status update - SOLVED

Posted: 05 Nov 2015 15:44
by ralfk
Hey, there!

I would say I'm new to zwave and razberry ... and somewhat overwhelmed by the possibillities generated by this automation-toolkit and so I'm looking for some guidance.
I have some minor experience in programming with nodejs (and so partially with JS).
I have managed to generated a CodeDevice based on a DÜWI-Wallplug which randomly delays switch-on and switch-off +-(1 to 10) Minutes.
Now I want this CodeDevice to update his status ... yeah I know it is not essentiall because the "real" düwi-device is updating his status ... BUT I want to know and learn ...
The düwi delivers his status as "true"(on) or "false"(off).
How does the function have to look for the status updating? Is only the returncode "on" / "off" needed ...
Where can I look for debug info? Maybe my "script" fails ... can I insert "debug lines" like console.log("reached point 1") ... where is it printed? ... is it the z-way-server.log? ... sorry didn't test it yesterday night ... it was too late.

Re: CodeDevice - Status update

Posted: 05 Nov 2015 20:51
by ralfk
@home again ...
Did some more test to understand the CodeDevice ... got only more questions ...

This is my CodeDevice (BinarySwitch):
on:
setTimeout(function(){zway.devices[3].Basic.Set(255)},Math.floor(((Math.random()*10)+1)*1000*60))

off:
setTimeout(function(){zway.devices[3].Basic.Set(0)},Math.floor(((Math.random()*10)+1)*1000*60))

real device[3] is switched on and off by the CodeDevice after a random amount of time.
It will happen that the real device[3] is switched by the GUI using the real device not the CodeDevice.
My target is to reflect this change of status in the CodeDevice.

1st Question:
I cannot write an interval for pulling ...more precise: I can write it, but it will be empty again after saving the CodeDevice. "30" is a valid input?
2nd Question:
I can put what I want to "Code to get value" ... I won't even get an error on something like "Quatsch^10{" ... this field seems not to be executed ... where is my misunderstanding?

Re: CodeDevice - Status update

Posted: 06 Nov 2015 00:15
by ralfk
... some hours later ...

One step more ...
Don't know why, but deleting the CodeDevice and starting from beginning, let's me define an update-time and this code in "Code to get value":
zway.devices[3].SwitchBinary.data.level.value

has a result in z-way-server.log:
Notification: device-info (device-OnOff): {"dev":"Code device 15","l":true}

so my last problem seems to be that this querry results in "true" and should be "on".
And there I'm stuck ... fighting heavily with callbacks in nodejs I have no idea how to write a valid function with a simple "if true callback('on')" ... or whatever
So the last question: How does a valid function looks like in "Code to get value"?

Re: CodeDevice - Status update

Posted: 07 Nov 2015 00:50
by ralfk
After another evening with some reading about
"expressions" and "statements"
and a look at the code of the CodeDevice-Module here is the solution:

Code to get value:
zway.devices[3].SwitchBinary.data.level.value == true ? "on" : "off";

Effekt:
The codedevice gets a status update every givin interval and changes its status shown in gui - even if the "real" Devices was switched in the gui. Target accomplished.

Background:
The input in the field "Code to get value" is run through an javascript eval() ... the rest is better explained by aunt google or mummy duckduckgo :)