Last active
April 15, 2020 09:20
-
-
Save artoliukkonen/46eff5eefaaafb088346dc18ebe8288f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const tradfriLib = require("node-tradfri-client"); | |
const TradfriClient = tradfriLib.TradfriClient; | |
const AccessoryTypes = tradfriLib.AccessoryTypes; | |
const tradfri = new TradfriClient("192.168.100.101"); | |
const lightbulbs = {}; | |
const plugs = {}; | |
const devices = {}; | |
const connect = async () => { | |
try { | |
await tradfri.connect('USERNAME', 'PASSWORD'); | |
tradfri | |
.on("device updated", tradfri_deviceUpdated) | |
.observeDevices(); | |
} catch (e) { | |
console.log(e); | |
} | |
} | |
function tradfri_deviceUpdated(device) { | |
devices[device.instanceId] = device; | |
if (device.type === AccessoryTypes.lightbulb) { | |
lightbulbs[device.instanceId] = device; | |
} else if (device.type === AccessoryTypes.plug) { | |
plugs[device.instanceId] = device; | |
} | |
} | |
connect(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment