Page 2 of 6
Re: Simple LMS LUA volume dimmer
Posted: Thursday 03 November 2016 10:47
by simon_rb
Thanks mate but unfortunately that completely breaks it all haha!
Whats happening is its sending an on command every 10 seconds and when the volume dimmer sends an on command it sets the radios to 0% as I don't think it understands 'On'. Don't know why its doing this... Any ideas? Both the LMS Lounge switch and dimmer/volume switch keep saying 'On even when something is playing.. But can't hear anything as volume keeps going to 0%. The log on both say 'On' every 10 secs. Obviously a loop somewhere.. And I can't turn them off, soon as your turn either switch off they turn back on.. Whoops..
Any ideas on that? Cheers
Update:- I lied, the LMS switch log says normal playing (nothing about on or off) The Dimmer/Volume is turned on every second.
Re: Simple LMS LUA volume dimmer
Posted: Thursday 03 November 2016 12:00
by simon_rb
Coming back to another issue is with HomeKit itself.. If I say set Kitchen Radio to 50% It always sends an On command followed for the 50% which works fine on the Kitchen Radio, log shows a 2 sec delay between the commands. When I say the same for the bedroom radio it sends the commands at the same time and even though the log shows the 50% as send second on the log the switch stays with the On value and the radio volume goes to 0%. Don't know what can be done to get around this.. I'll ask more in the specific HomeKit forum but thought I'd ask just incase

Re: Simple LMS LUA volume dimmer
Posted: Thursday 03 November 2016 22:51
by Nautilus
simon_rb wrote:Thanks mate but unfortunately that completely breaks it all haha!
Whats happening is its sending an on command every 10 seconds and when the volume dimmer sends an on command it sets the radios to 0% as I don't think it understands 'On'. Don't know why its doing this... Any ideas? Both the LMS Lounge switch and dimmer/volume switch keep saying 'On even when something is playing.. But can't hear anything as volume keeps going to 0%. The log on both say 'On' every 10 secs. Obviously a loop somewhere.. And I can't turn them off, soon as your turn either switch off they turn back on.. Whoops..
Any ideas on that? Cheers
Update:- I lied, the LMS switch log says normal playing (nothing about on or off) The Dimmer/Volume is turned on every second.
Hmm, so it thinks that the first condition is true whenever something changes, I guess? You could try changing it from:
Code: Select all
devicechanged['Lounge Touch'] ~= 'Off' and devicechanged['Lounge Touch'] ~= 'Disconnected' then
to
Code: Select all
devicechanged['Lounge Touch'] ~= 'Off' and devicechanged['Lounge Touch'] ~= 'Disconnected' and devicechanged['Lounge Touch'] ~= nil then
Anyhow, I'd implement something more robust to keep track of when the player is in state which requires the volume dimmer to be on and vice versa. Like the uservariable thing I mentioned earlier about.
When the volume dimmer switch is turned on, it always sets volume to 0, even if you manually set it first to something else? That's something else to think about then but maybe try to get this "On" loop first sorted...

Re: Simple LMS LUA volume dimmer
Posted: Friday 04 November 2016 1:11
by simon_rb
Hi mate,
Changing the script to the above turns the LMS player On/Off/On/Off in a loop..
Banging my head against a brick wall with this one. Well beyond my limited skills.
Cheers
Code: Select all
commandArray = {}
if devicechanged['Lounge Touch'] ~= 'Off' and devicechanged['Lounge Touch'] ~= 'Disconnected' and devicechanged['Lounge Touch'] ~= nil then
commandArray['Lounge Touch V'] = 'On'
elseif devicechanged['Lounge Touch'] == 'Off' or devicechanged['Lounge Touch'] == 'Disconnected' then
commandArray['Lounge Touch V'] = 'Off'
end
return commandArray
Re: Simple LMS LUA volume dimmer
Posted: Friday 04 November 2016 1:21
by simon_rb
Got it half working with the above. Only probs is it updates every couple of seconds.. So the log on the volume/dimmer is On On On On On every couple of seconds or Off Off Off Off.
What Im trying to do is turn the radios on and off from the dimmer volume and then if I turn the player on via iPeng or locally for example it reflects this in the Volume/Dimmer. Then I can not even look at the LMS switch within Domoticz..
Re: Simple LMS LUA volume dimmer
Posted: Friday 04 November 2016 1:29
by simon_rb
Could we modify this to also set the dimmer/volume switch (Lounge Touch V) to on and off from the json file therefore completely by passing the LMS switch completely?
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
Re: Simple LMS LUA volume dimmer
Posted: Friday 04 November 2016 10:29
by Nautilus
simon_rb wrote:Got it half working with the above. Only probs is it updates every couple of seconds.. So the log on the volume/dimmer is On On On On On every couple of seconds or Off Off Off Off.
What Im trying to do is turn the radios on and off from the dimmer volume and then if I turn the player on via iPeng or locally for example it reflects this in the Volume/Dimmer. Then I can not even look at the LMS switch within Domoticz..
Hmm, does not make sense why it goes like that. Probably a long shot but have you confirmed this you've set this up as "device" script, not "All" (provided you use the internal script editor? If you store the scripts to /home/pi/domoticz/scripts/lua you need to make sure the naming convention is followed ("device" in the script name).
These are only things I can think of to explain the behavior. But yeah, stop the behavior you can add another condition:
Code: Select all
commandArray = {}
if devicechanged['Lounge Touch'] ~= 'Off' and devicechanged['Lounge Touch'] ~= 'Disconnected' and devicechanged['Lounge Touch'] ~= nil then
if otherdevices['Lounge Touch V'] == 'Off' then
commandArray['Lounge Touch V'] = 'On'
end
elseif devicechanged['Lounge Touch'] == 'Off' or devicechanged['Lounge Touch'] == 'Disconnected' then
if otherdevices['Lounge Touch V'] == 'On' then
commandArray['Lounge Touch V'] = 'Off'
end
end
return commandArray
And now that I think of it, you can probably use also the "positive" condition in the first half (the song name will not be in the status, only on the sValue so it can really be only either "On", "Playing" or "Stopped" when player is on):
Code: Select all
commandArray = {}
if devicechanged['Lounge Touch'] == 'On' or devicechanged['Lounge Touch'] == Playing' then
if otherdevices['Lounge Touch V'] == 'Off' then
commandArray['Lounge Touch V'] = 'On'
end
elseif devicechanged['Lounge Touch'] == 'Off' or devicechanged['Lounge Touch'] == 'Disconnected' then
if otherdevices['Lounge Touch V'] == 'On' then
commandArray['Lounge Touch V'] = 'Off'
end
end
return commandArray
Re: Simple LMS LUA volume dimmer
Posted: Friday 04 November 2016 10:33
by Nautilus
simon_rb wrote:Could we modify this to also set the dimmer/volume switch (Lounge Touch V) to on and off from the json file therefore completely by passing the LMS switch completely?
Sure, if I understand correctly, you'd just add
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
commandArray['Lounge Touch V'] = 'On'
end
if tonumber(powerstatus) == 0 then
commandArray['Lounge Touch V'] = 'Off'
end
return commandArray
Note that this will react only once a minute when it fetches the json.
Simple LMS LUA volume dimmer
Posted: Friday 04 November 2016 10:54
by simon_rb
Cheers mate I shall take a look! Appreciate all your patience. I am learning too so thanks again buddy.
And the script was setup as a device script.
Re: Simple LMS LUA volume dimmer
Posted: Friday 04 November 2016 11:59
by simon_rb
All I ideally want to do is have the one dimmer switch turn on and off the corresponding radio and the dimmer change the volume. The button also has feedback from the players so if the volume is changed on the player or player is turned on locally then thats reflected.
I'm getting lost in it all now lol.
Still testing and finding odd consistencies. Will post back when Ive had a proper test. Cheers bud
Edit:-
Working at the mo, although when the Lounge Touch V turns on its always 'On' first off which sets the volume to 0%. Is there a way of it ignoring the 'On' when updating the volume for the dimmer? So if its on it ignores it?
Re: Simple LMS LUA volume dimmer
Posted: Friday 04 November 2016 20:45
by Nautilus
You can experiment the the other option to change the sValue state with json, the syntax is:
'
http://127.0.0.1:8080//json.htm?type=co ... ='..volume
with nvalue=0 it will switch off.
Re: Simple LMS LUA volume dimmer
Posted: Friday 04 November 2016 22:21
by simon_rb
Eh? LOL
Its working with the script below and set the Lounge Touch V switch to turn on the radio directly when turning on.. Only thing I'd like to do is to get the script to ignore the 'On' when comparing the volume number because if it detects its 'On' with no value the radio volume goes to zero. Or if you set volume via Siri sometimes the Lounge Touch V goes to 'On' rather than a '%' so then again the volume goes to zero. Is there a way to do that? If there is then the script below is perfect and I can leave you in peace and move on to another project

So if the Lounge Touch V = On then update value from the radio so then it goes back to being a '%'. It seems to be if it detects 'On' it tries to send that to the radio.. Does that make sense? The script is running every minute which is fine for me..
Cheers Dude
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
commandArray['Lounge Touch V'] = 'On'
end
if tonumber(powerstatus) == 0 then
commandArray['Lounge Touch V'] = 'Off'
end
return commandArray
Re: Simple LMS LUA volume dimmer
Posted: Friday 04 November 2016 22:49
by Nautilus
simon_rb wrote:
Its working with the script below and set the Lounge Touch V switch to turn on the radio directly when turning on.. Only thing I'd like to do is to get the script to ignore the 'On' when comparing the volume number because if it detects its 'On' with no value the radio volume goes to zero. Or if you set volume via Siri sometimes the Lounge Touch V goes to 'On' rather than a '%' so then again the volume goes to zero. Is there a way to do that? If there is then the script below is perfect and I can leave you in peace and move on to another project

So if the Lounge Touch V = On then update value from the radio so then it goes back to being a '%'. It seems to be if it detects 'On' it tries to send that to the radio.. Does that make sense? The script is running every minute which is fine for me..
Yes, maybe I'm a bit lost as well on what do we actually have there now - as far as it comes to the scripts - and thus why the behavior is as you describe
I also do not understand why I saw fit to add that extra 'On' command there, the json above it should be enough. Maybe the optimal way would be (only the on / playing part here):
Code: Select all
if tonumber(powerstatus) == 1 then
if 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
elseif otherdevices['Lounge Touch V'] == 'On' and tonumber(volume) ~= tonumber(switchVolume) then
commandArray['OpenURL'] = 'http://127.0.0.1:8080/json.htm?type=command¶m=switchlight&idx=265&switchcmd=Set%20Level&level='..volume
end
end
This should only be triggered when a) Lounge Touch V is Off but player is On and b) when Lounge Touch V is On (and player is On), but player volume is detected to be different than dim level on Lounge Touch V.
So what are the scripts that you have for this whole setup now, this and...?

Re: Simple LMS LUA volume dimmer
Posted: Friday 04 November 2016 22:59
by simon_rb
Brilliant, I am away from my house for a couple of hours lol. So turning on Lounge Touch V dimmer switch turns player on by sending when 'On Command'
http://192.168.1.26:9000/status.html?p0 ... 2.168.1.93
Then turning the Lounge Touch V off it turns the player off (using one of the scripts below). It all appears to be working fine other than when the dimmer says On instead of % it makes the volume go to 0 on the player
Hope thats made it clear
The two scripts are:-
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
commandArray['Lounge Touch V'] = 'On'
end
if tonumber(powerstatus) == 0 then
commandArray['Lounge Touch V'] = 'Off'
end
return commandArray
&
Code: Select all
commandArray = {}
DomDevice = 'Lounge Touch V';
if devicechanged[DomDevice] then
if(devicechanged[DomDevice]=='Off') then
commandArray['Lounge Touch']='Off';
else
commandArray['Lounge Touch']='On';
DomValue = otherdevices_svalues[DomDevice];
CalcValue = (DomValue);
commandArray['Lounge Touch']='Set Volume '..CalcValue;
end
end
return commandArray
Re: Simple LMS LUA volume dimmer
Posted: Friday 04 November 2016 23:41
by Nautilus
Ok, I guess I'd try something like this to avoid the unnecessary 'On' commands:
Code: Select all
if devicechanged['Lounge Touch V'] then
targetvolume = otherdevices_svalues['Lounge Touch V']
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
With the way you have it now, any change in the "volume dimmer" other than "Off" will trigger both "On" and "Set Volume XXX" commands. And when they are to same device, I think only the second is executed anyway (or the first, not sure

) The above method will execute both. Although, if this part was working then maybe just leave it as it was. Anyhow, if player already is in some other state than "Off", then no need to send any additional "On"...
Re: Simple LMS LUA volume dimmer
Posted: Saturday 05 November 2016 1:09
by simon_rb
I'm getting confused with what scripts I'm changing now haha. Also sometimes you can't help the dimmer switch from saying 'On'. Is there a way for the script to realise its On and not %, maybe like if its a string then updated Lounge Touch V from the player to get the % back.. Or is that not an possible?
So what will my two scripts look like now? As you know I have a device one and a time one.. confused what should be in each now lol
I was trying to move away from the LMS (Lounge Touch) as a reference for power by using the power state from the json file. Does any of this make sense now because it doesn't to me lol

