Author Topic: Using A Dimmer Light Switch As A Volume Control & Slider. (Sonos)  (Read 6905 times)

Offline parkerc

  • Beta Testers
  • Sr. Hero Member
  • *****
  • Posts: 2473
  • Karma: +35/-48
  • Life Moves Pretty Fast....
Using A Dimmer Light Switch As A Volume Control & Slider. (Sonos)
« on: September 18, 2012, 05:24:41 am »
Hi,

I've been playing with the idea of using an actual z-wave or lightwaveRF dimmer wall switch as a volume control for my Sonos. Currently I'm testing against an installed Fibaro dimmer switch (which is annoying the misses), but the hope is that I will be able to run another dimmer in isolation,so not connected to a light (this is still to be confirmed)

Looking at the dimmer levels of th light, they go from 0-100 (off to full on) and can be set to specific levels through a scene or code, but they only go up in 10s if clicking the UI device or the wall switch.

So to make this work via the wall switch, I'll look at having the increases and decreases being in increments of 10s.

The Sonos volume control from the vera plugin also seems to work from 0-100 (off to full on) and can be set to specific levels too, but I would not want to take that up to 100% :)

So my light level to volume mapping is currently looking as follows, the dimmer has a GetLoadalevelStatus option which I think checks the value set and the Sonos has a SetVolume & NewVolume option.

Dimmer = 0% - Sonos Volume = 0%
Dimmer = 10% - Sonos Volume = 10%
Dimmer = 20% - Sonos Volume = 20%
Dimmer = 30% - Sonos Volume = 25%
Dimmer = 40% - Sonos Volume = 30%
Dimmer = 50% - Sonos Volume = 35%
Dimmer = 60% - Sonos Volume = 40%
Dimmer = 70% - Sonos Volume = 45%
Dimmer = 80% - Sonos Volume = 50%
Dimmer = 90% - Sonos Volume = 55%
Dimmer = 100% - Sonos Volume =60%

I ideally would liked to have done this via the Scenes/Automation UI, but I am unable to set a trigger based on a Dimmer value, it's only if it is on or off.

Any help on how to create a piece of code to do the above would be hugely appreciated.

Offline futzle

  • Beta Testers
  • Master Member
  • *****
  • Posts: 3258
  • Karma: +191/-9
Re: Using A Dimmer Light Switch As A Volume Control & Slider. (Sonos)
« Reply #1 on: September 18, 2012, 06:46:55 am »
There's the luup.variable_watch() function which you could use to call a function every time the LoadLevelStatus variable changes.  I've never used it outside of a full-fledged plugin, I don't know if you can just stick it on a scene's Luup code or the global startup Lua but oTi@ reports that it works.  Give it a try.  There are a few examples of luup.variable_watch() that you can read: the Home Care plugin is a simple example, and dataMine is a complex example.

If you don't mind creating eleven Combination Switches and eleven scenes, you could do it without code entirely...
« Last Edit: September 19, 2012, 06:46:56 am by futzle »

Offline garrettwp

  • Master Member
  • *******
  • Posts: 6371
  • Karma: +227/-128
  • Vera 3, Lite, ISY994
Re: Using A Dimmer Light Switch As A Volume Control & Slider. (Sonos)
« Reply #2 on: September 18, 2012, 11:09:55 am »
I agree with futzle, have a look into the variable_watch function.

- Garrett

Offline oTi@

  • Master Member
  • *******
  • Posts: 4041
  • Karma: +32/-6
  • UI what ?!
Re: Using A Dimmer Light Switch As A Volume Control & Slider. (Sonos)
« Reply #3 on: September 19, 2012, 06:27:21 am »
luup.variable_watch() [...]  I've never used it outside of a full-fledged plugin, I don't know if you can just stick it on a scene's Luup code or the global startup Lua.
Conversely, I have a number of Luup-only scenes (that should be turned into a plug-in) registering for a watch. The scenes get started in the start-up Lua.
Dezwaved at the moment...

Offline parkerc

  • Beta Testers
  • Sr. Hero Member
  • *****
  • Posts: 2473
  • Karma: +35/-48
  • Life Moves Pretty Fast....
Re: Using A Dimmer Light Switch As A Volume Control & Slider. (Sonos)
« Reply #4 on: September 20, 2012, 05:15:31 pm »
Please excuse the following, it is my first attempt at some code, so be gentle. ;)

---the watch part to see if the dimmer level has changed.

local lul_argument {}
local value = luup.variable_watch("urn:upnp-org:serviceId:Dimming1", "LoadLevelTarget", 22)
lul_argument ["loadLevelTarget"] = 20

---if it has reached 20, set Sonos Volume to 20
---not sure how to set it, so that if 20 then go and set volume.

local lul_arguments = {}
lul_arguments["SetVolume"] = 25
lul_resultcode, lul_resultstring, lul_job, lul_returnarguments = luup.call_action("urn:micasaverde-com:serviceId:Volume1","SetVolume", lul_arguments,5)

---the above order then continues, so that each dimmer level has a corresponding volume level

Offline Tony G

  • Jr. Member
  • **
  • Posts: 56
  • Karma: +0/-0
Re: Using A Dimmer Light Switch As A Volume Control & Slider. (Sonos)
« Reply #5 on: March 31, 2013, 11:30:47 am »
were you ever successful in implementing this?

I have a similar setup, but instead of a Sonos I am using VLC with a media server. 

VLC has the great feature of having an HTTP remote interface, so I am wondering if we could trigger specific http requests when the user pushes the paddle up or down on a dimmer with no load (ca600)

Thanks!
« Last Edit: April 01, 2013, 12:25:12 am by Tony G »
Vera Lite, Intermatic HA07 (x2), GE 45601, Wayne-Dalton HA18 (10x), Intermatic CA600 (4x), Aeon Labs Micro Illuminator (3x), Everspring SM103 (6x), Intermatic CA9000 (x2), Wayne Dalton WDTC-20 (x2), Kwikset Deadbolt, GE45603, Hawking HRAM1,

Offline parkerc

  • Beta Testers
  • Sr. Hero Member
  • *****
  • Posts: 2473
  • Karma: +35/-48
  • Life Moves Pretty Fast....
Re: Using A Dimmer Light Switch As A Volume Control & Slider. (Sonos)
« Reply #6 on: April 01, 2013, 03:21:43 am »
Hi Tony G

Alas I did not progress very far with this, although in theory it should work if you map the dimmer levels to the volume levels.

The Luup.variable.watch is the key here, where you would set a dimmer 'load level' to trigger a volume level.

As for how you wire such a thing in, that is where is got to and stopped, so instead as I have the rtxrfx433 Vera add on I've been playing with an old x10 wall switch and just using that to control the up and down of the volume.

If you decide to have play, let me know how you get on.

Offline charlesrg

  • Jr. Member
  • **
  • Posts: 57
  • Karma: +1/-1
Re: Using A Dimmer Light Switch As A Volume Control & Slider. (Sonos)
« Reply #7 on: December 08, 2014, 11:56:58 pm »
Did you ever finish this ? I could not find a way to set the sonos volume without sending it a command for it to play something.
If you finish please let us know what your LUA code looks like.

Offline RichieB

  • Full Member
  • ***
  • Posts: 128
  • Karma: +2/-0
Re: Using A Dimmer Light Switch As A Volume Control & Slider. (Sonos)
« Reply #8 on: March 11, 2018, 10:43:29 am »
 i finally figured it out

so i use a Denon AVR E400 there is a plugin available but i wanted to tuse a dimmer as volume control

I crated a virtual Dimmer and created a custom implementation file

Code: [Select]

<?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)

local dBVolume = luup.variable_get ("urn:upnp-org:serviceId:Dimming1", "LoadLevelTarget", lul_device)
luup.call_action ("urn:upnp-org:serviceId:RenderingControl1", "SetVolume", {DesiredVolume= dBVolume}, 358)
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>

took me a while to get this

im the implementation u need to Get the number value of the dimmer and then pass it  to the avr

Quote
local dBVolume = luup.variable_get ("urn:upnp-org:serviceId:Dimming1", "LoadLevelTarget", lul_device)
            luup.call_action ("urn:upnp-org:serviceId:RenderingControl1", "SetVolume", {DesiredVolume= dBVolume}, 358)