Initiating devices

I’m brand new to Homey programming. I’m trying to develop an app to control my Wiz light bulbs. The bulbs use WiFi interface. I have encountered a problem I do not fully understand. When I pair the first bulb, it works perfectly. When I add a new device (bulb) I find the bulb with the correct mac (used as id) and ip address. When I return data in pair I get the following message: “[ManagerDrivers] [wizfilament] [1] Error: invalid_type at Remote Process” and the device that worked gets its ip address overwritten. I can not find anything in the documentation that explains the problem. Can anyone help?

Code or it didn’t happen :wink:

The driver code is almost directly from the documentation:

async onPairListDevices() {
	let devices = [];
	devices = this.getDevices();
	var funnet = false;
	if (devices.length > 0) {
		for (var i = 0; i < devices.length; i++) {

	discover = new Discover();
	var obj = await discover.getIpAndMacAddress(2, devId);
	if (obj != null) {
		console.log("NY!: " + obj.macId + " - " + obj.ipAdr);
		var deviceDescriptor = {
			"name": devName,
			"data": {
				"id": obj.macId,
				"ip": obj.ipAdr,
			capabilities: ["onoff", "dim", "wiz_kelvin", "wiz_scene"]
		obj = null;
		return deviceDescriptor;
	return null;

The first device works fine, when I add another device then everthing starts to go wrong.

Do you have the full code online somewhere (for instance on Github)? The code you’re showing seems only half finished, and it’s missing some parts (like what Discover is).

Some remarks about specifically this code:

  • not sure what devId is being used for and how it’s declared
  • devName is undefined
  • onPairListDevices should return an array

The code will be on the github, but currently it’s only local. The devName is a global variable (string), the devId is the mac address on the bulb (string). The discover is a javascript (NodeJs) accessing the unoffical API for discovering and getting the bulb settings. I tried to add the device description to a array, but the problem was the same.
I have updated the github, but it’s privat. I have set you up so you can see it.

Typically, “first device works, subsequent devices fail” point towards variable-reuse, for instance by using global variables that get overwritten. The Discover class is using various such global variables (adress, devName, success, devices) and the Driver too.

You need proper encapsulation of all data that should not be “shared” across different instances of a class.

Thank you, I going to look into it. Is it a good idea to check this in as an app when it’s finished? The API is unofficial and Wiz connect seemed very uninterested when I contacted them about the API and Homey app.

There are plenty of apps that use unofficial API’s, so go ahead and publish it when it works! :+1:t2:

The problem is solved. Actually a bit strange, but when I returned the array from onPairListDevices () this way:

var deviceDescriptor = {
“name”: name,
“data”: {
“id”: macAdr,
“ip”: ipAddr,
capabilities: [“onoff”, “dim”]

got all devices for the same driver ip the address of the last device that was paired. When I removed the ip address from “data” and entered a “settings” and used the ip address there everything works as normal.