Get dimmer level with LUA
Posted: Tuesday 10 November 2015 13:42
How do you GET the level of a dimmer with LUA?
Hi,sisaenkov wrote:Hello!
I also want to get dimmer level on LUA from JSON parameter "Level" :.
JSON parameter stores dimmer slider position instead of otherdevices_svalues['dimmername'] that is only shows current percentage when it's turned On.
Now I have to use variables as Level storage. But this is not the best solution (also curl with jq).
Here are necessary code blocks:madrian wrote: Can you share your solution?
Code: Select all
idx = 383
commandArray = {}
function getname(deviceIDX)
for i, v in pairs(otherdevices_idx) do
if v == deviceIDX then
return i
end
end
return 0
end
DomDevice = getname(idx)
if devicechanged[DomDevice] then
if tonumber(otherdevices_svalues[DomDevice]) ~= tonumber(uservariables['Dimmer_' .. idx]:match("(%d+)")) then
if (devicechanged[DomDevice] == 'Off') then
DomValue = 0
print (DomDevice ..": Turn Off")
datasend()
elseif (devicechanged[DomDevice] == 'On') then
print (DomDevice ..": Turn On without level change")
else
DomValue = (otherdevices_svalues[DomDevice]);
print (DomDevice ..": Dimming to " .. (DomValue) .. "%");
datasend()
end
elseif (tonumber(otherdevices_svalues[DomDevice]) ~= tonumber(uservariables['Dimmer_' .. idx]:match(",(%d+)")) and devicechanged[DomDevice] == 'On') then
DomValue = tonumber(uservariables['Dimmer_' .. idx]:match(",(%d+)"))
print (DomDevice ..": Turn On")
datasend()
end
end
return commandArray