Newbie trying to get automation to work

Discussions about Z-Way software and Z-Wave technology in general
Post Reply
thorbj
Posts: 9
Joined: 19 Nov 2014 14:48

Newbie trying to get automation to work

Post by thorbj »

I'm just starting to figure out z-wave and HA, and have set ut a RaZberry and a Fibaro wall plug to start testing.
Now I wonder how can I get the plug to turn on at given times of the day, and then of at other times. I want this plug to turn on a lamp at 6 am and again at 4pm, and turn it of at 9am and 1am. I tried to make a cron job using this thread: viewtopic.php?f=3419&t=20601, but it the commands never fires.
Here's the script I use:

Code: Select all

executeFile("/userModules/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 12h01m00sec
   Crontab.add( new Cron.Job( "0 01 12 * * *", function () {

                //get status of the switch. Change N and I, according to your actual config
      var status = zway.devices[5].instances[0].SwitchBinary.data.level.value;
      
      //if the swich is off, turn it on
      if(status==false){
         zway.devices[5].instances[0].SwitchBinary.Set(255);
      }
      
      
   }));   
   
           //runs every day, at 12h00m00sec
   Crontab.add( new Cron.Job( "0 00 12 * * *", function () {

                //get status of the switch. Change N and I, according to your actual config
      var status = zway.devices[5].instances[0].SwitchBinary.data.level.value;
      
      //if the swich is on, turn it off
      if(status==true){
         zway.devices[5].instances[0].SwitchBinary.Set(0);
      }
      
      
   }));   
   

   Crontab.start();
And I use a cron.js file from https://github.com/StefanLiebenberg/cron.js/

Thanks!
Vantskruv
Posts: 13
Joined: 06 Nov 2014 18:26

Re: Newbie trying to get automation to work

Post by Vantskruv »

Which version of Z-way server do you use?

If you update your server to version 2, there is a ScheduleScene module which will do what you want.
Though version 2 is in development, but it is quite stable. If you want to update to the latest branch:
1. Go to http://razberry.z-wave.me/z-way-server/
2. Check which version of z-way-server-RaspberryPiXTools files is the latest (at this time it is v2.0.0-rc20)
3. Go to your server at http://YOUR_SERVER_IP:8084
4. Choose the advanced tab and then choose the firmware tab.
5. Check the "update to" radio button and type in the version you want to update to (i.e. in this example v2.0.0-rc20).
6. When the server is updated, go to the Z-Way Autmation UI in at http://YOUR_SERVER_IP:8083
7. Go to preferences->modules->perihepals.
8. Install the Z-Wave binding module and set its setting value to:
/dev/ttyAMA0

Now you can install the ScheduledScene module. Note that you have to create a LightScene where you add your devices you want to control. This LightScene is then listed in the ScheduleScene module. (As for now you may have to update your browser to make the created Light-scenes visible).
ScheduleSun - a sunset/sunrise module
viewtopic.php?f=3424&t=20801
martinisonline
Posts: 14
Joined: 07 Jul 2014 22:41

Re: Newbie trying to get automation to work

Post by martinisonline »

Hi thorbj,

for my own solution i did, complementing the link for the other post:

create a folder in:
/opt/z-way-server/automation
name it myFiles.

Inside that folder put the files:
cron.js (cron scritp made by Stefan Liebenberg)
myZwave.js (your own script, like the one you posted)

using this folder struture, use the following script(myZwave.js) only to test if the cron is working:

Code: Select all

executeFile("/myFiles/cron.js");

var Crontab = new Cron(); //instatiates the Cron module

//simple example to test if cron tab is running every minute

        //runs every minute
   Crontab.add( new Cron.Job( "0 * * * * *", function () {

   console.log("CRONTAB IS WORKING");
      
      
   }));   
   
 Crontab.start();
  
[VERY IMPORTANT, dont forget it]
next step should be: go to "Z-Way Home Automation UI" from [<<<raspberry IP>>>:8083]:
go to "preferences"->"Automation" and create a new rule with template "Load custom Javascript File" ->"Add Item"
in the field "File name" write "myFiles/myZwave.js" and save it.

[VERY IMPORTANT, dont forget it]
restart zwave system(from a console):

Code: Select all

sudo /etc/init.d/z-way-server restart

use the command "tail -f /var/log/z-way-server.log" to watch the output in real time

if you see "CRONTAB IS WORKING" in the output every minute, change the script to your needs and everything should working.

Don't forget that any change you do in the script you need to restart the zway system in order to the changes take effect.

post any doubts you may have.
Post Reply