I have some plants connected to my Hue lights, and using the code below, I can molest them with Javascript.
- Cacti
- Makey-Makey
- Hue Lights
- JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 |
<!doctype html> <html> <head> <meta charset="UTF-8"> <title>☁</title> <style type="text/css"> body,td,th { font-family: Gotham, "Helvetica Neue", Helvetica, Arial, sans-serif; color: #FFFFFF; } a { color: #FFFFFF; } h1 { border:none; background:#666; padding:5px; cursor: help; } h2 { border:none; background:#333; padding:5px; cursor: help; } body { background-color: #3F8183; margin-left: 20px; margin-top: 20px; margin-right: 20px; margin-bottom: 20px; } </style> </head> <body> <table cellpadding="20"> <tr><td valign="top"> <div class="btn1"><h1>RESET</h1></div> <div class="btn2"><h2>PLANTS</h2></div> <div class="btn3"><h2>GARAGEWORX</h2></div> <hr> <p><a href="https://www.meethue.com/api/nupnp" target="hue">Click For Hue Info</a></p> <p><span class="hueIP">HUE IP</span> ☁ <span class="hueID">HUE ID</span></p> </td><td valign="top"> <div class="info">waiting</div> <hr> <div class="plant">...</div> <hr> <div class="gw">...</div> </td></tr> </table> <script language="javascript" type="text/javascript" src="jquery.js"></script> <script language="javascript" type="text/javascript" src="huejs.js"></script> <script> $(function() { // Document is ready //https://github.com/bsalinas/huejs //https://www.meethue.com/api/nupnp var hueIP = "192.168.1.3"; var hueID = "001788fffe17eaa9"; var hjs = HueJS({ ipAddress:hueIP, devicetype:"DLabHue01", username:hueID }); var brightLock = bright = 240; var colorLock = color = 48000; var colorMax = 65535; var colorAlt = 1; var lightId = Array(8,10,11); var l = lightId.length; var gwID = 9; var gwColor = 45535; var gwColorTemp = 100; var gwSineTime = 0; var gv = sv = svGW = gwTimer = null; // ---------------- function defaultHue() { // GARAGEWORX setGarageWorx(); // PLANT hjs.authenticate( function(f){ //alert("Successfully Found!"); //$('body').append(JSON.stringify(hjs.getCache())); console.log(hjs.getCache()); gv = hjs.getValue(lightId[0],['bri','alert','name']); console.log(gv); $('.info').html("<p>Ready!</p>"); // default color color = colorLock; bright = brightLock; updateHue(); }, function(f){ console.log(f); $('.info').html("<p>You Broke It</p>"); }); $('.hueIP').html(hueIP); $('.hueID').html(hueID); }; function updateHue(){ $("#plant").html('...'); var n ='' for(i=0;i<l;i++){ sv = hjs.setValue(lightId[i],{bri:bright,hue:color,sat:254,on:true}); n += " b:"+bright+" c:"+color+"</br>"; } $('.plant').html(n); $('.info').html("<p>b:"+brightLock+" c:"+colorLock+"</p>"); }; function colorRand(){ color = Math.floor(Math.random()*colorMax); updateHue() } function colorSine(){ gwSineTime = gwSineTime + 0.2; for(cnt = -1; cnt <= gwColor; cnt++) { gwColorTemp = Math.floor(gwColor - (Math.random() * 2 + Math.cos(gwSineTime + cnt * 0.05) * 5000 )); } svGW = hjs.setValue(gwID,{bri:bright,hue:gwColorTemp,sat:254,on:true}); $('.gw').html(gwColorTemp); } function setGarageWorx(){ clearInterval(gwTimer); gwTimer = setInterval(colorSine, 500); } // ---------------- $(".btn1").click(function(e){ // RESET defaultHue(); }); $(".btn2").click(function(e){ // PLANTS colorRand() }); $(".btn3").click(function(e){ // GARAGEWORX setGarageWorx(); }); $.get(); // MAKEY MAKEY $(this).keydown(function(e) { //$('.info').html(e.which); switch(e.which) { case 32: // spacebar :DEFAULT defaultHue() break; // --------- case 87: // w :W KEY break; case 65: // a :A KEY break; case 83: // s :S KEY break; case 68: // d :D KEY break; case 70: // f :F KEY break; case 71: // g :G KEY break; // --------- case 37: // left :COLOR ADJUST colorRand() break; case 39: // right : COLOR RANDOM colorRand() break; // --------- case 38: // up :BRIGHT ADJUST colorRand() break; case 40: // down :BRIGHT ADJUST colorRand() break; // --------- default: return; // exit this handler for other keys } e.preventDefault(); // prevent the default action (scroll / move caret) }); // -------- Launch on Start defaultHue(); }); </script> </body> </html> |
Leave a Reply