Virtual Dimmer

Hello!

Has anyone ever implemented a virtual DimmableLight? Any link?

I’m developing yet-another-external-UI and don’t want to install a whole set of real zwave device just to test my software. Actually I have a Vera 2 controller and various devices but no working light dimmer right now.

I guess a “library” of virtual devices (one for each category) would be greatly useful for many UI developers.

If such a thing does not exists, I shall implement it by myself. AFAIU, I need to create an implementation file I_DimmableLight1.xml (an XML embedding some Lua code) which is the companion of the specification contained in D_DimmableLight1.xml . Am I correct?

Thanks in advance.

Guido De Rosa

The “Plugin for cm15a/cm19a X10 Controllers” ([tt]http://forum.micasaverde.com/index.php/topic,7463.0.html[/tt]) implements a “virtual” dimmer that “connects” to a real X10 dimmer.

Here are some implementation files for virtual devices. There are:

[ul][li]a virtual binary light[/li]
[li]a virtual dimmable light[/li]
[li]a virtual thermostat[/li]
[li]a virtual window covering[/li][/ul]

VirtualDevices.zip (2.6 KB)

Is it possible to create a virtual device that supports group associations?
I need to create association from a physical switch to a virtual one.
Currently, the virtual devices do not appear in the device list in the Device Option/Associations/Set menu.

Fantastic! DimmableLight works great. Many thanks.

I think this should be made available on the wiki :wink:

Guido

Hello

in the virtual module I_covering I can meter up for example:
luup.inet.wget (“http://192.168.1.60/teleco.cgi&channel=2&action=up”) and to stop
luup.inet.wget (“http://192.168.1.60/teleco.cgi&channel=2&action =” my “) and down luup.inet.wget (” http://192.168.1.60/teleco.cgi&channel=2&action=down ")

I’m ui5 if possible I would need more to remove the dimmer and close and open the panel on the device

I have an post here
[url=http://forum.micasaverde.com/index.php/topic,9520.0.html]http://forum.micasaverde.com/index.php/topic,9520.0.html[/url]

[quote=“mcvflorin, post:3, topic:169515”]Here are some implementation files for virtual devices. There are:

[ul][li]a virtual binary light[/li]
[li]a virtual dimmable light[/li]
[li]a virtual thermostat[/li]
[li]a virtual window covering[/li][/ul][/quote]

I think someone should transfer these to apps.mios.com as plugins. This makes it possible for not so advanced users to install and use them.

I’m not an advanced user and I don’t know how to create these virtual devices.
I’m guessing that I should click on Mios developers icon, then upload the xml file?
But they don’t come with .json file?
I would appreciate any guidance. Thanks!!

if you’re on UI5, then go to Apps / Develop Apps / LUUP files. Upload the xml files you want,
then select create device from the left side menu (say you are creating a virtual BinaryLight1)
enter D_BinaryLight1.xml as Upnp Device Filename
enter I_BinaryLight1.xml as Upnp Implementation Filename

you are all set!

Thanks capjay! I’m on UI4 but your direction gave enough hints to get me going.

I have a question about the I_DimmableLight1.xml file. At the end of the action SetLoadLevelTarget it has the statement “return 4, 5.” What do these return values to the caller represent?

Thanks,
Chris

The first value is the job status (4 = job done), the second value is the job timeout (5 seconds).
Please read this: http://wiki.micasaverde.com/index.php/Luup_Plugins_ByHand#run.2Fjob.2Fincoming.2Ftimeout

I know this is an old topic but hoping someone will be able to help me. I’ve created a virtual dimmer which works fine in the web UI, but if I try to use it in Imperihome or Authomation it only takes an input from the slider. The On and Off functions don’t work. Any ideas?

There seems to be a problem with the virtual dimmer device.

The OFF button does not work for me.

The ON button does work OK and the slider 0% to 100% works OK also.

However when I press the OFF button the device is not turned off.

How to fix ?

This is the original code in the I_DimmableLight1.xml file:

<?xml version="1.0"?>
<implementation>
	<functions>
		function virtual_dimmable_light_startup (lul_device)
			luup.log ("Virtual dimmable light running...")
		end
	</functions>
	<startup>virtual_dimmable_light_startup</startup>
	<actionList>
		<action>
			<serviceId>urn:upnp-org:serviceId:Dimming1</serviceId>
			<name>SetLoadLevelTarget</name>
			<job>
				luup.variable_set ("urn:upnp-org:serviceId:Dimming1", "LoadLevelTarget", lul_settings.newLoadlevelTarget, lul_device)
				luup.variable_set ("urn:upnp-org:serviceId:Dimming1", "LoadLevelStatus", lul_settings.newLoadlevelTarget, lul_device)
				if (tonumber (lul_settings.newLoadlevelTarget, 10) == 0) then
					luup.variable_set ("urn:upnp-org:serviceId:SwitchPower1", "Status", "0", lul_device)
				else
					luup.variable_set ("urn:upnp-org:serviceId:SwitchPower1", "Status", "1", lul_device)
				end
				return 4, 5
			</job>
		</action>
	</actionList>
</implementation>

UPDATE:

Updated code fixes the OFF button:

<?xml version="1.0"?>
<implementation>
	<functions>
		function virtual_dimmable_light_startup (lul_device)
			luup.log ("Virtual dimmable light running...")
		end
	</functions>
	<startup>virtual_dimmable_light_startup</startup>
	<actionList>
		<action>
			<serviceId>urn:upnp-org:serviceId:Dimming1</serviceId>
			<name>SetLoadLevelTarget</name>
			<job>
				luup.variable_set ("urn:upnp-org:serviceId:Dimming1", "LoadLevelTarget", lul_settings.newLoadlevelTarget, lul_device)
				luup.variable_set ("urn:upnp-org:serviceId:Dimming1", "LoadLevelStatus", lul_settings.newLoadlevelTarget, lul_device)
				if ( tonumber(lul_settings.newLoadlevelTarget or 0) ) == 0 then
					luup.variable_set ("urn:upnp-org:serviceId:SwitchPower1", "Target", "0", lul_device)
					luup.variable_set ("urn:upnp-org:serviceId:SwitchPower1", "Status", "0", lul_device)
				else
					luup.variable_set ("urn:upnp-org:serviceId:SwitchPower1", "Target", "1", lul_device)
					luup.variable_set ("urn:upnp-org:serviceId:SwitchPower1", "Status", "1", lul_device)
				end
				return 4, 5
			</job>
		</action>
		<action>
			<serviceId>urn:upnp-org:serviceId:SwitchPower1</serviceId>
			<name>SetTarget</name>
			<job>
				luup.variable_set ("urn:upnp-org:serviceId:SwitchPower1", "Target", lul_settings.newTargetValue, lul_device)
				luup.variable_set ("urn:upnp-org:serviceId:SwitchPower1", "Status", lul_settings.newTargetValue, lul_device)
				if lul_settings.newTargetValue ~= "0" then
					luup.variable_set ("urn:upnp-org:serviceId:Dimming1", "LoadLevelTarget", "100", lul_device)
					luup.variable_set ("urn:upnp-org:serviceId:Dimming1", "LoadLevelStatus", "100", lul_device)
				else
					luup.variable_set ("urn:upnp-org:serviceId:Dimming1", "LoadLevelTarget", "0", lul_device)
					luup.variable_set ("urn:upnp-org:serviceId:Dimming1", "LoadLevelStatus", "0", lul_device)
				end
				return 4, 5
			</job>
		</action>
	</actionList>
</implementation>

Updated I_DimmableLight1.xml file here:

I_DimmableLight1.zip (602 Bytes)

If I manually edit the “Status” variable for the ON / OFF switch and change its value to 0 from 1, the device then turns off and the on / off button in the GUI shows as off.

image

image

However if I simply press the off button in the GUI I get a spinner appear for a while and then nothing happens, the switch button remains in the on position and the device hasn’t turned off.

If instead of pressing the OFF button, I move the slider down to 0% then that works and the device turns off and the off button shows as being off in the GUI.

Target (SwitchPower1) and LoadLevelTarget should also stay in sync (if LoadLevelTarget goes to 0, Target should be 0; if loadlevel > 0, Target should be 1).

Edit: it should be clear that this implies that your virtual dimmer must implement the SwitchPower1 action SetTarget as well, and coordinate back to LoadLevelTarget and LoadLevelStatus accordingly. The on-off switch uses the SetTarget action.

Hi Patrick

When the virtual dimmer device is OFF and slider is 0% (which I moved to 0%) and the OFF button in the GUI is showing as being off the variables look like this:

image

When the virtual dimmer device is ON and the slider is 100% and the ON button in the GUI is showing as being on the variables look like this:

image

If I press the OFF button nothing changes the variables still look like the above screen shot

If I then move the slider again back to 0% the variables look like this again:

image

See my edit to my previous post. You haven’t implemented all of the services/actions that a dimmer requires yet.

So the original code is incorrect then?

I need a coder to fix it LOL.

Or just use Switchboard, which does exactly all of this stuff. Sometimes virtual devices are more complicated than they seem at the surface. Coordinating these variables isn’t hard, though, it’s just hard to discover. If you want to do it yourself, here’s a revised version of your actions (one revised, one new):

		<action>
			<serviceId>urn:upnp-org:serviceId:Dimming1</serviceId>
			<name>SetLoadLevelTarget</name>
			<job>
				luup.variable_set ("urn:upnp-org:serviceId:Dimming1", "LoadLevelTarget", lul_settings.newLoadlevelTarget, lul_device)
				luup.variable_set ("urn:upnp-org:serviceId:Dimming1", "LoadLevelStatus", lul_settings.newLoadlevelTarget, lul_device)
				if ( tonumber(lul_settings.newLoadlevelTarget or 0) ) == 0 then
					luup.variable_set ("urn:upnp-org:serviceId:SwitchPower1", "Target", "0", lul_device)
					luup.variable_set ("urn:upnp-org:serviceId:SwitchPower1", "Status", "0", lul_device)
				else
					luup.variable_set ("urn:upnp-org:serviceId:SwitchPower1", "Target", "1", lul_device)
					luup.variable_set ("urn:upnp-org:serviceId:SwitchPower1", "Status", "1", lul_device)
				end
				return 4, 5
			</job>
		</action>
		<action>
			<serviceId>urn:upnp-org:serviceId:SwitchPower1</serviceId>
			<name>SetTarget</name>
			<job>
				luup.variable_set ("urn:upnp-org:serviceId:SwitchPower1", "Target", lul_settings.newTargetValue, lul_device)
				luup.variable_set ("urn:upnp-org:serviceId:SwitchPower1", "Status", lul_settings.newTargetValue, lul_device)
				if lul_settings.newTargetValue ~= "0" then
					luup.variable_set ("urn:upnp-org:serviceId:Dimming1", "LoadLevelTarget", "100", lul_device)
					luup.variable_set ("urn:upnp-org:serviceId:Dimming1", "LoadLevelStatus", "100", lul_device)
				else
					luup.variable_set ("urn:upnp-org:serviceId:Dimming1", "LoadLevelTarget", "0", lul_device)
					luup.variable_set ("urn:upnp-org:serviceId:Dimming1", "LoadLevelStatus", "0", lul_device)
				end
				return 4, 5
			</job>
		</action>

Note that this code does not handle LoadLevelLast or restoring the dimmer at its previous level if you use the on/off switch (SwitchPower1/SetTarget action). That requires even more coordination throughout. If that’s important to you, just punt and go to Switchboard.

BTW: The absence of the SwitchPower1 service should have stood out like a sore thumb in your LuaUPnP.log when you tried to operate the on/off control… always check that…

1 Like