Skip to content

Instantly share code, notes, and snippets.

@jtmoderate876
Forked from nothingmn/README.md
Last active October 21, 2020 18:15
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jtmoderate876/b70aab2401f57c2e68ff5b6eab5ba0b6 to your computer and use it in GitHub Desktop.
Save jtmoderate876/b70aab2401f57c2e68ff5b6eab5ba0b6 to your computer and use it in GitHub Desktop.
MyQ Chamberlain Garage Door Status and Control
[
{
"id": "11aaf4c8.4bf33b",
"type": "tab",
"label": "MyQ",
"disabled": false,
"info": ""
},
{
"id": "3153a0e9.678eb",
"type": "inject",
"z": "11aaf4c8.4bf33b",
"name": "",
"topic": "garage/status",
"payload": "",
"payloadType": "date",
"repeat": "60",
"crontab": "",
"once": true,
"onceDelay": "",
"x": 150,
"y": 100,
"wires": [
[
"e9a8bd7c.6f65"
]
]
},
{
"id": "e4163af7.d63848",
"type": "http request",
"z": "11aaf4c8.4bf33b",
"name": "",
"method": "POST",
"ret": "obj",
"url": "https://myqexternal.myqdevice.com/api/v4/User/Validate",
"tls": "74d52d37.cac784",
"x": 790,
"y": 100,
"wires": [
[
"795731b2.9f7f4",
"e718af7c.58e97"
]
]
},
{
"id": "83a330e4.d7b2c",
"type": "debug",
"z": "11aaf4c8.4bf33b",
"name": "",
"active": true,
"console": "false",
"complete": "true",
"x": 950,
"y": 60,
"wires": []
},
{
"id": "289ed2ed.db4a8e",
"type": "function",
"z": "11aaf4c8.4bf33b",
"name": "",
"func": "/* old used lowercase\nmsg.payload = {\n \"username\" : flow.get(\"myq.payload.username\"),\n \"password\" : flow.get(\"myq.payload.password\")\n}\n*/\nmsg.payload = {\n \"Username\" : flow.get(\"myq.payload.username\"),\n \"Password\" : flow.get(\"myq.payload.password\")\n}\n\nmsg.headers = {\n ContentType : \"application/json\",\n Accept : \"application/json\",\n MyQApplicationId : \"Vj8pQggXLhLy0WHahglCD4N1nAkkXQtGYpq2HrHD7H1nvmbT55KqtN6RSF4ILB/i\",\n Culture : \"en\"\n}\n\nreturn msg;",
"outputs": 1,
"noerr": 0,
"x": 650,
"y": 100,
"wires": [
[
"e4163af7.d63848",
"53f997e1.35bcd8"
]
]
},
{
"id": "e9a8bd7c.6f65",
"type": "function",
"z": "11aaf4c8.4bf33b",
"name": "",
"func": "\nif(msg.payload && msg.payload.desired_state) {\n msg.desired_state = msg.payload.desired_state;\n}\n\n\nmsg.payload = {};\n\nvar myq = flow.get(\"myq\");\n\nif(myq && myq.SecurityToken) {\n msg.payload.myq = myq; \n}\n\n\nreturn msg;\n",
"outputs": "1",
"noerr": 0,
"x": 350,
"y": 120,
"wires": [
[
"d2ff0087.35e4d",
"3514d096.e05a9",
"f6bd898d.11bb78"
]
]
},
{
"id": "ab1f61d1.f1759",
"type": "debug",
"z": "11aaf4c8.4bf33b",
"name": "",
"active": false,
"console": "false",
"complete": "true",
"x": 610,
"y": 60,
"wires": []
},
{
"id": "69bb7f4e.1b68e",
"type": "debug",
"z": "11aaf4c8.4bf33b",
"name": "",
"active": true,
"console": "false",
"complete": "true",
"x": 630,
"y": 140,
"wires": []
},
{
"id": "795731b2.9f7f4",
"type": "function",
"z": "11aaf4c8.4bf33b",
"name": "",
"func": "\nif(msg.statusCode == 200 && msg.payload.SecurityToken) {\n var myq = {\n SecurityToken : msg.payload.SecurityToken\n };\n \n flow.set(\"myq\", myq);\n msg.payload.myq = myq;\n return msg;\n} else {\n return null;\n}\n\n\n",
"outputs": 1,
"noerr": 0,
"x": 950,
"y": 100,
"wires": [
[
"83a330e4.d7b2c",
"f6bd898d.11bb78"
]
]
},
{
"id": "d2ff0087.35e4d",
"type": "switch",
"z": "11aaf4c8.4bf33b",
"name": "",
"property": "payload.myq",
"propertyType": "msg",
"rules": [
{
"t": "nnull"
},
{
"t": "else"
}
],
"checkall": "false",
"outputs": 2,
"x": 490,
"y": 120,
"wires": [
[
"ab1f61d1.f1759"
],
[
"289ed2ed.db4a8e",
"69bb7f4e.1b68e"
]
]
},
{
"id": "3514d096.e05a9",
"type": "debug",
"z": "11aaf4c8.4bf33b",
"name": "",
"active": false,
"console": "false",
"complete": "true",
"x": 470,
"y": 60,
"wires": []
},
{
"id": "f6bd898d.11bb78",
"type": "function",
"z": "11aaf4c8.4bf33b",
"name": "",
"func": "var myq;\n\nif(msg.payload.myq) {\n myq = msg.payload.myq;\n} else {\n myq = flow.get(\"myq\");\n}\n\nif(!myq) return msg;\n\nmsg.headers = {\n ContentType : \"application/json\",\n Accept : \"application/json\",\n MyQApplicationId : \"Vj8pQggXLhLy0WHahglCD4N1nAkkXQtGYpq2HrHD7H1nvmbT55KqtN6RSF4ILB/i\",\n Culture : \"en\",\n SecurityToken : myq.SecurityToken\n}\n\nreturn msg;\n",
"outputs": 1,
"noerr": 0,
"x": 350,
"y": 180,
"wires": [
[
"18d389f6.096626"
]
]
},
{
"id": "a33d683b.523ae8",
"type": "http request",
"z": "11aaf4c8.4bf33b",
"name": "",
"method": "GET",
"ret": "obj",
"url": "https://myqexternal.myqdevice.com/api/v4/UserDeviceDetails/Get",
"tls": "74d52d37.cac784",
"x": 730,
"y": 220,
"wires": [
[
"7cb3ce78.23626",
"d9892629.2348a8"
]
]
},
{
"id": "5ae7f1a6.6f716",
"type": "function",
"z": "11aaf4c8.4bf33b",
"name": "",
"func": "var myq = flow.get(\"myq\");\n\nmyq.devices = msg.payload.Devices;\nmyq.timestamp = new Date();\n\nflow.set(\"myq\", myq);\n\nmsg.payload.myq = myq;\n\nvar state = \"unknown\";\nfor(var d in myq.devices) {\n var device = myq.devices[d];\n if(device && device.MyQDeviceTypeName && device.MyQDeviceTypeName == \"GarageDoorOpener\" && device.Attributes) {\n myq.garage = device;\n for(var a in device.Attributes) {\n var attribute = device.Attributes[a];\n if(attribute && attribute.AttributeDisplayName == \"doorstate\") {\n var state = attribute.Value + \"\";\n myq.garage.state = \"unknown\";\n if(state == \"1\") myq.garage.state = \"open\";\n if(state == \"2\") myq.garage.state = \"closed\";\n if(state == \"3\") myq.garage.state = \"stopped\";\n if(state == \"4\") myq.garage.state = \"opening\";\n if(state == \"5\") myq.garage.state = \"closing\";\n if(state == \"8\") myq.garage.state = \"moving\";\n if(state == \"9\") myq.garage.state = \"open\";\n }\n }\n }\n}\nif(msg.headers) delete msg.headers;\nif(msg.statusCode) delete msg.statusCode;\nif(msg.responseUrl) delete msg.responseUrl;\nif(msg.responseCookies) delete msg.responseCookies;\n\nmsg.payload = msg.payload.myq;\n\nvar last = flow.get(\"myq_garage_last_known\")\nmsg.payload.garage.hasChanged = false;\nif(last && last != msg.payload.garage.state) {\n msg.payload.garage.hasChanged = true;\n}\nflow.set(\"myq_garage_last_known\", msg.payload.garage.state);\n\nvar msg2 = {};\nmsg2.payload=myq.garage.state;\nmsg2.topic=\"garage/state\";\nmsg2.timestamp=myq.timestamp;\n\nreturn [msg,msg2];\n",
"outputs": 2,
"noerr": 0,
"x": 770,
"y": 360,
"wires": [
[
"3a9461a7.cd4a4e",
"bf6423aa.2e9ed"
],
[
"6cfbef80.77ca7"
]
]
},
{
"id": "7cb3ce78.23626",
"type": "debug",
"z": "11aaf4c8.4bf33b",
"name": "",
"active": false,
"console": "false",
"complete": "true",
"x": 950,
"y": 200,
"wires": []
},
{
"id": "fce1223e.d0e64",
"type": "switch",
"z": "11aaf4c8.4bf33b",
"name": "",
"property": "payload.error",
"propertyType": "msg",
"rules": [
{
"t": "nnull"
},
{
"t": "else"
}
],
"checkall": "false",
"outputs": 2,
"x": 650,
"y": 340,
"wires": [
[
"c9319d60.746e"
],
[
"5ae7f1a6.6f716"
]
]
},
{
"id": "c9319d60.746e",
"type": "function",
"z": "11aaf4c8.4bf33b",
"name": "",
"func": "\nreturn { _msgid : msg._msgid }\n",
"outputs": 1,
"noerr": 0,
"x": 950,
"y": 160,
"wires": [
[
"289ed2ed.db4a8e"
]
]
},
{
"id": "d9892629.2348a8",
"type": "function",
"z": "11aaf4c8.4bf33b",
"name": "",
"func": "if(msg.payload.ErrorMessage && msg.payload.ErrorMessage !== \"\") {\n msg.payload.error = msg.payload.ErrorMessage;\n}\n\nreturn msg;",
"outputs": 1,
"noerr": 0,
"x": 710,
"y": 280,
"wires": [
[
"fce1223e.d0e64"
]
]
},
{
"id": "3a9461a7.cd4a4e",
"type": "debug",
"z": "11aaf4c8.4bf33b",
"name": "",
"active": false,
"console": "false",
"complete": "true",
"x": 950,
"y": 240,
"wires": []
},
{
"id": "5fd32ffd.682c7",
"type": "comment",
"z": "11aaf4c8.4bf33b",
"name": "",
"info": "https://github.com/jbnunn/Alexa-MyQGarage/blob/master/myq.py",
"x": 70,
"y": 240,
"wires": []
},
{
"id": "98be8b03.f31b88",
"type": "inject",
"z": "11aaf4c8.4bf33b",
"name": "",
"topic": "garage/status",
"payload": "",
"payloadType": "date",
"repeat": "",
"crontab": "",
"once": false,
"x": 150,
"y": 60,
"wires": [
[
"e9a8bd7c.6f65"
]
]
},
{
"id": "bf6423aa.2e9ed",
"type": "switch",
"z": "11aaf4c8.4bf33b",
"name": "",
"property": "payload.garage.hasChanged",
"propertyType": "msg",
"rules": [
{
"t": "true"
},
{
"t": "else"
}
],
"checkall": "false",
"outputs": 2,
"x": 750,
"y": 440,
"wires": [
[
"e266609d.8b1a2",
"875f97b1.d74f58"
],
[
"c0857b3c.74c4b8"
]
]
},
{
"id": "e266609d.8b1a2",
"type": "debug",
"z": "11aaf4c8.4bf33b",
"name": "",
"active": false,
"console": "false",
"complete": "true",
"x": 950,
"y": 500,
"wires": []
},
{
"id": "c0857b3c.74c4b8",
"type": "debug",
"z": "11aaf4c8.4bf33b",
"name": "",
"active": false,
"console": "false",
"complete": "true",
"x": 950,
"y": 540,
"wires": []
},
{
"id": "875f97b1.d74f58",
"type": "function",
"z": "11aaf4c8.4bf33b",
"name": "",
"func": "\nmsg.payload = \"Garage door is \" + msg.payload.garage.state + \" at \" + msg.payload.timestamp;\n\nreturn msg;",
"outputs": 1,
"noerr": 0,
"x": 730,
"y": 500,
"wires": [
[
"b1885fd7.f94e7"
]
]
},
{
"id": "91b5387.32c7fc8",
"type": "inject",
"z": "11aaf4c8.4bf33b",
"name": "Close",
"topic": "garage/control",
"payload": "{\"desired_state\":\"close\"}",
"payloadType": "json",
"repeat": "",
"crontab": "",
"once": false,
"x": 90,
"y": 300,
"wires": [
[
"e9a8bd7c.6f65"
]
]
},
{
"id": "533b9e9f.65d36",
"type": "debug",
"z": "11aaf4c8.4bf33b",
"name": "",
"active": false,
"console": "false",
"complete": "true",
"x": 430,
"y": 300,
"wires": []
},
{
"id": "fc3c8fdf.51006",
"type": "http request",
"z": "11aaf4c8.4bf33b",
"name": "",
"method": "PUT",
"ret": "obj",
"url": "https://myqexternal.myqdevice.com/api/v4/DeviceAttribute/PutDeviceAttribute",
"tls": "74d52d37.cac784",
"x": 510,
"y": 240,
"wires": [
[
"8744e4ff.0ca488",
"28318240.e66bfe"
]
]
},
{
"id": "f8b0bc9.b5bf34",
"type": "function",
"z": "11aaf4c8.4bf33b",
"name": "",
"func": "var myq;\n\nif(msg.payload.myq) {\n myq = msg.payload.myq;\n} else {\n myq = flow.get(\"myq\");\n}\nvar open_close_state = 0; \nif (msg.desired_state && msg.desired_state == \"open\") open_close_state = 1;\n\nmsg.payload = {\n \"attributeName\": \"desireddoorstate\",\n \"myQDeviceId\": myq.garage.MyQDeviceId,\n \"AttributeValue\": open_close_state\n }\n\n\nreturn msg;",
"outputs": 1,
"noerr": 0,
"x": 350,
"y": 240,
"wires": [
[
"533b9e9f.65d36",
"fc3c8fdf.51006"
]
]
},
{
"id": "18d389f6.096626",
"type": "switch",
"z": "11aaf4c8.4bf33b",
"name": "",
"property": "topic",
"propertyType": "msg",
"rules": [
{
"t": "eq",
"v": "garage/control",
"vt": "str"
},
{
"t": "else"
}
],
"checkall": "false",
"repair": false,
"outputs": 2,
"x": 490,
"y": 180,
"wires": [
[
"f8b0bc9.b5bf34"
],
[
"a33d683b.523ae8",
"ae758271.b8f4b"
]
]
},
{
"id": "8744e4ff.0ca488",
"type": "debug",
"z": "11aaf4c8.4bf33b",
"name": "",
"active": false,
"console": "false",
"complete": "true",
"x": 590,
"y": 380,
"wires": []
},
{
"id": "8bc9083d.c97bd8",
"type": "inject",
"z": "11aaf4c8.4bf33b",
"name": "Open",
"topic": "garage/control",
"payload": "{\"desired_state\":\"open\"}",
"payloadType": "json",
"repeat": "",
"crontab": "",
"once": false,
"x": 90,
"y": 340,
"wires": [
[
"e9a8bd7c.6f65"
]
]
},
{
"id": "28318240.e66bfe",
"type": "mqtt out",
"z": "11aaf4c8.4bf33b",
"name": "",
"topic": "garage/control/state",
"qos": "",
"retain": "false",
"broker": "971eda83.260398",
"x": 540,
"y": 460,
"wires": []
},
{
"id": "2b0d0b6a.cdf6e4",
"type": "mqtt in",
"z": "11aaf4c8.4bf33b",
"name": "",
"topic": "garage/control",
"qos": "2",
"broker": "971eda83.260398",
"x": 89.5,
"y": 390,
"wires": [
[
"e9a8bd7c.6f65"
]
]
},
{
"id": "b4a7829f.2ac4b",
"type": "mqtt in",
"z": "11aaf4c8.4bf33b",
"name": "",
"topic": "garage/status",
"qos": "2",
"broker": "971eda83.260398",
"x": 90,
"y": 140,
"wires": [
[
"e9a8bd7c.6f65"
]
]
},
{
"id": "b4e4efa6.25575",
"type": "comment",
"z": "11aaf4c8.4bf33b",
"name": "jeff note",
"info": "copied from:\nhttps://flows.nodered.org/flow/83f263d6f5f23e53e2aed85b96aadb3e\nhttps://gist.github.com/nothingmn/83f263d6f5f23e53e2aed85b96aadb3e\n",
"x": 50,
"y": 20,
"wires": []
},
{
"id": "8786d87.2882628",
"type": "credentials",
"z": "11aaf4c8.4bf33b",
"name": "",
"props": [
{
"value": "username",
"type": "msg"
},
{
"value": "password",
"type": "msg"
}
],
"x": 550,
"y": 20,
"wires": [
[
"a93b4b21.260828"
]
]
},
{
"id": "f8dc33ca.0ec39",
"type": "inject",
"z": "11aaf4c8.4bf33b",
"name": "initialize",
"topic": "",
"payload": "",
"payloadType": "date",
"repeat": "",
"crontab": "",
"once": true,
"onceDelay": 0.1,
"x": 200,
"y": 20,
"wires": [
[
"8786d87.2882628"
]
]
},
{
"id": "cad855c8.c1d138",
"type": "inject",
"z": "11aaf4c8.4bf33b",
"name": "",
"topic": "",
"payload": "",
"payloadType": "date",
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"x": 140,
"y": 560,
"wires": [
[
"971e7d8d.3ce8f"
]
]
},
{
"id": "971e7d8d.3ce8f",
"type": "function",
"z": "11aaf4c8.4bf33b",
"name": "",
"func": "msg = flow.get(\"myq\");\nreturn msg;",
"outputs": 1,
"noerr": 0,
"x": 290,
"y": 560,
"wires": [
[
"b1885fd7.f94e7"
]
]
},
{
"id": "b1885fd7.f94e7",
"type": "debug",
"z": "11aaf4c8.4bf33b",
"name": "",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"x": 450,
"y": 560,
"wires": []
},
{
"id": "a93b4b21.260828",
"type": "function",
"z": "11aaf4c8.4bf33b",
"name": "set flow context variables",
"func": "flow.set(\"myq\",\n {\n \"payload\" : {\n \"username\" : msg.username,\n \"password\" : msg.password\n }\n }\n);\n\nreturn msg;\n",
"outputs": 1,
"noerr": 0,
"x": 890,
"y": 20,
"wires": [
[]
]
},
{
"id": "84c4a650.1554a8",
"type": "mqtt out",
"z": "11aaf4c8.4bf33b",
"name": "",
"topic": "",
"qos": "",
"retain": "",
"broker": "971eda83.260398",
"x": 950,
"y": 340,
"wires": []
},
{
"id": "ae758271.b8f4b",
"type": "debug",
"z": "11aaf4c8.4bf33b",
"name": "",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"x": 800,
"y": 180,
"wires": []
},
{
"id": "6cfbef80.77ca7",
"type": "rbe",
"z": "11aaf4c8.4bf33b",
"name": "",
"func": "rbe",
"gap": "",
"start": "",
"inout": "out",
"property": "payload",
"x": 930,
"y": 400,
"wires": [
[
"84c4a650.1554a8",
"3d19a9c0.0e8736"
]
]
},
{
"id": "3d19a9c0.0e8736",
"type": "debug",
"z": "11aaf4c8.4bf33b",
"name": "",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"x": 950,
"y": 460,
"wires": []
},
{
"id": "e718af7c.58e97",
"type": "debug",
"z": "11aaf4c8.4bf33b",
"name": "",
"active": true,
"console": "false",
"complete": "true",
"x": 810,
"y": 60,
"wires": []
},
{
"id": "53f997e1.35bcd8",
"type": "debug",
"z": "11aaf4c8.4bf33b",
"name": "",
"active": true,
"console": "false",
"complete": "true",
"x": 950,
"y": 280,
"wires": []
},
{
"id": "74d52d37.cac784",
"type": "tls-config",
"z": "",
"name": "TLS Config Generic",
"cert": "",
"key": "",
"ca": "",
"certname": "",
"keyname": "",
"caname": "",
"servername": "",
"verifyservercert": true
},
{
"id": "971eda83.260398",
"type": "mqtt-broker",
"z": "",
"name": "127.0.0.1:1883",
"broker": "127.0.0.1",
"port": "1883",
"clientid": "",
"usetls": false,
"compatmode": true,
"keepalive": "60",
"cleansession": true,
"birthTopic": "",
"birthQos": "0",
"birthPayload": "",
"closeTopic": "",
"closeQos": "0",
"closePayload": "",
"willTopic": "",
"willQos": "0",
"willPayload": ""
}
]
@jtmoderate876
Copy link
Author

Node-RED MyQ 2020-07-07 072822

@rgerrans
Copy link

Is yours still working? Mine quit based on the original code a few weeks ago. Just tried your modifications and still can't get back up and running

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment