Good Afternoon
I wonder if someone could point me in the right direction, I have node-red running fine and have installed Zwavejs successfully along with my USB zwave controller.
I have included a AEON Labs ZW096 plug in switch with a node id of 15
I have tried using the command factory node but to be honest I am at a loss
If anyone could help me basically understand how to switch it on and off I would be very grateful
HI @fogmajor
To control a plug - it likey uses the binary class.
See attached example
[{"id":"28a7c094d7479125","type":"cmd-factory","z":"2d7bf6e3.84c97a","name":"ZWave CMD Factory","node":"topic","endpoint":"0","cc":"Select Command Class","method":"Select Method","params":"payload","noEvent":false,"forceUpdate":"forceUpdate","api":"ValueAPI","vapiMode":"setValue","vapiValue":"payload","vapiValueId":"valueId","vapiOptions":"options","x":540,"y":1020,"wires":[["f0352aa9e33beec2"]]},{"id":"6d75fd42974aafcd","type":"inject","z":"2d7bf6e3.84c97a","name":"","props":[{"p":"valueId","v":"{\"commandClassName\":\"Binary Switch\",\"commandClass\":37,\"endpoint\":0,\"property\":\"targetValue\",\"propertyName\":\"targetValue\"}","vt":"json"},{"p":"topic","vt":"str"},{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"15","payload":"true","payloadType":"bool","x":290,"y":1000,"wires":[["28a7c094d7479125"]]},{"id":"9baa7c70f9ac599c","type":"inject","z":"2d7bf6e3.84c97a","name":"","props":[{"p":"valueId","v":"{\"commandClassName\":\"Binary Switch\",\"commandClass\":37,\"endpoint\":0,\"property\":\"targetValue\",\"propertyName\":\"targetValue\"}","vt":"json"},{"p":"topic","vt":"str"},{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"15","payload":"false","payloadType":"bool","x":290,"y":1040,"wires":[["28a7c094d7479125"]]},{"id":"f0352aa9e33beec2","type":"debug","z":"2d7bf6e3.84c97a","name":"debug 387","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":530,"y":860,"wires":[]}]
To get the different Value IDs -double click one of class values in the side panel.
The value ID - is on object, that identifies the class and property to change.
Connect the Factory to your controller, for it to send the value to the network.
Marcus you are a superstar, I am now controlling the binary switch.
Sorry to be cheeky but could you point me on how to get the binary switches current state
Thank you so much
Kind Regards
Andrew
Hi Marcus I found the sidebar that displays all that is needed, Thank you again
All you would do, is set the method to get and use the current value id.
The factory uses JSONata, using the factory isn’t required, just helps to simplify your message
Hi Marcus
I changed the msg.valueid to
{"commandClassName":"Binary Switch","commandClass":37,"endpoint":0,"property":"currenttValue","propertyName":"currentValue"}
Set the factory to GET
the value comes back as undefined, i used an inject node with a payload of true
I am making slow progress but beginning to understand a little better
Could you clarify for me please if I have a zwave PIR and it detects will the device transmit the change or do i have to monitor its state permanently?
Hi @fogmajor
Real time events will get sent out from the controller as they happen.
As for getting the value, ensure your using the correct valueId for currentValue.(double click it) to see the value ID
The side bar is using the same methods - so should be there.
Print out the entire msg that that you receive back
Cheers and thank you again
You have 2 t’s in currentValue
Well spotted, at 65 years old they say its never to late to learn something new, I am beginning to wonder lol
Thanks Again
Good Morning Marcus
Many thanks for your help on my zwave journey.
You mentioned that you could work without the command factory, Are there any resources available on how to do that ie sending a command to turn on a binary switch?
Kind Regards
Andrew
Hi @fogmajor
Yes you can, using traditional function
nodes as an example.
const _nodeId = 25; /* Target Node */
const _value = true; /* Value */
const _valueId = {
"commandClass": 37, /* Binary Class */
"endpoint": 0, /* Target End point - The device might have 2 binary switches */
"property": "targetValue", /* Property */
}
const Message = {
payload: {
cmd: {
api: 'VALUE',
method: 'setValue'
},
cmdProperties: {
nodeId: _nodeId,
valueId: _valueId,
value: _value
}
}
}
return Message;
commandClass
, endpoint
, property
-are the only requirements for a value ID
sometimes propertyKey
- but not often.
the other bits are just metadata - so have omitted them
That's awesome thank you
I would prefer to use a function
Cheers
Andrew
The factory just builds the above - using inputs from an upstream message.
but there is nothing stopping you doing it yourself.
as long as you have the correct message structure.
Hi Marcus
Works like a dream thank you
Hi Marcus
Yes I am getting my head round it, I have written a function and passed nodeid and value variables and it works well, just working on getting values now
Thank you
Andrew
A few users, just keep a context variable database of values - and update them, as and when the controller spits out an update in real time
This way, you can fetch any value in a function - without asking the controller.
You can get the entire values database also
api = DRIVER
method = getValueDB
No need for cmdProperties for that one
It’s a big payload that gets returned - but is useful as a start up method in Node RED, you can then use it to create the context database - and update in real time as and when the controller sends an update (i.e from a sensor)
Values persists over reboots BTW - the driver stores them to disk, the values are updated (and alerts you) as they change via the device(s) sending an update
Hello again Marcus
Thank you for the last message.
In basic terms are you saying that at node-red startup you get the entire values database.
You then use context to assign the values, update when controller spits stuff out and then use those values to do as you wish?
Being newish scripting could you show me a function to get the entire values database please
You really have helped me understand the zwavejs funtionality
Cheers
Andrew
Correct..
You can instead, keep a mirrored copy of the drivers values, within your flow (via context memory)
- Using an
inject
Node, trigger this at Node RED Start up.
const Message = {
payload: {
cmd: {
api: 'DRIVER',
method: 'getValueDB'
}
}
}
return Message;
This will return the complete value DB from the driver.
You can then use a change
node to create a global variable, or use a function
Node, to store the result
global.set('ZWAVE_V_DB',msg.payload)
Later, you can refer to this database.
const zwaveValueDB = global.get('ZWAVE_V_DB')
You will need to engineer a mechanism / decide how you want to use the cached data set of course.
And also - update it, when the controller pushes out an update to you.
All this is just to skip the need to query the controller each time you want a value - but keeping an in process cached dataset, make things a littler easier.
see here for Context
Working with context : Node-RED