Customize Dimmer Behavior

I am attempting to use a standard dimmer control to control volume (via slider) and power (via on / off buttons) on an AV receiver. I would like this to remain on a standard dimmer device so that it can be controlled from third party apps (such as Imperihome).

I have the code worked out for communication with the receiver and I have the volume control working on the virtual dimmer, however i cannot seem to get the on / off to trigger SwitchPower. Instead On / Off sets the slider level to 0 / 100 respectively.

I created a custom implementation file containing the following (sloppy) code, which never executes:

[code]

urn:upnp-org:serviceId:SwitchPower1
SetTarget

local deviceID
–336 = living room amp
–337 = loft amp
–105 = living room amp volume control
–107 = loft volume control

			if lul_device == 105 then
				--Living Room Volume Control
				deviceID = 336 
			elseif lul_device == 107 then
				--Loft Volume Control
				deviceID = 337
			end
			
	luup.call_action("urn:upnp-org:serviceId:SwitchPower1", "SetTarget", lul_settings.newTargetValue, deviceID)

  </run>

[/code]

It looks like the json file is setting the loadlevel status instead of the dimmer instead of the status of SwitchPower, so I also tried creating a custom json file for this dimmer, modifying some of the control tags as below (copying the binary switch file).

"Control": [ { "ControlGroup": "1", "ControlType": "multi_state_button", "top": "0", "left": "1", "states":[ { "Label": { "lang_tag": "ui7_cmd_on", "text": "On" }, "ControlGroup": "1", "Display": { "Service": "urn:upnp-org:serviceId:SwitchPower1", --Changed from urn:upnp-org:serviceId:Dimming1 "Variable": "Status", -- Changed from LoadLevelStatus "Value": "1" -- Changed from 100, typically changed for the remainder of this code snippet }, "Command": { "Service": "urn:upnp-org:serviceId:SwitchPower1", "Action": "SetTarget", "Parameters": [ { "Name": "newTargetValue", "Value": "1" } ] }, "ControlCode": "power_on" }, { "Label": { "lang_tag": "ui7_cmd_off", "text": "Off" }, "ControlGroup": "1", "Display": { "Service": "urn:upnp-org:serviceId:SwitchPower1", "Variable": "Status", "Value": "0" }, "Command": { "Service": "urn:upnp-org:serviceId:SwitchPower1", "Action": "SetTarget", "Parameters": [ { "Name": "newTargetValue", "Value": "0" } ] }, "ControlCode": "power_off" } ]

Am I approaching this incorrectly? It seems like it should be trivial, but it’s eating my lunch.

The only way I was able to get this functionality working in a way that seemed universally accepted by third party developers was by creating and watching child devices. These child devices get created as “native” dimmer / binaryswitch devices and then work with third party apps.

I’m not sure why you aren’t able to get those actions working. I was able to get similar actions working on custom devices, just they would never show up in third party apps.

I never figured out child devices. How would you go about creating a child on off switch (that could control a on off state of an amplifier for example)?

You shouldn’t have to use child devices…

You need to realize that, if you change the D_DimmableLight1.json on the Vera, It will affect all dimmer devices that use that json file… this is a bad thing…

The D_DimmableLight1.json (json file) file is paired with the D_DimmableLight1.xml (device file)… The standard dimmer device does not use an implementation file, because the implementation is handled by the parent device… All dimmer devices will have a parent, in the case of natively supported devices it is the Z-Wave (or ZigBee or Bluetooth) system device…

The “trick” is to create a dimmer device that does not have a parent… A device that does not have a parent requires an implementation file…

So, to get a custom dimmer device which appears as a standard dimmer device, you need to prepare a custom device file, a custom json file, and a custom implementation file…

For your specific case, you would need to copy D_DimmableLight1.xml and D_DimmableLight1.json to new files - IE: D_StereoControl1.xml and D_StereoControl1.json.

You then edit tag in the D_StereoControl1.xml file to specify the D_StereoControl1.json file. The you modify the D_StereoControl1.json file (as you did in your original post). Yo then need to create the I_StereoControl1.xml implementation file, and define all the actions that are required for your task…

Then, ** VERY IMPORTANT ** use a json lint program (local or online) to validate your D_StereoControl1.xml and xml lint program to validate your D_StereoControl1.xml and I_StereoControl1.xml files. Once you are sure there are no json or xml errors, you can upload the custom files to the Vera.

the you manually create a dimmer device - you need to specify:
Device Type : urn:schemas-upnp-org:device:DimmableLight:1
Description:
UPnP Device filename: D_StereoControl1.xml
UPnP Implementation filename: I_StereoControl1.xml
Then click on “Create”…

You then wait a minute (or more) for the device to be created… then reload the LuaUPnP engine to make sure that the device is actually loaded… and refresh your browser to make sure you are seeing current devices… Then look at the LuaUPnP.log file to make sure that your lua code did not throw and errors when loading…

This should give you a “standard” dimmer device that uses a custom json and implementation file, without having to create and manage child devices.

You can then test the UI interface for your device… using the LuaUPnP.log file to catch any errors…