Author Topic: Increasing dimmer value by 10% LUA  (Read 318 times)

Offline P-a

  • Jr. Member
  • **
  • Posts: 60
  • Karma: +2/-0
Increasing dimmer value by 10% LUA
« on: May 03, 2018, 03:02:09 am »
Hi,

Looking for simple LUA to increase light Level by 10% on a number of dimmers.

What would the LUA look like?


Best regards,
P-a

Online akbooer

  • Master Member
  • *******
  • Posts: 6158
  • Karma: +276/-69
  • "Less is more"
Re: Increasing dimmer value by 10% LUA
« Reply #1 on: May 03, 2018, 03:16:03 am »
Did you try searching the forum?  Searching for just "ramp" produces lots of relevant stuff.

I found this WakeupRamp a device for ramping up a set of lights slowly

It seems relevant, but I have no idea if it works.
3x Vera Lite-UI5/Edge-UI7, 25x Fibaro, 23x TKB, 9x MiniMote, 2x NorthQ Power, 2x Netatmo, 1x Foscam FI9831P, 9x Philips Hue,
Razberry, MySensors Arduino, HomeWave, AltUI, AltHue, DataYours, Grafana, openLuup, ZWay, ZeroBrane Studio.

Offline a-lurker

  • Hero Member
  • *****
  • Posts: 859
  • Karma: +63/-8
Re: Increasing dimmer value by 10% LUA
« Reply #2 on: May 03, 2018, 03:21:42 am »
Something along these lines as just an example. Put the id of each of your lights into the ID array. I have just assumed four lights. Every time you call  my_lights()  the dim level will change. The light level of  LIGHT_1  is tracked by the other three lights. You can run the code in the Vera Lua test box.

Code: [Select]
local ID = {
    LIGHT_1 = 46,
    LIGHT_2 = 53,
    LIGHT_3 = 92,
    LIGHT_4 = 36
}

local SID = {
    DIMMER_SWITCH = "urn:upnp-org:serviceId:Dimming1"
}

local function setDimmers(dimmers, level)
    for _,v in ipairs(dimmers) do luup.call_action(SID.DIMMER_SWITCH, "SetLoadLevelTarget", {newLoadlevelTarget = level}, v) end
end

local function my_lights()
    local theDimmers = {
        ID.LIGHT_1,
        ID.LIGHT_2,
        ID.LIGHT_3,
        ID.LIGHT_4
    }

    local lightLevel = luup.variable_get(SID.DIMMER_SWITCH, "LoadLevelStatus", ID.LIGHT_1)

    if (lightLevel == "0") then
        setDimmers(theDimmers, 100)
    elseif (lightLevel == "100") then
        setDimmers(theDimmers, 66)
    elseif (lightLevel == "66") then
        setDimmers(theDimmers, 33)
    else
        setDimmers(theDimmers,0)
    end

    return true -- no further processing is required but allow the last run time stamp to be updated
end


my_lights()

return true

Offline P-a

  • Jr. Member
  • **
  • Posts: 60
  • Karma: +2/-0
Re: Increasing dimmer value by 10% LUA
« Reply #3 on: May 03, 2018, 05:19:23 am »
Thanks a-lurker,

I want it dead simple, a straightforward increase/ decrease on a single dimmer. Regardless of what it was set on or what level other lights are on.

Want to create a + and - scene for stepping ligths up n down via scenes

BR