Jump to content

Welcome to Smart Home Forum by FIBARO

Dear Guest,

 

as you can notice parts of Smart Home Forum by FIBARO is not available for you. You have to register in order to view all content and post in our community. Don't worry! Registration is a simple free process that requires minimal information for you to sign up. Become a part of of Smart Home Forum by FIBARO by creating an account.

 

As a member you can:

  •     Start new topics and reply to others
  •     Follow topics and users to get email updates
  •     Get your own profile page and make new friends
  •     Send personal messages
  •     ... and learn a lot about our system!

 

Regards,

Smart Home Forum by FIBARO Team


  • 0

need help with lua scene light off


Question

Posted

please help me with this scene:

the scene not started automatic after light on in the bathroom.

 

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

local jT = json.decode(fibaro:getGlobalValue("jTable"))

local trigger = fibaro:getSourceTrigger();
if(trigger['type'] == 'global')then

if(fibaro:getValue(jT.bathroom.light, "value") == "1")then
      if(fibaro:getValue(jT.bathroom.sens, "value") == "0")then
      fibaro:sleep(2 * 60 * 1000)
      fibaro:call(jT.bathroom.light, "turnOff")
      end 
end
end

9 answers to this question

Recommended Posts

  • 1
Posted (edited)

@Anatolyy86right... missing trigger...

 

do not mixed with %% autostart concept, %% autostart means this scene starts whenever your HC is started.. this includes reboot, so consider not every scene needs autostart

 

Your case is you need to add your device ID to be monitored by this scene under %% properties.. even you have json table you still need an id for example.

 

%% properties

123 value -- Your jT.bathroom.light

%% event

%% globals

 

scene starts when the "value" of device ID "123" changes.

 

And your scene logic... just wonder, what if 2 * 60 * 1000 has passed, then jT.bathroom.sens becomes 1? your scene will still turn off light. If it is fine, then great :)

Edited by Sirhideo
  • 0
Posted
On 5/10/2018 at 11:41 AM, Anatolyy86 said:

please help me with this scene:

the scene not started automatic after light on in the bathroom.

 

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

local jT = json.decode(fibaro:getGlobalValue("jTable"))

local trigger = fibaro:getSourceTrigger();
if(trigger['type'] == 'global')then

if(fibaro:getValue(jT.bathroom.light, "value") == "1")then
      if(fibaro:getValue(jT.bathroom.sens, "value") == "0")then
      fibaro:sleep(2 * 60 * 1000)
      fibaro:call(jT.bathroom.light, "turnOff")
      end 
end
end

1

 

my guess

 

Please login or register to see this code.

 

  • 0
  • Inquirer
  • Posted
    11 hours ago, 10der said:

     

    my guess

     

    Please login or register to see this code.

     

    It's same to my script? What different?

    • 0
    Posted (edited)

     

     

    Please login or register to see this code.

    Edited by 10der
    • 0
    Posted (edited)
    32 minutes ago, Sirhideo said:

    scene starts when the "value" of device ID "123" changes.

     

    as I can understand he trying to handle not property value - changing a global value...

    but maybe I am wrong

    Edited by 10der
    • 0
    Posted

    @10der yeah, original poster needsto clarify why trigger type = global where if statment is on a device value...

    • 0
    Posted
    Just now, Sirhideo said:

    @10der yeah, original poster needsto clarify why trigger type = global where if statment is on a device value...

    yep!

    crazy,

    but fact. what he asks - I am trying to help him

    • 0
    Posted

    @10der me too trying to help, but my guess is different, let see who gets the jackpot! :)

    • Thanks 1
    • 0
  • Inquirer
  • Posted

    thanks to all friends is help me.

     

    this my code the work fine:

     

    --[[
    %% autostart
    %% properties
    22 value
    64 value
    %% events
    %% globals
    --]]

    if (fibaro:countScenes() > 2) then
      fibaro:abort();
    end

    local jT = json.decode(fibaro:getGlobalValue("jTable"));
     

    local startSource = fibaro:getSourceTrigger();
    if(startSource["type"] == "other") then
        fibaro:call(jT.bathroom.light, "turnOff");
     else    
      if((tonumber(fibaro:getValue(jT.bathroom.light, "value")) == 1) and 
        (tonumber(fibaro:getValue(jT.bathroom.sens, "value")) == 0))  then
          
        local delayVar0 = false; 
      if((tonumber(fibaro:getValue(jT.bathroom.light, "value")) == 1)) then
        delayVar0 = true;
      end
        
        setTimeout(function()
            local delayVar1 = false;
            local sensVar1, sensTime1 = fibaro:get(jT.bathroom.sens, "value");
        if ((tonumber(fibaro:getValue(jT.bathroom.sens, "value")) == 0) and 
              (os.time() - sensTime1) >= 90) then
              delayVar1 = true;
        end
             
    local startSource = fibaro:getSourceTrigger();
    if(
      (delayVar0 == true and delayVar1 == true) 
    or
    startSource["type"] == "other"
       ) then
            fibaro:call(jT.bathroom.light, "turnOff");
    end
        end, 2*60*1000)
      end
    end
        
       

    Join the conversation

    You can post now and register later. If you have an account, sign in now to post with your account.

    Guest
    Answer this question...

    ×   Pasted as rich text.   Paste as plain text instead

      Only 75 emoji are allowed.

    ×   Your link has been automatically embedded.   Display as a link instead

    ×   Your previous content has been restored.   Clear editor

    ×   You cannot paste images directly. Upload or insert images from URL.

    ×
    ×
    • Create New...