Jump to content
Guides for the Forum Read more... ×
Poradniki na Forum Read more... ×
  • 0
jasonway

LUA script to turn off all downstairs lights

Question

Hi, I currently use the script (Scene) below to turn off all lights when going to sleep. The problem is sometimes my adult children are still awake upstairs. How would I modify scene to turn off only downstairs lights?

 

HC2 - Running latest version

 

I thought of using the description field in devices and evaluating but can't work out the code. Help!

 

--[[
%% properties
%% events
%% globals
--]]
local ids = fibaro:getDevicesId(
  {
    interfaces = {
      "light",
    },
    properties = {
      dead = false,  
    },
    enabled = true,
    visible = true, -- optional
    --userDescription ~= "", -- attempt to evaluate if user description in device is not nil.
  }
);
    
-- loop through light ids
for i, id in ipairs(ids) do
    fibaro:debug("Turning off " .. fibaro:getName(id));
    -- turn light off
    fibaro:call(id, "turnOff");
end

 

Thanks

Jason

 

Share this post


Link to post
Share on other sites

4 answers to this question

Recommended Posts

  • 0

The topic has been moved from "

Please login or register to see this link.

" to "

Please login or register to see this link.

".

 

Temat został przeniesiony z "

Please login or register to see this link.

" do "

Please login or register to see this link.

".

Share this post


Link to post
Share on other sites
  • 0

Jason, you can try the code below, should work (not at home so cannot test right now).

Please login or register to see this code.

There is a thread describing in detail how to use these functions getDevicesIds and callGroupAction (especially the contributions from @petergebruers:-) ). Confused me as well...

 

 

Best, Rene.

Share this post


Link to post
Share on other sites
  • 0
  • Inquirer
  • Hi and Thanks Rene, I tried what you suggested and at first it didn't work but using the discussion you pointed me to I was able to get it functioning as desired. Thanks Again.

     

    Jason

     

    --[[
    %% properties
    %% events
    %% globals
    --]]

    local data =
    {
       args = { 1 },
       filters =
       {
          {
             filter = "deviceID",
             value = { 454, 45, 452, 51, 466, 471, 113, 26, 459, 482, 294, 302, 7, 386, 131, 86, 55, 112 }
          }
       }
    }

    local devices = fibaro:callGroupAction("turnOff", data)

    print(json.encode(devices))
    -- 454 --Family
    -- 45 --Lounge
    -- 452 --Lounge Lamp
    -- 51 --Meals
    -- 466 --Kitchen
    -- 471 --Kitchen LED
    -- 113 --Laundry
    -- 26 --Hall
    -- 459 --Entry
    -- 482 --Master Bedroom
    -- 294 --Ensuite LED
    -- 302 --Ensuite Exhaust
    -- 7 --Gamnes
    -- 386 --Stairs
    -- 131 --Air Compressor
    -- 86 --FrontYard
    -- 55 --Patio
    -- 112 --SideYard

    Share this post


    Link to post
    Share on other sites

    Create an account or sign in to comment

    You need to be a member in order to leave a comment

    Create an account

    Sign up for a new account in our community. It's easy!

    Register a new account

    Sign in

    Already have an account? Sign in here.

    Sign In Now

    ×