Myq Chamberlain API v5.1 Updated Flow

With the v4 API's being shutdown, used the original flow by @nothingmn (with @jtmoderate876's mod to add in the Credential's node. Then used this work to adapt to the v5.1 API. Also trimmed out a lot of the excess pieces I didn't need for my basic status/control.

App ID is stored in the credentials node (and commented right above it).

[{"id":"4d9a8a5b.bb3e34","type":"credentials","z":"28d48d0d.e70672","name":"","props":[{"value":"payload.username","type":"msg"},{"value":"payload.password","type":"msg"},{"value":"payload.appID","type":"msg"}],"x":490,"y":1440,"wires":[["ddbfa6f1.a9b5f8"]]},{"id":"db3d1c91.55d1e","type":"inject","z":"28d48d0d.e70672","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"60","crontab":"","once":true,"onceDelay":"60","topic":"garage/status","payload":"","payloadType":"date","x":250,"y":1520,"wires":[["d4831b2b.3eaee8"]]},{"id":"9a37be19.868fa","type":"http request","z":"28d48d0d.e70672","name":"Login","method":"POST","ret":"obj","paytoqs":"ignore","url":"https://api.myqdevice.com/api/v5/Login","tls":"4b9f48cc.9fc1c8","persist":false,"proxy":"","authType":"","x":770,"y":1440,"wires":[["23944cdb.1e08b4"]]},{"id":"d4831b2b.3eaee8","type":"function","z":"28d48d0d.e70672","name":"Set Credentials","func":"var myq = flow.get(\"myq\");\n\nif(myq && myq.headers.SecurityToken && myq.accountId) {\n    msg.myq = myq; \n    msg.headers = myq.headers\n    return msg;\n} else {\n    return null;\n}\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":500,"y":1540,"wires":[["6d191dc7.62fc14"]]},{"id":"23944cdb.1e08b4","type":"function","z":"28d48d0d.e70672","name":"Set SecurityToken","func":"var myq = msg.myq;\n\nif(msg.statusCode == 200 && msg.payload.SecurityToken) {\n//    myq.securityToken = msg.payload.SecurityToken;\n    myq.headers.SecurityToken = msg.payload.SecurityToken;\n\n//    flow.set(\"myq\", myq);\n    msg.myq = myq;\n    msg.headers = myq.headers;\n\n    return msg;\n} else {\n    return null;\n}","outputs":1,"noerr":0,"initialize":"","finalize":"","x":930,"y":1440,"wires":[["9b38881d.971f78"]]},{"id":"847daee7.50877","type":"http request","z":"28d48d0d.e70672","name":"Get Devices","method":"GET","ret":"obj","paytoqs":"ignore","url":"https://api.myqdevice.com//api/v5.1/Accounts/{{{myq.accountId}}}/Devices","tls":"4b9f48cc.9fc1c8","persist":false,"proxy":"","authType":"","x":830,"y":1520,"wires":[["a522ca73.e59a78"]]},{"id":"9ebe3273.1049","type":"function","z":"28d48d0d.e70672","name":"Device State","func":"var myq = msg.myq;\n\nfor(var d in msg.payload.items) {\n    var device = msg.payload.items[d];\n    if(device && device.device_family && device.device_family == \"garagedoor\" && device.state) {\n        myq.garage = {\n            \"name\" : device.name,\n            \"state\" : device.state.door_state,\n            \"din\" : device.serial_number,\n            \"lastUpdate\" : device.state.last_update\n        }\n    }\n};\n\nflow.set(\"myq\", myq);\n\nvar msg2 = {};\nmsg2.myq = myq;\nmsg2.payload=myq.garage.state;\nmsg2.topic=\"garage/state\";\n\nreturn msg2;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":1190,"y":1520,"wires":[["c1e2da60.1c4308"]]},{"id":"10cf6215.09181e","type":"http request","z":"28d48d0d.e70672","name":"Control","method":"PUT","ret":"txt","paytoqs":"ignore","url":"https://api.myqdevice.com/api/v5.1/Accounts/{{{myq.accountId}}}/Devices/{{{myq.garage.din}}}/actions","tls":"4b9f48cc.9fc1c8","persist":false,"proxy":"","authType":"","x":820,"y":1560,"wires":[[]]},{"id":"6d191dc7.62fc14","type":"switch","z":"28d48d0d.e70672","name":"","property":"topic","propertyType":"msg","rules":[{"t":"eq","v":"garage/status","vt":"str"},{"t":"eq","v":"garage/control","vt":"str"}],"checkall":"false","repair":false,"outputs":2,"x":650,"y":1540,"wires":[["847daee7.50877"],["10cf6215.09181e"]]},{"id":"c865536b.9dbf4","type":"inject","z":"28d48d0d.e70672","name":"initialize","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"300","crontab":"","once":true,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":200,"y":1440,"wires":[["858c044f.5e0f98"]]},{"id":"ddbfa6f1.a9b5f8","type":"function","z":"28d48d0d.e70672","name":"Set Login","func":"var myq;\n\nmyq = {\n//        \"appID\" : msg.appID,\n        \"headers\" : {\n            \"ContentType\" : \"application/json; charset=utf-8\",\n//            \"Accept\" : \"application/json\",\n//            \"Culture\" : \"en\",\n            \"MyQApplicationId\" : msg.payload.appID\n        }\n    };\n\n//flow.set(\"myq\",myq);\nmsg.myq = myq;\nmsg.headers = myq.headers;\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":640,"y":1440,"wires":[["9a37be19.868fa"]]},{"id":"ba4e8b19.f12a98","type":"mqtt in","z":"28d48d0d.e70672","name":"Garage Door Control","topic":"home/garage/garageDoor/set","qos":"0","datatype":"auto","broker":"35e878ff.e53308","x":170,"y":1560,"wires":[["96721f6e.23102"]]},{"id":"544334a2.9c00fc","type":"mqtt out","z":"28d48d0d.e70672","name":"Garage Door Status","topic":"home/garage/garageDoor","qos":"","retain":"","broker":"35e878ff.e53308","x":1440,"y":1520,"wires":[]},{"id":"c1e2da60.1c4308","type":"rbe","z":"28d48d0d.e70672","name":"","func":"rbe","gap":"","start":"","inout":"out","property":"payload","x":1295,"y":1520,"wires":[["544334a2.9c00fc"]],"l":false},{"id":"9b38881d.971f78","type":"http request","z":"28d48d0d.e70672","name":"Get AccountID","method":"GET","ret":"obj","paytoqs":"ignore","url":"https://api.myqdevice.com/api/v5/My","tls":"4b9f48cc.9fc1c8","persist":false,"proxy":"","authType":"","x":1120,"y":1440,"wires":[["7df52bb.027c0d4"]]},{"id":"7df52bb.027c0d4","type":"function","z":"28d48d0d.e70672","name":"Set AccountID","func":"var myq = msg.myq;\n\nif(msg.statusCode == 200 && msg.payload.UserId) {\n    myq.accountId = msg.payload.UserId\n\n    flow.set(\"myq\", myq);\n    msg.myq = myq;\n    msg.headers = msg.myq.headers;\n    msg.payload={};\n\n    return msg;\n} else {\n    return null;\n}","outputs":1,"noerr":0,"initialize":"","finalize":"","x":1300,"y":1440,"wires":[[]]},{"id":"a522ca73.e59a78","type":"switch","z":"28d48d0d.e70672","name":"Token Expired","property":"statusCode","propertyType":"msg","rules":[{"t":"eq","v":"401","vt":"num"},{"t":"eq","v":"200","vt":"num"}],"checkall":"true","repair":false,"outputs":2,"x":1000,"y":1520,"wires":[["4d9a8a5b.bb3e34"],["9ebe3273.1049"]]},{"id":"858c044f.5e0f98","type":"change","z":"28d48d0d.e70672","name":"Delete","rules":[{"t":"delete","p":"payload","pt":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":330,"y":1440,"wires":[["4d9a8a5b.bb3e34"]]},{"id":"96721f6e.23102","type":"change","z":"28d48d0d.e70672","name":"Action","rules":[{"t":"set","p":"topic","pt":"msg","to":"garage/control","tot":"str"},{"t":"set","p":"action","pt":"msg","to":"payload","tot":"msg"},{"t":"delete","p":"payload","pt":"msg"},{"t":"set","p":"payload.action_type","pt":"msg","to":"action","tot":"msg"},{"t":"delete","p":"action","pt":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":330,"y":1560,"wires":[["d4831b2b.3eaee8"]]},{"id":"db37e391.b8aaf","type":"comment","z":"28d48d0d.e70672","name":"AppID","info":"JVM/G9Nwih5BwKgNCjLxiFUQxQijAebyyg8QUHr7JOrP+tuPb8iHfRHKwTmDzHOu","x":500,"y":1400,"wires":[]},{"id":"664c4c56.ace024","type":"comment","z":"28d48d0d.e70672","name":"Sources","info":"https://github.com/jbnunn/Alexa-MyQGarage/blob/master/myq.py\n\nv5.1\nhttps://github.com/dcmeglio/hubitat-myq/blob/master/smartapps/brbeaird/myq-lite.src/myq-lite.groovy","x":140,"y":1620,"wires":[]},{"id":"4b9f48cc.9fc1c8","type":"tls-config","name":"TLS Config Generic","cert":"","key":"","ca":"","certname":"","keyname":"","caname":"","servername":"","verifyservercert":true},{"id":"35e878ff.e53308","type":"mqtt-broker","name":"Home","broker":"localhost","port":"1883","clientid":"nodered","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closePayload":"","willTopic":"","willQos":"0","willPayload":""}]
2 Likes

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.