

Moderator: leecollings
Code: Select all
commandArray = {}
if devicechanged['Lounge Touch V'] ~= 'Off' then
volume = otherdevices_svalues['Lounge Touch V']
calcvolume = (volume*100) / 31
commandArray['Lounge Touch']='Set Volume '..calcvolume
end
return commandArray
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']
calcVolume = math.floor((switchVolume*100 / 31)+0.5)
if tonumber(volume) ~= tonumber(calcVolume) 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
if tonumber(powerstatus) == 1 and otherdevices['Lounge Touch V'] == 'Off' then
commandArray['OpenURL'] = 'http://127.0.0.1:8080/json.htm?type=command¶m=switchlight&idx=265&switchcmd=Set%20Level&level='..volume
end
if tonumber(powerstatus) == 0 and otherdevices['Lounge Touch V'] ~= 'Off' then
commandArray['Lounge Touch V'] = 'Off'
end
return commandArray
I have one player for outdoor speakers where perhaps this kind of volume switch would be nice as well. So I went ahead and tested and there's some things I did not consider. But this seems to work for setting the volume. You need to create one user variable as well, type integer to store the volume level before "Off" as for some reason this new dummy dimmer seems to set it to 0 when Off. So when turning it back to On, the value will be taken from the uservariable.simon_rb wrote:I'll try them and see what happens. I had the power on setup already. I'll let you..
Code: Select all
if devicechanged['Lounge Touch V'] ~= 'Off' and devicechanged['Lounge Touch V'] ~= nil then
if tonumber(otherdevices_svalues['Lounge Touch V']) > 0 then
volume = otherdevices_svalues['Lounge Touch V']
calcvolume = math.floor((volume*100/32)+0.5)
print('Setting Lounge Touch volume to '..calcvolume)
commandArray['Lounge Touch']='Set Volume '..calcvolume
commandArray['Variable:LoungeTouchVolume'] = otherdevices_svalues['Lounge Touch V']
else
volume = tonumber(uservariables['LoungeTouchVolume'])
calcvolume = math.floor((volume*100/32)+0.5)
commandArray['Lounge Touch']='Set Volume '..calcvolume
end
end
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)
volume = deviceinfo.result["mixer volume"]
powerstatus = deviceinfo.result.power
switchVolume = otherdevices_svalues['Lounge Touch V']
print(switchVolume)
calcVolume = math.floor((volume/100*31)+0.5)
print(calcVolume)
if tonumber(volume) ~= tonumber(calcVolume) and tonumber(powerstatus) == 1 then
os.execute('curl -s "http://url/json.htm?type=command¶m=switchlight&idx=IDX&switchcmd=Set%20Level&level='..calcVolume..'" &')
end
if tonumber(powerstatus) == 1 and otherdevices['Lounge Touch V'] == 'Off' then
os.execute('curl -s "url/json.htm?type=command¶m=switchlight&idx=IDX&switchcmd=Set%20Level&level='..calcVolume..'" &')
end
if tonumber(powerstatus) == 0 and otherdevices['Lounge Touch V'] ~= 'Off' then
commandArray['Lounge Touch V'] = 'Off'
end
end
return commandArray
Code: Select all
if uservariables['Lounge Touch'] == 'On' then
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']
print(switchVolume)
calcVolume = math.floor((volume/100*31)+0.5)
print(calcVolume)
if tonumber(volume) ~= tonumber(calcVolume) and tonumber(powerstatus) == 1 then
os.execute('curl -s "http://192.168.1.26:8080/json.htm?type=command¶m=switchlight&idx=281&switchcmd=Set%20Level&level='..calcVolume..'" &')
end
if tonumber(powerstatus) == 1 and otherdevices['Lounge Touch V'] == 'Off' then
os.execute('curl -s "http://192.168.1.26:8080/json.htm?type=command¶m=switchlight&idx=281&switchcmd=Set%20Level&level='..calcVolume..'" &')
end
if tonumber(powerstatus) == 0 and otherdevices['Lounge Touch V'] ~= 'Off' then
commandArray['Lounge Touch V'] = 'Off'
end
end
return commandArray
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']
print(switchVolume)
calcVolume = math.floor((volume/100*31)+0.5)
print(calcVolume)
if tonumber(volume) ~= tonumber(calcVolume) and tonumber(powerstatus) == 1 then
os.execute('curl -s "http://192.168.1.26:8080/json.htm?type=command¶m=switchlight&idx=281&switchcmd=Set%20Level&level='..calcVolume..'" &')
end
if tonumber(powerstatus) == 1 and otherdevices['Lounge Touch V'] == 'Off' then
os.execute('curl -s "http://192.168.1.26:8080/json.htm?type=command¶m=switchlight&idx=281&switchcmd=Set%20Level&level='..calcVolume..'" &')
end
if tonumber(powerstatus) == 0 and otherdevices['Lounge Touch V'] ~= 'Off' then
commandArray['Lounge Touch V'] = 'Off'
end
return commandArray
Yes, as mentioned a few posts earliersimon_rb wrote:The Lounge Touch V switch will turn on and off to reflect the players power status however turning off the Lounge Touch V switch will just turn off the switch and the player remains on, then a minute later the Lounge Touch V turns back on lol. I have the turn on action to turn the player on, do I need to set the turn off action to turn the player off. Last time the scripts turned off the player when the Lounge Touch V was turned off.
(you need to start really paying attention to what there is defined in the script, especially if you see something you are not expecting. Only this way you can learn and amend stuff to work to your likingAs suggested by the thread starter, to control the player on/off status you can put to on action of the Lounge Touch V something like this:
"http://192.168.1.10:9000/status.html?p0 ... 2.168.1.10" (change the first address to LMS ip and port and second to player ip). For off action change power_on to power_off. Then the device script can just control the volume.
Code: Select all
if devicechanged['Lounge Touch V'] ~= 'Off' and devicechanged['Lounge Touch V'] ~= nil and tonumber(otherdevices_svalues['Lounge Touch V']) > 0 then
volume = otherdevices_svalues['Lounge Touch V']
calcvolume = math.floor((volume*100/32)+0.5)
print('Setting Lounge Touch volume to '..calcvolume)
commandArray['Lounge Touch']='Set Volume '..calcvolume
end
Code: Select all
calcVolume = math.floor((volume/100*32)+0.5)
Code: Select all
calcvolume = math.floor((volume*100/31)+0.5)
You have just changed the 32 & 31s around? Unfortunately it doesn't work my end.. its still going down lolHey, I got it working at least based on quick test by using
CODE: SELECT ALL
calcVolume = math.floor((volume/100*32)+0.5)
In the time script and
CODE: SELECT ALL
calcvolume = math.floor((volume*100/31)+0.5)
on the device script. Now it send always the same volume to player although sValue changes by +/- 1. Need to think something more robust just in case though...
Yes, noticed it only worked with big enough levels. With small sValue levels it started going down. Tried it the other way around and this seems to work with both big and small levelssimon_rb wrote:My apologise for the miss understanding with the On and Off, I didn't add the Off as wasn't sure it would create some sort of loop. So the scripts no longer turn off Lounge Touch when Lounge Touch V is off - understood. I have the On already so I can copy that and change it to off. The user variable is understood. Could have it if Lounge Touch V is anything other than Off run the script.
You have just changed the 32 & 31s around? Unfortunately it doesn't work my end.. its still going down lolHey, I got it working at least based on quick test by using
CODE: SELECT ALL
calcVolume = math.floor((volume/100*32)+0.5)
In the time script and
CODE: SELECT ALL
calcvolume = math.floor((volume*100/31)+0.5)
on the device script. Now it send always the same volume to player although sValue changes by +/- 1. Need to think something more robust just in case though...
Code: Select all
playervolume = deviceinfo.result["mixer volume"]
playercalc = math.floor((playervolume/100*31)+0.5)
switchvolume = otherdevices_svalues['Terassin äänenvoimakkuus']
switchcalc = math.floor((switchvolume*100/31)+0.5)
difference = math.abs(switchcalc - playervolume)
if difference > 2 and tonumber(powerstatus) == 1 then
os.execute('curl -s "http://url/json.htm?type=command¶m=switchlight&idx=314&switchcmd=Set%20Level&level='..playercalc..'" &')
end
if tonumber(powerstatus) == 1 and otherdevices['Terassin äänenvoimakkuus'] == 'Off' then
os.execute('curl -s "http://url/json.htm?type=command¶m=switchlight&idx=314&switchcmd=Set%20Level&level='..playercalc..'" &')
end
if tonumber(powerstatus) == 0 and otherdevices['Terassin äänenvoimakkuus'] ~= 'Off' then
commandArray['Terassin äänenvoimakkuus'] = 'Off'
end
Code: Select all
commandArray['UpdateDevice'] = '409|2|60'
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)
playervolume = deviceinfo.result["mixer volume"]
playercalc = math.floor((playervolume/100*31)+0.5)
switchvolume = otherdevices_svalues['Lounge Touch V']
switchcalc = math.floor((switchvolume*100/31)+0.5)
difference = math.abs(switchcalc - playervolume)
if difference > 2 and tonumber(powerstatus) == 1 then
os.execute('curl -s "http://192.168.1.26:8080/json.htm?type=command¶m=switchlight&idx=281&switchcmd=Set%20Level&level='..playercalc..'" &')
end
if tonumber(powerstatus) == 1 and otherdevices['Lounge Touch V'] == 'Off' then
os.execute('curl -s "http://192.168.1.26:8080/json.htm?type=command¶m=switchlight&idx=281&switchcmd=Set%20Level&level='..playercalc..'" &')
end
if tonumber(powerstatus) == 0 and otherdevices['Lounge Touch V'] ~= 'Off' then
commandArray['Lounge Touch V'] = 'Off'
end
return commandArray
Cheers G3rard. It's pretty much all NautilusG3rard wrote:Will post my script here once it is finished.
I know, but my script is a bit different as I have a Sonossimon_rb wrote: Cheers G3rard. It's pretty much all Nautilus
Correct - didn't have time to change them nowsimon_rb wrote:Excellent - I shall give it ago.. It looks like you have changed quite a lot! lol Terassin äänenvoimakkuus = Lounge Touch V, that right?
Yes, this is something I was thinking earlier (viewtopic.php?f=23&t=9638#p101592) as well, just didn't know about the option"2" for nValue for not triggering the script. I had earlier played with the same (using json / udevice though, i.e. /json.htm?type=command¶m=udevice&idx=IDX&nvalue=NVALUE&svalue=SVALUE) and managed to change status without triggering the On/Off scripts but LUA would still be executed on devicechange. But good to know this.G3rard wrote:I found that it is possible to update the dimmer switch in Domoticz without triggering the script (to avoid the volume loop) withCode: Select all
commandArray['UpdateDevice'] = '409|2|60'
Yes, I guess it is. Though I first want to make sure the current script works properly and once I feel confident it does, then maybe change the dimmer type...simon_rb wrote:Is it worth going back to the 100 step dimmer then?
Users browsing this forum: No registered users and 1 guest