
Simple LMS LUA volume dimmer
Moderator: leecollings
-
- Posts: 612
- Joined: Wednesday 07 August 2013 19:09
- Target OS: -
- Domoticz version:
- Location: UK
- Contact:
Re: Simple LMS LUA volume dimmer
I had a try with grabbing the "Level" instead of using svalue and got completely confused. Started by using your JSON for the LMS player in the time script and tried adding it to the device script and grabbing the "Level" value and comparing that rather than the svalue but too many errors etc.. So close.. lol 

-
- Posts: 612
- Joined: Wednesday 07 August 2013 19:09
- Target OS: -
- Domoticz version:
- Location: UK
- Contact:
Re: Simple LMS LUA volume dimmer
Am I close? I suspect my file = assert isn't quite right and my the device info.result might need more than just Level..
It runs but get a Nil value as I don't know how to read the Level from the JSON, not sure what the syntax should be lol
It runs but get a Nil value as I don't know how to read the Level from the JSON, not sure what the syntax should be lol
Code: Select all
commandArray = {}
json = (loadfile '/home/pi/domoticz/scripts/lua/json.lua')()
file = assert(io.popen('curl \'http://http://192.168.1.26:8080/json.htm?type=devices&rid=265'))
raw = file:read('*all')
file:close()
deviceinfo = json:decode(raw)
vlevel = deviceinfo.result["Level"]
if devicechanged['Lounge Touch V'] then
targetvolume = vlevel
if devicechanged['Lounge Touch V'] == 'Off' and otherdevices['Lounge Touch'] ~= 'Off' then
commandArray['Lounge Touch'] = 'Off'
elseif devicechanged['Lounge Touch V'] == 'On' and otherdevices['Lounge Touch'] == 'Off' then
commandArray[#commandArray+1]={['Lounge Touch'] = 'On'}
commandArray[#commandArray+1]={['Lounge Touch'] = 'Set Volume '..targetvolume}
else
commandArray['Lounge Touch'] = 'Set Volume '..targetvolume
end
end
return commandArray
-
- Posts: 722
- Joined: Friday 02 October 2015 12:12
- Target OS: Raspberry Pi / ODroid
- Domoticz version: beta
- Location: Finland
- Contact:
Re: Simple LMS LUA volume dimmer
Ok, now this maybe starts to make more sense, maybesimon_rb wrote:You have the patience of a saint. This is working except for the On command. If you say set to 20% for example it will send an On command which can't be helped (HomeKit thing). But when the scripts tries to send 'On' the volume goes to zero. Is there a way to ignore the On and after the minute the script will get the current volume state from the player and everything is fine. Its hit and miss when you use Siri to set the volume sometimes the on command is sent first and sometimes second - its when its sent second it becomes a problem as it leaves the switch with 'On' then the script tries to send 'On' and the dimmer is set to 0. Maybe its more of a domoticz thing..
Thanks for all your help and patience!

Code: Select all
else
commandArray['Lounge Touch'] = 'Set Volume '..targetvolume
end
As mentioned, the script does what you are asking it to do, no more, no lessIs there a way to ignore the On and after the minute the script will get the current volume state from the player and everything is fine. Its hit and miss when you use Siri to set the volume sometimes the on command is sent first and sometimes second - its when its sent second it becomes a problem as it leaves the switch with 'On' then the script tries to send 'On' and the dimmer is set to 0. Maybe its more of a domoticz thing..

-
- Posts: 722
- Joined: Friday 02 October 2015 12:12
- Target OS: Raspberry Pi / ODroid
- Domoticz version: beta
- Location: Finland
- Contact:
Re: Simple LMS LUA volume dimmer
Well, you have double http there. It should be enough just to:simon_rb wrote:Am I close? I suspect my file = assert isn't quite right and my the device info.result might need more than just Level..
It runs but get a Nil value as I don't know how to read the Level from the JSON, not sure what the syntax should be lol
Code: Select all
'curl http://192.168.1.26:8080/json.htm?type=devices&rid=265'
Code: Select all
'curl "http://192.168.1.26:8080/json.htm?type=devices&rid=265"'
-
- Posts: 612
- Joined: Wednesday 07 August 2013 19:09
- Target OS: -
- Domoticz version:
- Location: UK
- Contact:
Re: Simple LMS LUA volume dimmer
Yes a guy over at the edomoticz is looking at the on command being sent. However still when not using Siri the volume will got to an On command for some strange reason. If I grab the Level from JSON it won't matter anymore.. 
How the hell did I miss that double http:// Been going over this all day scratching my head and searching google lol. I have just tried this and it crashes Domoticz lol Thats an achievement, never done that before lol
Also tried this and still crashes Domoticz lol

How the hell did I miss that double http:// Been going over this all day scratching my head and searching google lol. I have just tried this and it crashes Domoticz lol Thats an achievement, never done that before lol
Code: Select all
commandArray = {}
json = (loadfile '/home/pi/domoticz/scripts/lua/json.lua')()
file = assert(io.popen('curl http://192.168.1.26:8080/json.htm?type=devices&rid=265'))
raw = file:read('*all')
file:close()
deviceinfo = json:decode(raw)
vlevel = deviceinfo.result["Level"]
if devicechanged['Lounge Touch V'] then
targetvolume = vlevel
if devicechanged['Lounge Touch V'] == 'Off' and otherdevices['Lounge Touch'] ~= 'Off' then
commandArray['Lounge Touch'] = 'Off'
elseif devicechanged['Lounge Touch V'] == 'On' and otherdevices['Lounge Touch'] == 'Off' then
commandArray[#commandArray+1]={['Lounge Touch'] = 'On'}
commandArray[#commandArray+1]={['Lounge Touch'] = 'Set Volume '..targetvolume}
else
commandArray['Lounge Touch'] = 'Set Volume '..targetvolume
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:8080/json.htm?type=devices&rid=265"'))
raw = file:read('*all')
file:close()
deviceinfo = json:decode(raw)
vlevel = deviceinfo.result.Level
if devicechanged['Lounge Touch V'] then
targetvolume = vlevel
if devicechanged['Lounge Touch V'] == 'Off' and otherdevices['Lounge Touch'] ~= 'Off' then
commandArray['Lounge Touch'] = 'Off'
elseif devicechanged['Lounge Touch V'] == 'On' and otherdevices['Lounge Touch'] == 'Off' then
commandArray[#commandArray+1]={['Lounge Touch'] = 'On'}
commandArray[#commandArray+1]={['Lounge Touch'] = 'Set Volume '..targetvolume}
else
commandArray['Lounge Touch'] = 'Set Volume '..targetvolume
end
end
return commandArray
-
- Posts: 722
- Joined: Friday 02 October 2015 12:12
- Target OS: Raspberry Pi / ODroid
- Domoticz version: beta
- Location: Finland
- Contact:
Re: Simple LMS LUA volume dimmer
I think the problem is that the json decoding is triggered now on whatever change happens in your domoticz. You should move this whole bit:simon_rb wrote:Yes a guy over at the edomoticz is looking at the on command being sent. However still when not using Siri the volume will got to an On command for some strange reason. If I grab the Level from JSON it won't matter anymore..
How the hell did I miss that double http:// Been going over this all day scratching my head and searching google lol. I have just tried this and it crashes Domoticz lol Thats an achievement, never done that before lol
Also tried this and still crashes Domoticz lolCode: Select all
commandArray = {} json = (loadfile '/home/pi/domoticz/scripts/lua/json.lua')() file = assert(io.popen('curl http://192.168.1.26:8080/json.htm?type=devices&rid=265')) raw = file:read('*all') file:close() deviceinfo = json:decode(raw) vlevel = deviceinfo.result["Level"] if devicechanged['Lounge Touch V'] then targetvolume = vlevel if devicechanged['Lounge Touch V'] == 'Off' and otherdevices['Lounge Touch'] ~= 'Off' then commandArray['Lounge Touch'] = 'Off' elseif devicechanged['Lounge Touch V'] == 'On' and otherdevices['Lounge Touch'] == 'Off' then commandArray[#commandArray+1]={['Lounge Touch'] = 'On'} commandArray[#commandArray+1]={['Lounge Touch'] = 'Set Volume '..targetvolume} else commandArray['Lounge Touch'] = 'Set Volume '..targetvolume 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:8080/json.htm?type=devices&rid=265"')) raw = file:read('*all') file:close() deviceinfo = json:decode(raw) vlevel = deviceinfo.result.Level if devicechanged['Lounge Touch V'] then targetvolume = vlevel if devicechanged['Lounge Touch V'] == 'Off' and otherdevices['Lounge Touch'] ~= 'Off' then commandArray['Lounge Touch'] = 'Off' elseif devicechanged['Lounge Touch V'] == 'On' and otherdevices['Lounge Touch'] == 'Off' then commandArray[#commandArray+1]={['Lounge Touch'] = 'On'} commandArray[#commandArray+1]={['Lounge Touch'] = 'Set Volume '..targetvolume} else commandArray['Lounge Touch'] = 'Set Volume '..targetvolume end end return commandArray
Code: Select all
json = (loadfile '/home/pi/domoticz/scripts/lua/json.lua')()
file = assert(io.popen('curl "http://192.168.1.26:8080/json.htm?type=devices&rid=265"'))
raw = file:read('*all')
file:close()
deviceinfo = json:decode(raw)
vlevel = deviceinfo.result.Level
-
- Posts: 612
- Joined: Wednesday 07 August 2013 19:09
- Target OS: -
- Domoticz version:
- Location: UK
- Contact:
Re: Simple LMS LUA volume dimmer
Its not crashing! Thanks! So I guess Domoticz was overloading - get it. Prob is I get this now when the player is turned on which actually domoticz comes up with "problem sending command" however it does because the player turns on.
2016-11-06 19:49:11.044 Error: EventSystem: in /home/pi/domoticz/scripts/lua/script_device_sqtouch_volume.lua: ...pi/domoticz/scripts/lua/script_device_sqtouch_volume.lua:23: attempt to concatenate global 'targetvolume' (a nil value)
2016-11-06 19:49:11.044 Error: EventSystem: in /home/pi/domoticz/scripts/lua/script_device_sqtouch_volume.lua: ...pi/domoticz/scripts/lua/script_device_sqtouch_volume.lua:23: attempt to concatenate global 'targetvolume' (a nil value)
-
- Posts: 722
- Joined: Friday 02 October 2015 12:12
- Target OS: Raspberry Pi / ODroid
- Domoticz version: beta
- Location: Finland
- Contact:
Re: Simple LMS LUA volume dimmer
By the way, now's the first time I actually looked the new script. What is it exactly that you are trying to achieve?simon_rb wrote:Its not crashing! Thanks! So I guess Domoticz was overloading - get it. Prob is I get this now when the player is turned on which actually domoticz comes up with "problem sending command" however it does because the player turns on.
2016-11-06 19:49:11.044 Error: EventSystem: in /home/pi/domoticz/scripts/lua/script_device_sqtouch_volume.lua: ...pi/domoticz/scripts/lua/script_device_sqtouch_volume.lua:23: attempt to concatenate global 'targetvolume' (a nil value)


Error itself should be avoided by adding to the conditions that result into using targetvolume: "and targetvolume ~= nil"
-
- Posts: 612
- Joined: Wednesday 07 August 2013 19:09
- Target OS: -
- Domoticz version:
- Location: UK
- Contact:
Re: Simple LMS LUA volume dimmer
Haha, no worries. It only half makes sense to me.
I'm trying to bypass the dimmer trying to send an "On" value to the player and making the volume go to 0%. Instead of comparing it to the svalue which is the same as "Data" or "Status" which can say "On". The "Level" within the JSON will always be a the number the volume is set at. This way it covers all bases. Does that make sense?
I'm trying to bypass the dimmer trying to send an "On" value to the player and making the volume go to 0%. Instead of comparing it to the svalue which is the same as "Data" or "Status" which can say "On". The "Level" within the JSON will always be a the number the volume is set at. This way it covers all bases. Does that make sense?

-
- Posts: 722
- Joined: Friday 02 October 2015 12:12
- Target OS: Raspberry Pi / ODroid
- Domoticz version: beta
- Location: Finland
- Contact:
Re: Simple LMS LUA volume dimmer
But the device script we are talking about does not do anything to "Lounge Touch V" (= the dimmer?). It reacts to any change on "Lounge Touch V" and then either turns the "Lounge Touch" (the player?) Off or On (and sets the volume). Are you sure there isn't any other script that causes the odd behaviour with "Lounge Touch V"? As it shouldn't be this script! Or did you set it as a slave for "Lounge Touch" and forgot about it?simon_rb wrote:Haha, no worries. It only half makes sense to me.
I'm trying to bypass the dimmer trying to send an "On" value to the player and making the volume go to 0%. Instead of comparing it to the svalue which is the same as "Data" or "Status" which can say "On". The "Level" within the JSON will always be a the number the volume is set at. This way it covers all bases. Does that make sense?
-
- Posts: 612
- Joined: Wednesday 07 August 2013 19:09
- Target OS: -
- Domoticz version:
- Location: UK
- Contact:
Re: Simple LMS LUA volume dimmer
I'm sure the device script sends the volume when it changes. So if the Lounge Touch V changes then the script compares the number. So if I increase the dimmer on Lounge Touch V switch then the Lounge Touch V will see its different to the LMS Lounge Touch physical player and change its volume? Is that correct? If it is then for some reason if the switch displays "On" instead of "50%" for example then the script somehow sets the physical LMS Player to 0%.But the device script we are talking about does not do anything to "Lounge Touch V" (= the dimmer?). It reacts to any change on "Lounge Touch V" and then either turns the "Lounge Touch" (the player?) Off or On (and sets the volume)
So instead of comparing the vstatus of Lounge Touch V wee compare it to the JSON file and use the Level which is always the dimmer number.. So even if for some reason it reverts to On then it doesn't matter.
No I don't have anything else interfering with the switch, No slaves or anything.Are you sure there isn't any other script that causes the odd behaviour with "Lounge Touch V"? As it shouldn't be this script! Or did you set it as a slave for "Lounge Touch" and forgot about it?
Cheers

-
- Posts: 612
- Joined: Wednesday 07 August 2013 19:09
- Target OS: -
- Domoticz version:
- Location: UK
- Contact:
Re: Simple LMS LUA volume dimmer
I think the penny has just dropped.. The script just sends the svalue and thats it.. and if its "On" then it sends that which sets the radio.. I was hoping to send the Level rather than svalue.. thats what it comes down to 

-
- Posts: 722
- Joined: Friday 02 October 2015 12:12
- Target OS: Raspberry Pi / ODroid
- Domoticz version: beta
- Location: Finland
- Contact:
Re: Simple LMS LUA volume dimmer
Trust me, if the script is exactly as you have copied it here, then it only checks these conditionssimon_rb wrote: I'm sure the device script sends the volume when it changes. So if the Lounge Touch V changes then the script compares the number. So if I increase the dimmer on Lounge Touch V switch then the Lounge Touch V will see its different to the LMS Lounge Touch physical player and change its volume? Is that correct? If it is then for some reason if the switch displays "On" instead of "50%" for example then the script somehow sets the physical LMS Player to 0%.
Code: Select all
if devicechanged['Lounge Touch V'] == 'Off' and otherdevices['Lounge Touch'] ~= 'Off' then
commandArray['Lounge Touch'] = 'Off'
elseif devicechanged['Lounge Touch V'] == 'On' and otherdevices['Lounge Touch'] == 'Off' then
commandArray[#commandArray+1]={['Lounge Touch'] = 'On'}
commandArray[#commandArray+1]={['Lounge Touch'] = 'Set Volume '..targetvolume}
else
commandArray['Lounge Touch'] = 'Set Volume '..targetvolume
end

-
- Posts: 612
- Joined: Wednesday 07 August 2013 19:09
- Target OS: -
- Domoticz version:
- Location: UK
- Contact:
Re: Simple LMS LUA volume dimmer
Ah I see. I thought it compared - my mistake
Can it not send the Level from the JSON as the targetvolume?
Sent from my iPhone using Tapatalk

Sent from my iPhone using Tapatalk
-
- Posts: 722
- Joined: Friday 02 October 2015 12:12
- Target OS: Raspberry Pi / ODroid
- Domoticz version: beta
- Location: Finland
- Contact:
Re: Simple LMS LUA volume dimmer
Yes!simon_rb wrote:I think the penny has just dropped.. The script just sends the svalue and thats it.. and if its "On" then it sends that which sets the radio.. I was hoping to send the Level rather than svalue.. thats what it comes down to

Althoug, I also observed something else very strange. When using the json to set the level, the scale is offset by one. Setting it it to 0 or 1 turns the switch off (= svalue 0), setting the level to 2 turns it to 1%, setting the level to 100 turns it to 99% and setting the level to 101 turns it to 100%. Not sure how this should be factored into the code.
-
- Posts: 722
- Joined: Friday 02 October 2015 12:12
- Target OS: Raspberry Pi / ODroid
- Domoticz version: beta
- Location: Finland
- Contact:
Re: Simple LMS LUA volume dimmer
Hmm, well yes I guess it should work. You change the dim level, the script is triggered and it check the level and then sets that level to the player. So yes it should work also like this. Maybe you can avoid the problems with sValue "offset" (as mentioned in the previous post) also with this approach...simon_rb wrote:Ah I see. I thought it compared - my mistakeCan it not send the Level from the JSON as the targetvolume?
Sent from my iPhone using Tapatalk
-
- Posts: 612
- Joined: Wednesday 07 August 2013 19:09
- Target OS: -
- Domoticz version:
- Location: UK
- Contact:
Re: Simple LMS LUA volume dimmer
Ah, I noticed this too that the volume was off by 1% but I wasn't too worried about that. I never have it at 100% volume anyways..
Ah, so which dimmer would be best? I obviously turn on the Lounge Touch player using the Lounge Touch V dimmer. Most of the time it reverts back to the previous dimmer or it can display "On". So should I change the dimmer to the 32? Would that stop the "On" problem?
Or would it best to just send the "Level" from the JSON reply. All I need to do is set it from the script above but it's coming up with a Nil, obviously my "vlevel = deviceinfo.result.Level" is wrong.. once it grabs that value then it wouldn't matter if the dimmer displays on for whatever reason as it will send the Level anyways..
Sent from my iPhone using Tapatalk
Ah, so which dimmer would be best? I obviously turn on the Lounge Touch player using the Lounge Touch V dimmer. Most of the time it reverts back to the previous dimmer or it can display "On". So should I change the dimmer to the 32? Would that stop the "On" problem?
Or would it best to just send the "Level" from the JSON reply. All I need to do is set it from the script above but it's coming up with a Nil, obviously my "vlevel = deviceinfo.result.Level" is wrong.. once it grabs that value then it wouldn't matter if the dimmer displays on for whatever reason as it will send the Level anyways..
Sent from my iPhone using Tapatalk
-
- Posts: 722
- Joined: Friday 02 October 2015 12:12
- Target OS: Raspberry Pi / ODroid
- Domoticz version: beta
- Location: Finland
- Contact:
Re: Simple LMS LUA volume dimmer
commandArray['OpenURL'] always gives and error to me as well. If you want to avoid it, you can use os.execute('curl -s "http://url"'). The lua error is result from "targetvolume" not having any value. Addsimon_rb wrote:Its not crashing! Thanks! So I guess Domoticz was overloading - get it. Prob is I get this now when the player is turned on which actually domoticz comes up with "problem sending command" however it does because the player turns on.
2016-11-06 19:49:11.044 Error: EventSystem: in /home/pi/domoticz/scripts/lua/script_device_sqtouch_volume.lua: ...pi/domoticz/scripts/lua/script_device_sqtouch_volume.lua:23: attempt to concatenate global 'targetvolume' (a nil value)
Code: Select all
print(vlevel)
Edit: No it does not read it correctly

Code: Select all
vlevel = deviceinfo.result[1].Level
-
- Posts: 612
- Joined: Wednesday 07 August 2013 19:09
- Target OS: -
- Domoticz version:
- Location: UK
- Contact:
Re: Simple LMS LUA volume dimmer
Cheers, There is a massive delay between moving the slider and it updating the volume.. Sometimes it doesn't update at all. Noticed this in the log, it also crashes Domoticz lol.
I suspect when you change the slider it starts a loop with the JSON and it crashes the Domoticz..
2016-11-06 22:54:20.388 Error: EventSystem: Warning!, lua script /home/pi/domoticz/scripts/lua/script_device_sqtouch_volume.lua has been running for more than 10 seconds

2016-11-06 22:54:20.388 Error: EventSystem: Warning!, lua script /home/pi/domoticz/scripts/lua/script_device_sqtouch_volume.lua has been running for more than 10 seconds
-
- Posts: 722
- Joined: Friday 02 October 2015 12:12
- Target OS: Raspberry Pi / ODroid
- Domoticz version: beta
- Location: Finland
- Contact:
Re: Simple LMS LUA volume dimmer
What are you using to change the dim level? Do you "click" it to another position or move the slider? Maybe moving the slider causes it to go through each step ( = multiple json calls) and thus hangs the system, not sure though. What happens if you just click to certain point in the dim slider and wait Domoticz to finish? How long does it take then and does that create some sort of loop?simon_rb wrote:Cheers, There is a massive delay between moving the slider and it updating the volume.. Sometimes it doesn't update at all. Noticed this in the log, it also crashes Domoticz lol.I suspect when you change the slider it starts a loop with the JSON and it crashes the Domoticz..
2016-11-06 22:54:20.388 Error: EventSystem: Warning!, lua script /home/pi/domoticz/scripts/lua/script_device_sqtouch_volume.lua has been running for more than 10 seconds
You could add a check when the device was last changed and do nothing unless it has been e.g. three seconds since the last change. Maybe it would help.
Who is online
Users browsing this forum: No registered users and 1 guest