Hi,
I am pretty new to z-way - I've got my devices included, reporting their status correctly and responding to manual control through the UI. But now, despite many hours of trawling through the documentation, forums and the examples of code that I could find, I am really stuck trying to move to the next step: creating a simple heating schedule.
In principle it looks fairly simple: use something like cron to send a message to z-way to set a switch. But I just can't get past the basics of what sort of file to put where and what else do to with it.
Can you share any sample code or tips, please?
Thanks very much!
Pls share example code for switching on a schedule?
-
- Posts: 14
- Joined: 07 Jul 2014 22:41
Re: Pls share example code for switching on a schedule?
Hello jonespm,
i understand what you going trough because i found myself in the same situation a month ago.
A developer manual for beginners, accomplish with the actual "Z-Way Developers Documentation 1.7" would be very, very nice for starters like us! An "Hello world" example is hard (impossible) to find and you have to dig lots of forums/post to start to understand the logic behind our razberry!
I will explain what i did and maybe would help with your situation either.
Please note that probably this is not the correct way of doing it, but its a way that works for me with actual versions (1.7.2).
I created a folder inside "automation" folder and called it "myFiles".
Inside that folder i have 2 files:
- myZwave.js
- cron.js
The cron.js file is a very nice script made by Stefan Liebenberg that allows you to schedule events in JS like the actual crontab in linux. you can find it here:
https://github.com/StefanLiebenberg/cron.js/
The myZwave.js file contains my own code, including (but not only) some schedule events.
At start, it loads the cron.js file. Then i have my own code.
At the end, i use the "Load custom JavaScript file" module from automation UI to load my myZwave.js file automatically every time the system starts.
The load path of files are relative of automation/ folder.
As a simple examle of myZwave.js file could be(not tested):
Please note that every time you do any change on myZwave.js file, you must restart the zway system:
If you have any errors on the file, it will not be loaded, and you should pay attention on the logs of zway.
After an update of Zway system version, the folder myFiles may be deleted and you should create it again.
I believe that this is not the best method, so any other methods/comments would be appreciated.
BR,
i understand what you going trough because i found myself in the same situation a month ago.
A developer manual for beginners, accomplish with the actual "Z-Way Developers Documentation 1.7" would be very, very nice for starters like us! An "Hello world" example is hard (impossible) to find and you have to dig lots of forums/post to start to understand the logic behind our razberry!
I will explain what i did and maybe would help with your situation either.
Please note that probably this is not the correct way of doing it, but its a way that works for me with actual versions (1.7.2).
I created a folder inside "automation" folder and called it "myFiles".
Inside that folder i have 2 files:
- myZwave.js
- cron.js
The cron.js file is a very nice script made by Stefan Liebenberg that allows you to schedule events in JS like the actual crontab in linux. you can find it here:
https://github.com/StefanLiebenberg/cron.js/
The myZwave.js file contains my own code, including (but not only) some schedule events.
At start, it loads the cron.js file. Then i have my own code.
At the end, i use the "Load custom JavaScript file" module from automation UI to load my myZwave.js file automatically every time the system starts.
The load path of files are relative of automation/ folder.
As a simple examle of myZwave.js file could be(not tested):
Code: Select all
executeFile("/myFiles/cron.js");
var Crontab = new Cron(); //instatiates the Cron module
//simple example of turn on a wallPlug at specific time automatically
//runs every day, at 20h30m00sec
Crontab.add( new Cron.Job( "0 30 20 * * *", function () {
//get status of the switch. Change N and I, according to your actual config
var status = zway.devices[N].instances[I].SwitchBinary.data.level.value;
//if the swich is off, turn it on
if(status==false){
zway.devices[N].instances[I].SwitchBinary.Set(255);
}
}));
Crontab.start();
Code: Select all
sudo /etc/init.d/z-way-server restart
After an update of Zway system version, the folder myFiles may be deleted and you should create it again.
I believe that this is not the best method, so any other methods/comments would be appreciated.
BR,
Re: Pls share example code for switching on a schedule?
Folder userModules inside the automation folder is intended for storing user code that should survive a version upgrade.martinisonline wrote: I created a folder inside "automation" folder and called it "myFiles".
Since 29-12-2016 I am no longer a moderator for this forum
-
- Posts: 14
- Joined: 07 Jul 2014 22:41
Re: Pls share example code for switching on a schedule?
good to know pz1. I will change my project accordingly.
BR,
BR,
Re: Pls share example code for switching on a schedule?
...could you pls explain, how to get the file "crone.js"?
Under https://github.com/StefanLiebenberg/cron.js/ I find a Directory named "cron.js". Inside there a 2 files with the Name "cron.js" - cron.js-master/lib/classes/cron.js and cron.js-master/src/cron.js
Which one is the right?
Uwe
Under https://github.com/StefanLiebenberg/cron.js/ I find a Directory named "cron.js". Inside there a 2 files with the Name "cron.js" - cron.js-master/lib/classes/cron.js and cron.js-master/src/cron.js
Which one is the right?
Uwe
Z-Way v2.0.1-rc18 on Raspberry Pi
-
- Posts: 14
- Joined: 07 Jul 2014 22:41
Re: Pls share example code for switching on a schedule?
Hey LAN,
I´m not 100% sure, because im traveling, and im not right in front of my system. Nevertheless, i think i used the file in "cron.js / build /" named "cron.cc.js".
give a try with that file.
Dont forget that, any time you change anything in your script, you need to restart the zway system in order to the new code be loaded. Pay also attention in the log files to understand if something goes wrong.
I´m not 100% sure, because im traveling, and im not right in front of my system. Nevertheless, i think i used the file in "cron.js / build /" named "cron.cc.js".
give a try with that file.
Dont forget that, any time you change anything in your script, you need to restart the zway system in order to the new code be loaded. Pay also attention in the log files to understand if something goes wrong.
Re: Pls share example code for switching on a schedule?
ok - now it works
Under "Z-Way Home Automation UI" - "Preferences" - "Automation" I created a new module "Load custom JavaScript file". "File Name" I filled with "userModules/Heizung/myZwave.js".
I created "/opt/z-way-server/automation/userModules/Heizung/myZwave.js" with
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
executeFile("userModules/Heizung/cron.cc.js");
var Crontab = new Cron(); //instatiates the Cron module
Crontab.add( new Cron.Job( "0 50 21 * * *", function () {
zway.devices[7].instances[0].commandClasses[67].Set(1,15);
}));
Crontab.start();
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
I copied "cron.cc.js" in the Directory "/opt/z-way-server/automation/userModules/Heizung/"
Restart Z-Wave and at 21:50 throttles the heating at 15 ° C
Thanks for your help!!
Uwe
Under "Z-Way Home Automation UI" - "Preferences" - "Automation" I created a new module "Load custom JavaScript file". "File Name" I filled with "userModules/Heizung/myZwave.js".
I created "/opt/z-way-server/automation/userModules/Heizung/myZwave.js" with
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
executeFile("userModules/Heizung/cron.cc.js");
var Crontab = new Cron(); //instatiates the Cron module
Crontab.add( new Cron.Job( "0 50 21 * * *", function () {
zway.devices[7].instances[0].commandClasses[67].Set(1,15);
}));
Crontab.start();
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
I copied "cron.cc.js" in the Directory "/opt/z-way-server/automation/userModules/Heizung/"
Restart Z-Wave and at 21:50 throttles the heating at 15 ° C
Thanks for your help!!
Uwe
Z-Way v2.0.1-rc18 on Raspberry Pi