Last active
September 16, 2017 14:31
-
-
Save HerrLevin/6ae4f6a47210aa76534a8ab2addf13fa to your computer and use it in GitHub Desktop.
A small sonoff-traffic light controlling javascript. Don't ask. Please. | Sonoff 4CH running Tasmota (https://github.com/arendst/Sonoff-Tasmota) | Demo: https://twitter.com/HerrLevin_/status/909058890364592128
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<title>Parteyampel3000</title> | |
<meta name="author" content="HerrLevin_"> | |
</head> | |
<script> | |
//Made for Sonoff 4CH running tasmota | |
//red on CH1 | |
//yellow on CH2 | |
//green on CH3 | |
//no use for CH4 | |
//set x.x.x.x to your Parteyampel-IP | |
var rot = "http://x.x.x.x/cm?cmnd=Power1"; | |
var gelb = "http://x.x.x.x/cm?cmnd=Power2"; | |
var gruen = "http://x.x.x.x/cm?cmnd=Power3"; | |
function ON(w){ | |
var http = new XMLHttpRequest(); | |
http.open("GET", w + "%20ON", false); | |
http.send(); | |
} | |
function OFF(w){ | |
var http = new XMLHttpRequest(); | |
http.open("GET", w + "%20OFF", false); | |
http.send(); | |
} | |
function wait(ms){ | |
var start = new Date().getTime(); | |
var end = start; | |
while(end < start + ms) { | |
end = new Date().getTime(); | |
} | |
} | |
function ampel(){ | |
OFF(rot); | |
OFF(gelb); | |
OFF(gruen); | |
ON(rot); | |
wait(1000); | |
ON(gelb); | |
wait(1500); | |
OFF(rot); | |
OFF(gelb) | |
ON(gruen); | |
wait(5000); | |
OFF(gruen); | |
ON(gelb); | |
wait(1500); | |
OFF(gelb); | |
ON(rot); | |
wait(2000); | |
Off(rot); | |
ON(gelb); | |
wait(500); | |
OFF(gelb); | |
ON(gruen); | |
wait(500); | |
ON(gelb); | |
wait(500); | |
ON(rot); | |
} | |
function party(){ | |
wait(500); | |
OFF(rot); | |
OFF(gelb); | |
OFF(gruen); | |
wait(500); | |
ON(rot); | |
ON(gelb); | |
ON(gruen); | |
wait(500); | |
OFF(rot); | |
OFF(gelb); | |
OFF(gruen); | |
wait(500); | |
ON(rot); | |
ON(gelb); | |
ON(gruen); | |
wait(500); | |
OFF(rot); | |
OFF(gelb); | |
OFF(gruen); | |
wait(500); | |
ON(rot); | |
ON(gelb); | |
ON(gruen); | |
wait(500); | |
OFF(rot); | |
OFF(gelb); | |
OFF(gruen); | |
wait(500); | |
} | |
</script> | |
<body> | |
<h1>DO YOU WANT TO PARTEY?!</h1> | |
<button onclick="party()">PARTEY!!1</button> | |
<h5>Or do you want to ampel?</h5> | |
<button onclick="ampel()">AMPEL</button> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment