SHARE
TWEET

Untitled

a guest Feb 7th, 2016 338 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var myMsg = msg;
  2. var d = new Date();
  3. var hour = d.getHours();
  4. var cmd = msg.payload;
  5.  
  6. myMsg.topic = "home/livingrm/cmd"; // MQTT topic
  7. myMsg.payload = "b"; // default state is off
  8.  
  9. if (cmd==="on") global.set("biglight","on"); // override set to ON
  10. else if (cmd==="off") global.set("biglight","off"); // override set to Off
  11. else if (cmd==="default") global.set("biglight",""); // no override
  12.  
  13. var override = global.get("biglight");
  14.  
  15. if (override==="on") {
  16.     myMsg.payload="B"; // force ON state
  17. } else if (override==="off") {
  18.     myMsg.payload="b"; // force OFF state
  19. } else {
  20.     if ((hour>=7) && (hour<12)) myMsg.payload = "B"; //first on period
  21.     else if ((hour>=17) && (hour<22)) myMsg.payload = "B"; //second on period
  22. }
  23.  
  24. return myMsg;
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top