Skip to content

Instantly share code, notes, and snippets.

@strelniece
Last active August 29, 2015 14:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save strelniece/ff0091dffe5b121e0663 to your computer and use it in GitHub Desktop.
Save strelniece/ff0091dffe5b121e0663 to your computer and use it in GitHub Desktop.
Limitless Led, sunrise-node
[
{
"id": "a1e6a9c6.5e1958",
"type": "mqtt-broker",
"broker": "localhost",
"port": "1883",
"clientid": ""
},
{
"id": "ba386057.845d3",
"type": "mqtt-broker",
"broker": "localhost",
"port": "1883",
"clientid": ""
},
{
"id": "9920bd25.66df4",
"type": "mqtt in",
"name": "",
"topic": "lights/scenes/sunrise",
"broker": "ba386057.845d3",
"x": 231,
"y": 40,
"z": "bd70c1cd.428f4",
"wires": [
[
"6806363c.97f9c8"
]
]
},
{
"id": "6806363c.97f9c8",
"type": "function",
"name": "Sunrise",
"func": "var lightsMsg = null;\ncontext.count = context.count || 0; \n\nswitch (msg.payload) {\n\tcase \"start\":\n\t\t//initialize loop, switch on the lights at minimum brightness and start_hue\n\t\tcontext.stopped = 0;\n\t\tmsg.payload = 1;\n\t\tmsg.count = 176\n\t\tlightMsg = [{topic:\"lights/2/power\", payload:\"on\"},{topic:\"lights/2/brightness\", payload:1}, {topic:\"lights/2/hue\", payload:176}];\n\t\tbreak;\n\tcase \"stop\":\n\t\t//switch off the light and stops the music\n\t\tcontext.stopped = 1;\n\t\tmsg = null;\n\t\tlightMsg = {topic:\"lights/2/power\", payload:\"off\"};\n\t\tbreak;\n\tcase 101:\n\t\t//end of sunrise, turn on all lamps in bedrom to white\n\t\tlightMsg = [{topic:\"lights/2/whitemode\", payload:\"yes\"},{topic:\"lights/1/power\", payload:\"on\"},{topic:\"lights/1/whitemode\", payload:\"yes\"}, {topic:\"lights/1/brightness\", payload:100}];\n\t\tmsg.payload++;\n\t\tbreak;\n\tcase 102:\t\n\t\t//natural end of the loop\n\t\tmsg = null;\n\t\tbreak;\n\tdefault:\n\t\tif (context.stopped == 0) {\n\t\t\t//set the right brightness on the payload value and increments it\n\t\t\tlightMsg = [{topic:\"lights/2/brightness\", payload:msg.payload}, {topic:\"lights/2/hue\", payload:msg.count}];\n\t\t\tmsg.payload ++;\n\t\t\tif (msg.payload%2 == 1){\n\t\t\t\tmsg.count --;\n\t\t\t}\n\t\t}\n\t\telse\n\t\t{\n\t\t\tmsg = null;\n\t\t}\n\t\tbreak;\n}\nreturn [msg, lightMsg];",
"outputs": "2",
"x": 415,
"y": 39,
"z": "bd70c1cd.428f4",
"wires": [
[
"78e842b3.8717bc"
],
[
"804e2a03.7fb1d8"
]
]
},
{
"id": "78e842b3.8717bc",
"type": "delay",
"name": "",
"pauseType": "delay",
"timeout": "18",
"timeoutUnits": "seconds",
"rate": "1",
"rateUnits": "second",
"randomFirst": "1",
"randomLast": "5",
"randomUnits": "seconds",
"drop": false,
"x": 416,
"y": 96,
"z": "bd70c1cd.428f4",
"wires": [
[
"6806363c.97f9c8"
]
]
},
{
"id": "804e2a03.7fb1d8",
"type": "mqtt out",
"name": "Lights MQTT",
"topic": "",
"qos": "",
"retain": "",
"broker": "a1e6a9c6.5e1958",
"x": 615,
"y": 43,
"z": "bd70c1cd.428f4",
"wires": []
}
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment