simon_rb wrote:Ok, I now have the Grab Status one running every minute which is fine however I only want it to run when the switch is on as every time it updates the switch it turns the switch on. I only want it to update the dimmer value when its actually on..
As you have the "player switch" you could control the volume switch so that if the player switch is off, then the volume switch is off. And when the player switch turns on, it turns the volume switch on. If player switch is called "Lounge Touch" this would be with LUA something like:
Code: Select all
commandArray = {}
if devicechanged['Lounge Touch'] ~= 'Off' and devicechanged['Lounge Touch'] ~= 'Disconnected' then --add more conditions if needed (this reacts to 'On', 'Playing' and 'Stopped')
commandArray['Lounch Touch V'] == 'On'
elseif devicechanged['Lounge Touch'] == 'Off' or devicechanged['Lounge Touch'] == 'Disconnected' then
commandArray['Lounch Touch V'] == 'Off'
end
return commandArray
But you could maybe also just define the volume switch as slave to player switch.
Then the time script for reading the volume would be (voluem is updated only if the actual volume differs from the volume switch value and the player is on):
Code: Select all
commandArray = {}
json = (loadfile '/home/pi/domoticz/scripts/lua/json.lua')()
file = assert(io.popen('curl \'http://192.168.1.26:9000/jsonrpc.js\' --data-binary \'{"id":1,"method":"slim.request","params":["00:04:20:23:88:36",["status","-","1",""]]}\''))
raw = file:read('*all')
file:close()
deviceinfo = json:decode(raw)
volume = deviceinfo.result["mixer volume"]
switchVolume = otherdevices_svalues['Lounge Touch V']
if tonumber(volume) ~= tonumber(switchVolume) and otherdevices['Lounge Touch'] ~= 'Off' and otherdevices['Lounge Touch'] ~= 'Disconnected' then
commandArray['OpenURL'] = 'http://127.0.0.1:8080/json.htm?type=command¶m=switchlight&idx=265&switchcmd=Set%20Level&level='..volume
end
return commandArray
as a second option you could always read the palyer power status from the json:
Code: Select all
commandArray = {}
json = (loadfile '/home/pi/domoticz/scripts/lua/json.lua')()
file = assert(io.popen('curl \'http://192.168.1.26:9000/jsonrpc.js\' --data-binary \'{"id":1,"method":"slim.request","params":["00:04:20:23:88:36",["status","-","1",""]]}\''))
raw = file:read('*all')
file:close()
deviceinfo = json:decode(raw)
volume = deviceinfo.result["mixer volume"]
powerstatus = deviceinfo.result.power
switchVolume = otherdevices_svalues['Lounge Touch V']
if tonumber(volume) ~= tonumber(switchVolume) and tonumber(powerstatus) == 1 then
commandArray['OpenURL'] = 'http://127.0.0.1:8080/json.htm?type=command¶m=switchlight&idx=265&switchcmd=Set%20Level&level='..volume
end
return commandArray
And if you want, you could also change the on / off behavior so that you read the volume level when the player turns on and update it directly to correct volume. But the above will sort it as soon as the time script runs so not too much added benefit from this...
edit: I'd like to add that there are actually quite many "devicechanged" events for the Squeezebox players as when the playing track changes, it also triggers the devicechanged event. Because of this, I've created a uservariable for each player that get's value of 1 if the player is on and playing something and value of 0 if it is off, disconnected or stopped. Then I use this variable in other scripts to avoid the scripts triggering on each track change.