RC37: userModule device selector takes wrong device types

Discussions about RaZberry - Z-Wave board for Raspberry computer
pz1
Posts: 2053
Joined: 08 Apr 2012 13:44

RC37: userModule device selector takes wrong device types

Post 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 6851 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.
Since 29-12-2016 I am no longer a moderator for this forum
User avatar
PoltoS
Posts: 7649
Joined: 26 Jan 2011 19:36

Re: RC37: userModule device selector takes wrong device type

Post by PoltoS »

IDs are correct, but lables are not:

This is the reason:
"optionLabels": "namespaces:devices_toggleButton:deviceName"
pz1
Posts: 2053
Joined: 08 Apr 2012 13:44

Re: RC37: userModule device selector takes wrong device type

Post 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
User avatar
PoltoS
Posts: 7649
Joined: 26 Jan 2011 19:36

Re: RC37: userModule device selector takes wrong device type

Post 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"
pz1
Posts: 2053
Joined: 08 Apr 2012 13:44

Re: RC37: userModule device selector takes wrong device type

Post 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 6821 times
User avatar
PoltoS
Posts: 7649
Joined: 26 Jan 2011 19:36

Re: RC37: userModule device selector takes wrong device type

Post by PoltoS »

Name them uniquely ;) You can keep "namespaces:devices_sensorMultilevel:deviceId" to have IDs, but this is less userfiendly
pz1
Posts: 2053
Joined: 08 Apr 2012 13:44

Re: RC37: userModule device selector takes wrong device type

Post 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.
User avatar
PoltoS
Posts: 7649
Joined: 26 Jan 2011 19:36

Re: RC37: userModule device selector takes wrong device type

Post by PoltoS »

Pieter, in schema you need to specify deviceId, while in options deviceName to let user select names and keep in options IDs.
pz1
Posts: 2053
Joined: 08 Apr 2012 13:44

Re: RC37: userModule device selector takes wrong device type

Post 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.
pz1
Posts: 2053
Joined: 08 Apr 2012 13:44

Re: RC37: userModule device selector takes wrong device type

Post 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
Post Reply