Get dimmer level with LUA

Moderator: leecollings

Post Reply
User avatar
Westcott
Posts: 423
Joined: Tuesday 09 December 2014 17:04
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: UK - Glos
Contact:

Get dimmer level with LUA

Post by Westcott »

How do you GET the level of a dimmer with LUA?
Zwave - Sigma Z+ stick, Fibaro, Horstmann, Neo Coolcam, EUROtronic
RFlink - IR detectors and temperatures
Wifi - YeeLights, ESP32s, Anoop sockets
Zigbee - lots with zigbee2mqtt and ZbBridge
User avatar
jvdz
Posts: 2333
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: Get dimmer level with LUA

Post by jvdz »

otherdevices_svalues['dimmername'] ?

Jos
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
User avatar
sisaenkov
Posts: 50
Joined: Friday 27 May 2016 7:21
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.8
Location: Moscow, Russia
Contact:

Re: Get dimmer level with LUA

Post 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).
madrian
Posts: 231
Joined: Saturday 27 August 2016 1:18
Target OS: -
Domoticz version:
Contact:

Re: Get dimmer level with LUA

Post 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
User avatar
sisaenkov
Posts: 50
Joined: Friday 27 May 2016 7:21
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.8
Location: Moscow, Russia
Contact:

Re: Get dimmer level with LUA

Post 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
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest