Page 1 of 2

RC37: userModule device selector takes wrong device types

Posted: 23 Jun 2015 17:15
by pz1
I do have a problem with setup of my userModule Arithmetic (see github for full sources). Arthmetic does ADD, SUB, MULT, DIV operations with two multilevelSensors
It does work fine on my RasberryPi 2, which I only use for testing a small number of devices and test modules.

However when installed on my production server, I can only select devices of type toggleButton. In module.json I have defined the sensor selector as:

Code: Select all

           "sensor1": {
                    "field": "enum",
                    "datasource": "namespaces",
                    "enum": "namespaces:devices_sensorMultilevel:deviceId",
                    "required": true
            },
One off the sensors I use
PVLogger.PNG
PVLogger.PNG (6.16 KiB) Viewed 6850 times
Full configuration:
configjson.json.zip
(4.96 KiB) Downloaded 183 times
So I don't understand why I only do get the toggleButton devices in the drop down list on installation of the module.

Re: RC37: userModule device selector takes wrong device type

Posted: 24 Jun 2015 00:32
by PoltoS
IDs are correct, but lables are not:

This is the reason:
"optionLabels": "namespaces:devices_toggleButton:deviceName"

Re: RC37: userModule device selector takes wrong device type

Posted: 24 Jun 2015 14:51
by pz1
I fear that I must changed the installation on the RasPi2, and afterwards not properly synced it with my central directory, and for that matter not with Github. Can't verify that because Raspi2 did crash without proper backup. shame on me :oops:

So this morning I did change
"optionLabels": "namespaces:devices_toggleButton:deviceName"
into
"optionLabels": "namespaces:devices_sensorMultilevel:deviceId"

Remaining problem: I do get multi level sensors now, but not the DeviceId's (e.g. Solar Energy instead of PVLogger_74-2)

module.json

Code: Select all

{
	"dependencies" : [],
	"singleton" : false,
	"category" : "devices",
	"author" : "Pieter E. Zanstra (click for Recipe)",
	"homepage" : "http://forum.z-wave.me/viewtopic.php?f=3424&t=21381",
	"icon" : "calculator.png",
        "moduleName": "Arithmetic",
	"version" : "1.0.0",
	"maturity" : "stable",
	"repository" : {
		"type" : "",
		"source" : ""
	},
	"defaults" : {
		"title" : "__title__",
		"description" : "__description__",
		"formula" : ""
	},
	"schema" : {
		"type" : "object",
		"properties" : {
			"formula" : {
				"type" : "select",
				"enum" : ["add", "sub", "mult", "div"],
				"required" : true
			},
			"Title" : {
				"type" : "string",
				"required" : true
			},
			"scaleTitle" : {
				"type" : "string",
				"required" : true
			},
            "sensor1": {
                    "field": "enum",
                    "datasource": "namespaces",
                    "enum": "namespaces:devices_sensorMultilevel:deviceId",
                    "required": true
            },
			"metric1" : {
				"type" : "string",
				"required" : true
			},
            "sensor2": {
                    "field": "enum",
                    "datasource": "namespaces",
                    "enum": "namespaces:devices_sensorMultilevel:deviceId",
                    "required": true
            },
			"metric2" : {
				"type" : "string",
				"required" : true
			}

		},
		"required" : true
	},
	"options" : {
		"fields" : {
			"formula" : {
				"label" : "__formula__",
				"optionLabels" : ["a+b", "a-b", "a*b", "a/b"],
				"helper" : "__helper__"
			},
			"Title" : {
				"label" : "__sensor-name__",
				"placeholder" : "__sensor-name-placeholder__"
			},
			"scaleTitle" : {
				"label" : "__sensor-units__",
				"placeholder" : "__sensor-units-placeholder__"
			},
            "sensor1": {
                    "label": "__sensor1__",
                    "type": "select",
                    "datasource": "namespaces",
                    "field": "optionLabels",
                    "optionLabels": "namespaces:devices_sensorMultilevel:deviceId"
            },
			"metric1" : {
				"label" : "__metric1__",
				"placeholder" : "__metric1-placeholder__"
			},
            "sensor2": {
                    "label": "__sensor2__",
                    "type": "select",
                    "datasource": "namespaces",
                    "field": "optionLabels",
                    "optionLabels": "namespaces:devices_sensorMultilevel:deviceId"
            },
			"metric2" : {
				"label" : "__metric2__",
				"placeholder" : "__metric2-placeholder__"
			}
		}
	}
}
Nota Bene: I think it is not a good idea to select devices by their name. That puts a burden on every module to create unique names if the module allows multiple instances

Re: RC37: userModule device selector takes wrong device type

Posted: 25 Jun 2015 02:00
by PoltoS
pz1 wrote:So this morning I did change
"optionLabels": "namespaces:devices_toggleButton:deviceName"
into
"optionLabels": "namespaces:devices_sensorMultilevel:deviceId"
Should be
"optionLabels": "namespaces:devices_toggleButton:deviceName"
into
"optionLabels": "namespaces:devices_sensorMultilevel:deviceName"

Re: RC37: userModule device selector takes wrong device type

Posted: 25 Jun 2015 09:33
by pz1
PoltoS wrote: Should be

"optionLabels": "namespaces:devices_sensorMultilevel:deviceName"
I did try this one as well of course, still I do get the deviceNames and not the deviceIds in the dropdown list. As mentioned in my post the device names are not unique.
devicenames.png
devicenames.png (6.56 KiB) Viewed 6820 times

Re: RC37: userModule device selector takes wrong device type

Posted: 26 Jun 2015 02:40
by PoltoS
Name them uniquely ;) You can keep "namespaces:devices_sensorMultilevel:deviceId" to have IDs, but this is less userfiendly

Re: RC37: userModule device selector takes wrong device type

Posted: 26 Jun 2015 09:54
by pz1
PoltoS wrote:Name them uniquely ;)
Well the (fixed) names are created within the userModule. The DeviceId already is a unique identifier generated by the system, so to me it seems to be a bit awkward and superfluous, to create yet another unique identifier with my JS code.

Re: RC37: userModule device selector takes wrong device type

Posted: 26 Jun 2015 15:50
by PoltoS
Pieter, in schema you need to specify deviceId, while in options deviceName to let user select names and keep in options IDs.

Re: RC37: userModule device selector takes wrong device type

Posted: 26 Jun 2015 16:11
by pz1
As I said I tried all permutations. Also this one (tried that again just now, restarted ZWay). It just does not work since my index.js expects the DeviceId. ( Cannot instantiate module: Arithmetic: TypeError: object is not a function)

Since it seems impossible to get that Id in the selector, I am going to remove the option to choose a sensor from the configuration screen, and fall back to just a string field as I it was before.

Re: RC37: userModule device selector takes wrong device type

Posted: 27 Jun 2015 17:53
by pz1
Tested a bit further today.
My tests were conducted on virtualDevices created by PVLogger. As you can see above my userModule PVLogger does create two virtual devices (PVLogger_74-1 and PVLogger_74-2). The DeviceName that I do see in the selector via config.json seem to produce virtual device id PVLogger_74, which does not exist.
In that context it is unfortunate that I can't just select the DeviceId, as I had it working in some rc version. Sofar I have been unable to recreate that