Listing all devices associated with a Telldus Live account

This function node will connect to the Telldus Live service, and from there download a list of all devices available for the user credentials being used.

A device in this context is anything that is not a sensor, typical devices are radio controlled (the Tellsticks are 433 MHz transceivers for sending commands to/reading data from devices and sensors) on/off switches, dimmers, doorbells etc.

One message will be fired for each device, including the device's id and its name.

To use the device, just hook up an injector and a debug node, configure the user credentials in the node and make sure the needed node.js lib is installed.

More info and related code available athttps://www.ptarmiganlabs.com/category/home-automation/

[{"id":"65b4fc80.9a4b04","type":"function","name":"Telldus Live: List all devices","func":"// Node-RED function to\n// a) list all Telldus devices (device = everything in Telldus Live except sensors)\n//\n// The code below relies on the following modules to be installed in the Node-RED environment, including being set up \n// in the functionGlobalContext section of the Node-RED settings.js config file (see last section of http://nodered.org/docs/writing-functions.html page)\n// \n// a) Telldus-Live module (https://github.com/TheThingSystem/node-telldus-live)\n//\n//\n// The function will fire one output message for each device it gets information about from Telldus Live.\n// By default the device id and name is included in the messages, but this can be customised as needed.\n//\n\n// Define Telldus Live API credentials    \nvar publicKey    = '<enter your public key here>'\n  , privateKey   = '<enter your private key here>'\n  , token        = '<enter your token here>'\n  , tokenSecret  = '<enter your token secret here>'\n  , cloud\n  ;\n\n// Create and log into new TelldusAPI object\ncloud = new context.global.telldusLive.TelldusAPI({ publicKey  : publicKey\n                                  , privateKey : privateKey });\n                                  \ncloud.login(token, tokenSecret, function(err, user) {\n  if (!!err) return console.log('login error: ' + err.message);\n\n  // Get list of all devices. Use async call to avoid blocking  \n  cloud.getDevices(function(err, devices) {\n    var f, i;\n\n    if (!!err) return console.log('getDevices: ' + err.message);\n\n    f = function(offset, p, s) {\n      return function(err, device) {\n        var d, type, types;\n\n        if (!!err) return console.log(s + ' id=' + p.id + ': ' + err.message);\n\n        var devInfo = 'Device list, id=' + device.id + ', name=' + device.name;\n        node.log (devInfo);\n        \n        // Fire one output message for each pass of this function.\n        // An effect of this function being a callback (which is async by its nature) is that the devices\n        // will be returned in random order (i.e. not sorted from lowest to highest)\n        node.send({payload:devInfo});\n         \n        return;\n      };\n    };\n\n    // Loop over all devices, asynchcronously get the data for each \n    for (i = 0; i < devices.length; i++) {\n      if (devices[i].type === 'device') cloud.getDeviceInfo(devices[i], f(i, devices[i], 'getDeviceInfo'));\n    }\n  });\n}).on('error', function(err) {\n  console.log('background error: ' + err.message);\n});\n\n\nreturn;\n","outputs":1,"noerr":0,"x":464,"y":900,"z":"47520c37.b8adf4","wires":[[]]}]

Flow Info

Created 9 years, 4 months ago
Rating: not yet rated

Owner

Actions

Rate:

Node Types

Core
  • function (x1)

Tags

  • telldus
  • tellduslive
  • homeautomation
Copy this flow JSON to your clipboard and then import into Node-RED using the Import From > Clipboard (Ctrl-I) menu option