Re: Simple LMS LUA volume dimmer
Posted: Saturday 05 November 2016 16:27
by simon_rb
Getting a headache now LOL.
For some reason the scripts above are now updating the switch even when its off so every minute it gets sent an OFF command even though its off. Don't know whats changed since last night.. Damn this thing lol!
Re: Simple LMS LUA volume dimmer
Posted: Saturday 05 November 2016 23:01
by Nautilus
Well, the previous would be the device script controlling the state of the actual player switch. Something like this should work:
1. Device script
Code: Select all
commandArray = {}
if devicechanged['Lounge Touch V'] then
targetvolume = otherdevices_svalues['Lounge Touch V']
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
2. Time script:
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
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 to admit it is quite hard to follow what is going on there at your end

I think you need to invest a bit more on debugging and for example add print commands if you are unsure what part of the script is causing which action. I think though that you should pretty much have all the pieces together now to make this work. Just need to remember that the system is always doing what you are telling it to do, no more, no less. Even if some behavior in unexpected it is just result from thinking some part a bit wrong and then making the necessary corrections...

Re: Simple LMS LUA volume dimmer
Posted: Sunday 06 November 2016 0:31
by simon_rb
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!

Re: Simple LMS LUA volume dimmer
Posted: Sunday 06 November 2016 2:45
by simon_rb
I may have thought of a way around it.. Instead of getting the "Data" or "Status" from the JSON could we not grab the "Level" instead? As you can see the Data says "On" and the level is still showing 19... If we can grab the level rather than the Data from the JSON then we are completely sorted!
Code: Select all
{
"ActTime" : 1478396660,
"ServerTime" : "2016-11-06 01:44:20",
"Sunrise" : "07:07",
"Sunset" : "16:23",
"result" : [
{
"AddjMulti" : 1.0,
"AddjMulti2" : 1.0,
"AddjValue" : 0.0,
"AddjValue2" : 0.0,
"BatteryLevel" : 255,
"CustomImage" : 0,
"Data" : "On",
"Description" : "",
"Favorite" : 0,
"HardwareID" : 3,
"HardwareName" : "Dummy",
"HardwareType" : "Dummy (Does nothing, use for virtual switches only)",
"HardwareTypeVal" : 15,
"HaveDimmer" : true,
"HaveGroupCmd" : true,
"HaveTimeout" : false,
"ID" : "00014158",
"Image" : "Light",
"IsSubDevice" : false,
"LastUpdate" : "2016-11-06 01:44:16",
"Level" : 19,
"LevelInt" : 19,
"MaxDimLevel" : 100,
"Name" : "Lounge Touch V",
"Notifications" : "false",
"PlanID" : "4",
"PlanIDs" : [ 4 ],
"Protected" : false,
"ShowNotifications" : true,
"SignalLevel" : "-",
"Status" : "On",
"StrParam1" : "aHR0cDovLzE5Mi4xNjguMS4yNjo5MDAwL3N0YXR1cy5odG1sP3AwPWJ1dHRvbiZwMT1wb3dlcl9vbiZwbGF5ZXI9MTkyLjE2OC4xLjkz",
"StrParam2" : "",
"SubType" : "Switch",
"SwitchType" : "Dimmer",
"SwitchTypeVal" : 7,
"Timers" : "false",
"Type" : "Light/Switch",
"TypeImg" : "dimmer",
"Unit" : 1,
"Used" : 1,
"UsedByCamera" : false,
"XOffset" : "0",
"YOffset" : "0",
"idx" : "265"
}
],
"status" : "OK",
"title" : "Devices"
}