How to program work of a dimmer?

Discussions about Z-Way software and Z-Wave technology in general
Post Reply
Antti
Posts: 16
Joined: 14 Oct 2014 00:06

How to program work of a dimmer?

Post by Antti »

I wrote a code, but it doesn't work as it is necessary to me. Somebody can explain, why?

Code: Select all

zway.devices[6].SwitchMultilevel.data.level.bind(function() {
  var date = new Date();
  var hour = date.getHours();
  if (this.value > 0) {
    if (hour > 11 && hour < 15) {
      zway.devices[6].SwitchMultilevel.Set(30);
      setTimeout(function() {
        zway.devices[6].SwitchMultilevel.Set(10);
      }, 300000);
      setTimeout(function() {
        zway.devices[6].SwitchMultilevel.Set(0);
      }, 60000);
    }
    else {
      setTimeout(function() {
        zway.devices[6].SwitchMultilevel.Set(30);
      }, 300000);
      setTimeout(function() {
        zway.devices[6].SwitchMultilevel.Set(0);
      }, 60000);
    }
  }
});
And how after all correctly to write me a code? Thanks.
pofs
Posts: 688
Joined: 25 Mar 2011 19:03

Re: How to program work of a dimmer?

Post by pofs »

Antti wrote:but it doesn't work as it is necessary to me
You probably should explain what exactly is necessary to you first :)

I see two possible problems with your code:
1) it might be never called in case you have incorrect association groups setup
2) it might be called too many times, because calling Set() would result in changing level value and executing your handler once again. It even might get into a permanent "off" state after a minute or so.
Antti
Posts: 16
Joined: 14 Oct 2014 00:06

Re: How to program work of a dimmer?

Post by Antti »

Thank you that you answered.
Yes, you are right, I have the second problem.
The algorithm wanted to realize the following.
1. At inclusion of a dimmer the switch it is necessary to check time and if it between12 and 15 o'clock, to include a dimmer for 30%, to include in other time for 100%.
2. After inclusion of a dimmer to wait five minutes and to reduce brightness to 10% or 30% respectively.
3. After reduction of brightness to wait a minute more and if not I was the switch button (it didn't turn out to realize) is pressed, to turn off the light completely.
Unfortunately I am a beginner in js...
Post Reply