Node Red access to the local API

Moderator: Telldus

Node Red access to the local API

Postby kamsvag » Tue Sep 05, 2017 6:50 pm

Ok, so I just wanted to share something I build in Node Red today. It utilize the Dashboard node so if you haven't already installed it, go ahead.

Simply copy/paste into Node Red, set your own Bearer/API key and IP of your Tellstick zNet Lite v2 and you should be good to go. I've been sloppy, so you will have to enter our key at two places (the nodes named Headers) and your IP at three (it's marked with question nodes).

Code: Select all
[{"id":"d4c5bfe.948664","type":"function","z":"9a4f16f0.65d3e8","name":"Headers","func":"msg.headers = {\n\t'Authorization': 'Bearer XXXXXXXXXXXXXXXXXXXXXXXXX',\n\t};\nreturn msg;","outputs":1,"noerr":0,"x":300,"y":100,"wires":[["7238fed9.4906f"]]},{"id":"7238fed9.4906f","type":"http request","z":"9a4f16f0.65d3e8","name":"HTTP","method":"GET","ret":"obj","url":"http://10.0.100.6/api/devices/list?supportedMethods=2","tls":"","x":430,"y":100,"wires":[["2b22c034.d627d"]]},{"id":"14048d17.1ca4d3","type":"inject","z":"9a4f16f0.65d3e8","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":true,"x":130,"y":80,"wires":[["d4c5bfe.948664"]]},{"id":"59c8f721.3994b8","type":"ui_template","z":"9a4f16f0.65d3e8","group":"8e82bb7c.9f6cc8","name":"","order":0,"width":"10","height":"25","format":"<style>\n    li { display: block; }\n</style>\n\n<div style=\"min-height: 300px;\">\n  <ul>\n      <li ng-repeat=\"item in msg.payload | orderBy : 'name'\">\n      <span>\n          <button ng-click=\"send({new: [item.id, 1]})\">\n              On\n          </button>\n          <button ng-click=\"send({new: [item.id, 0]})\">\n              Off\n          </button>\n          {{item.name}}, {{item.state}}\n      </span>\n    </li>\n  </ul>\n</div>","storeOutMessages":false,"fwdInMessages":false,"x":1100,"y":100,"wires":[["b19b902c.9a74"]]},{"id":"6a46abf2.503d84","type":"function","z":"9a4f16f0.65d3e8","name":"Headers","func":"msg.headers = {\n\t'Authorization': 'Bearer XXXXXXXXXXXXXXXXXXXXXXXXX',\n\t};\nreturn msg;","outputs":1,"noerr":0,"x":1420,"y":100,"wires":[["4298a34c.946e5c"]]},{"id":"19271eb7.f132b1","type":"http request","z":"9a4f16f0.65d3e8","name":"","method":"GET","ret":"obj","url":"http://10.0.100.6/api/device/turnOn?id={{MsgID.id}}","tls":"","x":1730,"y":80,"wires":[["658bf645.f6f7f8","c5c76cfe.406c3"]]},{"id":"4298a34c.946e5c","type":"switch","z":"9a4f16f0.65d3e8","name":"On or Off","property":"MsgDO.do","propertyType":"msg","rules":[{"t":"eq","v":"1","vt":"num"},{"t":"eq","v":"0","vt":"num"},{"t":"else"}],"checkall":"false","outputs":3,"x":1560,"y":100,"wires":[["19271eb7.f132b1"],["92d35b10.54b998"],[]]},{"id":"92d35b10.54b998","type":"http request","z":"9a4f16f0.65d3e8","name":"","method":"GET","ret":"obj","url":"http://10.0.100.6/api/device/turnOff?id={{MsgID.id}}","tls":"","x":1730,"y":120,"wires":[["658bf645.f6f7f8","c5c76cfe.406c3"]]},{"id":"658bf645.f6f7f8","type":"debug","z":"9a4f16f0.65d3e8","name":"","active":true,"console":"false","complete":"false","x":1910,"y":80,"wires":[]},{"id":"b19b902c.9a74","type":"function","z":"9a4f16f0.65d3e8","name":"Make Readable","func":"var MsgID = { id: msg.new[0] };\nvar MsgDO = { do: msg.new[1] };\nvar Msg = { MsgID, MsgDO };\nreturn [ Msg ];","outputs":1,"noerr":0,"x":1260,"y":100,"wires":[["6a46abf2.503d84"]]},{"id":"2b22c034.d627d","type":"split","z":"9a4f16f0.65d3e8","name":"","splt":"","x":550,"y":100,"wires":[["52a7e683.52bec8"]]},{"id":"52a7e683.52bec8","type":"split","z":"9a4f16f0.65d3e8","name":"","splt":"","x":670,"y":100,"wires":[["d2b8aab0.3cab28"]]},{"id":"d2b8aab0.3cab28","type":"change","z":"9a4f16f0.65d3e8","name":"","rules":[{"t":"change","p":"payload.state","pt":"msg","from":"0","fromt":"num","to":"On","tot":"str"},{"t":"change","p":"payload.state","pt":"msg","from":"2","fromt":"num","to":"Off","tot":"str"},{"t":"change","p":"payload.name","pt":"msg","from":".","fromt":"str","to":" ","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":820,"y":100,"wires":[["e7aefd97.30d3a"]]},{"id":"e7aefd97.30d3a","type":"join","z":"9a4f16f0.65d3e8","name":"","mode":"auto","build":"string","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","timeout":"","count":"","x":970,"y":100,"wires":[["59c8f721.3994b8"]]},{"id":"c5c76cfe.406c3","type":"delay","z":"9a4f16f0.65d3e8","name":"","pauseType":"delay","timeout":"3","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":1900,"y":120,"wires":[["6dc43be6.ae23d4"]]},{"id":"6dc43be6.ae23d4","type":"link out","z":"9a4f16f0.65d3e8","name":"Refresh","links":["c0c23631.f946c8"],"x":1995,"y":120,"wires":[]},{"id":"c0c23631.f946c8","type":"link in","z":"9a4f16f0.65d3e8","name":"Refresh","links":["6dc43be6.ae23d4"],"x":175,"y":120,"wires":[["d4c5bfe.948664"]]},{"id":"7245f1dc.519f9","type":"comment","z":"9a4f16f0.65d3e8","name":"Header: Set your own key for local API access","info":"","x":410,"y":60,"wires":[]},{"id":"14760409.0987fc","type":"comment","z":"9a4f16f0.65d3e8","name":"HTTP: Set IP for you Tellstick","info":"","x":500,"y":140,"wires":[]},{"id":"dcb3bcf.27d474","type":"comment","z":"9a4f16f0.65d3e8","name":"Header: Set your own key for local API access","info":"","x":1530,"y":40,"wires":[]},{"id":"98842260.4a2f9","type":"comment","z":"9a4f16f0.65d3e8","name":"HTTP: Set IP for you Tellstick","info":"","x":1780,"y":160,"wires":[]},{"id":"8e82bb7c.9f6cc8","type":"ui_group","z":"","name":"Controls","tab":"9efa07a6.42cb98","order":2,"disp":true,"width":"10"},{"id":"9efa07a6.42cb98","type":"ui_tab","z":"","name":"Controll","icon":"dashboard","order":1}]
kamsvag
 
Posts: 57
Joined: Thu Mar 12, 2015 1:46 pm

Re: Node Red access to the local API

Postby kamsvag » Thu Oct 05, 2017 6:17 am

Not interesting at all?
or did it not work for others?

Feedback would be nice.
kamsvag
 
Posts: 57
Joined: Thu Mar 12, 2015 1:46 pm


Return to Beta testing

Who is online

Users browsing this forum: No registered users and 1 guest