Page 1 of 1

Get dimmer level with LUA

Posted: Tuesday 10 November 2015 13:42
by Westcott
How do you GET the level of a dimmer with LUA?

Re: Get dimmer level with LUA

Posted: Tuesday 10 November 2015 22:18
by jvdz
otherdevices_svalues['dimmername'] ?

Jos

Re: Get dimmer level with LUA

Posted: Thursday 23 February 2017 16:18
by sisaenkov
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).

Re: Get dimmer level with LUA

Posted: Saturday 15 July 2017 21:36
by madrian
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).
Hi,

Can you share your solution?

I am trying to do the same, but my LUA script hangs. :evil:

viewtopic.php?f=61&t=18375

Re: Get dimmer level with LUA

Posted: Sunday 16 July 2017 12:56
by sisaenkov
madrian wrote: Can you share your solution?
Here are necessary code blocks:
(The key strings for you contains "uservariables")

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