simon_rb wrote:I ran it from command to see whats happening, the script didn't do anything within Domoticz.. Confusing! LOL Hows your script coming along?
I changed mine to 100 step dimmer and have it working now both ways. The scripts I use for this are basically 1) Device:
Code: Select all
if devicechanged['Terassin äänenvoimakkuus'] ~= 'Off' and devicechanged['Terassin äänenvoimakkuus'] ~= nil then
if tonumber(otherdevices_svalues['Terassin äänenvoimakkuus']) > 0 then
volume = otherdevices_svalues['Terassin äänenvoimakkuus']
commandArray['Musiikki terassi']='Set Volume '..volume
end
end
if (devicechanged['Musiikki terassi'] == 'Off' or devicechanged['Musiikki terassi'] == 'Stopped' or devicechanged['Musiikki terassi'] == 'Disconnected') then
if otherdevices['Terassin äänenvoimakkuus'] ~= 'Off' then
commandArray[#commandArray+1]={['Terassin äänenvoimakkuus'] = 'Off'}
end
end
and 2) Time:
Code: Select all
if uservariables['SBTerassiStatus'] == 'On' then
json = (loadfile '/home/pi/domoticz/scripts/lua/json.lua')()
file = assert(io.popen('curl \'http://url/jsonrpc.js\' --data-binary \'{"id":1,"method":"slim.request","params":["mac",["status","-","1",""]]}\''))
raw = file:read('*all')
file:close()
deviceinfo = json:decode(raw)
powerstatus = deviceinfo.result.power
playervolume = deviceinfo.result["mixer volume"] + 1
switchvolume = otherdevices_svalues['Terassin äänenvoimakkuus']
difference = math.abs(switchvolume - playervolume)
if difference > 1 and tonumber(powerstatus) == 1 then
os.execute('curl -s "http://192.168.11.92:30/json.htm?type=command¶m=switchlight&idx=314&switchcmd=Set%20Level&level='..playervolume..'" &')
end
if tonumber(powerstatus) == 1 and otherdevices['Terassin äänenvoimakkuus'] == 'Off' then
os.execute('curl -s "http://192.168.11.92:30/json.htm?type=command¶m=switchlight&idx=314&switchcmd=Set%20Level&level='..playervolume..'" &')
end
end
Player on/off is still via the On/Off action of the volume switch.
Also, When playing about I think it is the device script that would end up making the players go to 0 when they are turned on!
That's correct. As explained in few previous posts (;)), the Off command basically equal sValue = 0 and the On does not change it to anything else. So if the volume dimmer just turn on, sValue is always 0 and if you let that to be sent to the player it is muted. Therefore you need to ignore sValue = 0 completely. The uservariable method I mentioned about will allow you to send the same sValue as it was before last "Off" but it should not be necessary to use this as the player should be on the same volume as it previously was...
edit: if there are some confusing bits there, it is probably because I had already scripts for "Musiikki terassi" ( = the player) and I just added the parts I needed for "Terassin äänenvoimakkuus" ( = the volume dimmer). But I copied here just the relevant parts for this purpose.