Subversion Repositories HomeAutomation

Rev

Rev 1786 | Blame | Compare with Previous | Last modification | View Log | SVN | RSS feed

  1.  
  2.  
  3. function skohylla(aliasnameSensor, aliasnameDimmer, triggerstate, defaultValue)
  4. {
  5.     /* We must always call the parent constructor, initialization
  6.        of variables could be done here, but initialize is a better place */
  7.     var self = this;
  8.     this.mySensor = aliasnameSensor;
  9.     this.myDimmer = aliasnameDimmer;
  10.     this.triggstate = triggerstate;
  11.     this.defaultValue = defaultValue;
  12.     Module_RegisterToOnMessage(aliasnameSensor, function(alias_name, command, variables) { self.sensorOnMessage(alias_name, command, variables) });
  13.     Module_RegisterToOnChange( aliasnameSensor, function(alias_name, available,test) { self.sensorOnline(alias_name, available,test) });
  14.     Module_RegisterToOnChange( aliasnameDimmer, function(alias_name, available) { self.dimmerOnline(alias_name, available) });
  15.    
  16.     /* Start interval timer for sending timestamp to network. Arguments are the callback function and time in milliseconds
  17.     used to make sure an eth-node gets its init packet (600s) */
  18.     this.myTimer = Timer_SetTimer(function(timer) {self.timerUpdate(timer)}, 5000, true);
  19.     Log("\033[33mskohylla created.\033[0m\n");
  20.    
  21. }
  22.  
  23. /* Declaration of instance variables, for static variables remove prototype */
  24. skohylla.prototype.myDimmer = null;
  25. skohylla.prototype.triggstate = null;
  26. skohylla.prototype.mySensor = null;
  27. skohylla.prototype.outputStatus = "Low";
  28. skohylla.prototype.myInterval = null;
  29. skohylla.prototype.oldPwmValue = 0;
  30. skohylla.prototype.turnOffCnt = 0;
  31. skohylla.prototype.defaultValue = 255;
  32. const SkoMovementTimeout = 100;
  33.  
  34. skohylla.prototype.sensorOnline = function(alias_name, available)
  35. {
  36.  
  37. }
  38.  
  39. skohylla.prototype.dimmerOnline = function(alias_name, available)
  40. {
  41.  
  42. }
  43.  
  44. skohylla.prototype.sensorOnMessage = function(alias_name, command, variables)
  45. {
  46. //Log("\033[33mMessage.\033[0m\n");
  47.     switch (command)
  48.     {
  49.         case "PinStatus":
  50.         {
  51.            
  52.             if (variables["Status"] == this.triggstate) {
  53.               //Log("\033[33mPin low.\033[0m\n");
  54.                 var last_value_string = Storage_GetParameter("LastValues", this.myDimmer);
  55.                 var last_value = eval("(" + last_value_string + ")");
  56.                 if (last_value["Level"]["value"] == 0) {
  57.                       //log(this.myName + ":" + this.myId + "> Light on.\n");
  58.                     if (this.oldPwmValue == 0) {
  59.                         this.oldPwmValue = this.defaultValue;
  60.                     }
  61.                     Dimmer_AbsoluteFade(this.myDimmer, 129, this.oldPwmValue);
  62.                 }
  63.          
  64.             } else {
  65.               //Log("\033[33mPin high.\033[0m\n");
  66.             }
  67.             if (this.turnOffCnt <  SkoMovementTimeout) {
  68.                 this.turnOffCnt = SkoMovementTimeout;
  69.             }
  70.             break;
  71.         }
  72.     }
  73.  
  74. }
  75.  
  76. skohylla.prototype.timerUpdate = function(timer)
  77. {
  78.   //Log("\033[33mTimer.\033[0m\n");
  79.     if (this.turnOffCnt > 0) {
  80.         this.turnOffCnt -= 5;
  81.         if (this.turnOffCnt < 0) {
  82.             this.turnOffCnt = 0;
  83.         }
  84.         if (this.turnOffCnt == 0) {
  85.             //Turn off light
  86.             //log(this.myName + ":" + this.myId + "> Light off.\n");
  87.             var last_value_string = Storage_GetParameter("LastValues", this.myDimmer);
  88.             var last_value = eval("(" + last_value_string + ")");
  89.             this.oldPwmValue = last_value["Level"]["value"];
  90.             //this.myPWM.setPWMValue(0,2);
  91.             Dimmer_AbsoluteFade(this.myDimmer, 132, 0);
  92.             //getDimmerService('Skohylla').absFade(2,129, 0);
  93.         }
  94.     }
  95. }
  96.  
  97.  
  98.