custom Function

Discussions about RaZberry - Z-Wave board for Raspberry computer
Post Reply
dario87
Posts: 18
Joined: 13 Jun 2014 11:46

custom Function

Post by dario87 »

hi,
I would like to know how I can create a custom function (for example, a scenario) and how can I call it using the JSON-API.

For example if I want to call the function

function myFunctio () {
zway.devices[2].SwitchBinary.Set(1);
zway.devices[3].SwitchBinary.Set(0);
zway.devices[4].SwitchBinary.Set(1);
}

how can i to do?
must i to insert the function in utomation/main.js?
must I to use a module?

Can you to help me please?

thanks
pz1
Posts: 2053
Joined: 08 Apr 2012 13:44

Re: custom Function

Post by pz1 »

You can do this at the moment with a scene in the latest version (1.7.1-rc2) using the develop branch of Home Automation
Since 29-12-2016 I am no longer a moderator for this forum
pofs
Posts: 688
Joined: 25 Mar 2011 19:03

Re: custom Function

Post by pofs »

What you described above, perfectly fits a light scene concept.

But if you really want to make it a function, the simplest way is to put your it into a separate js file under z-way-utils/ folder. It will be accessible as http://ip:8083/ZAutomation/YourFunctionName after z-way-server restart.
pz1
Posts: 2053
Joined: 08 Apr 2012 13:44

Re: custom Function

Post by pz1 »

pofs wrote: a separate js file under z-way-utils/ folder
@pofs
Do the contents of that folder survive a version upgrade?
Since 29-12-2016 I am no longer a moderator for this forum
pofs
Posts: 688
Joined: 25 Mar 2011 19:03

Re: custom Function

Post by pofs »

pz1 wrote:
pofs wrote: a separate js file under z-way-utils/ folder
@pofs
Do the contents of that folder survive a version upgrade?
No, it doesn't. Only userModules folder survives it.
But I've said it is the simplest way, not the best one :)
dario87
Posts: 18
Joined: 13 Jun 2014 11:46

Re: custom Function

Post by dario87 »

hello,
thank you very much to everyone for your answers!
were very helpful.
I have another question:
how do I listen to an event from the network and call my function?
For example, if the switch changes state I see the change from the log file.
I want that when there is a change, is executed my function "myFunction ()".

is it possible?
how can I to do?


thanks
Post Reply