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

LUA help needed (again)


Question

Posted

Hi guys,

I am minimize the number of scenes I have by combining them. See below.

Problems:

1) The switch off of

elseif
      ( Dagdelen == "Bedtijd" ) or ( Dagdelen == "Nacht")

then
    fibaro:call(96, "turnOff");
  debug("green","VerlichtingVlag, uit");


Does not work, is still on after 00.00 hour

2) and why I can not add end to it?

3) How I can add debug after elseif to show wich part is starting?

Remark all GV are created.

Thanks in advance

2 answers to this question

Recommended Posts

  • 0
Posted

@Sjakie,

 

can you post the whole code?

  • 0
  • Inquirer
  • Posted

    sorry hereby

     

    --[[
    %% autostart
    351 value
    %% properties
    %% globals
    Dagdelen
    Stookseizoen
    LocatieGezin
    HuisStatus
    --]]
    function debug(color, message)
         fibaro:debug(string.format('<%s style="color:%s;">%s</%s>', "span", color, message, "span"));
    end

    function traceFibaro(name)
      local orgFun=fibaro[name]
      fibaro[name]=function(f,...)
        local args={...}
        local res={orgFun(f,table.unpack(args))}
        print(string.format("fibaro:%s(%s)%s",name,json.encode(args):sub(2,-2),#res>0 and "="..json.encode(res):sub(2,-2) or ""))
        return table.unpack(res)
      end
    end

    traceFibaro("getValue")
    traceFibaro("getSourceTrigger")
    traceFibaro("getGlobalValue")

    --
    --------------- Use function----------------------------------------------------
    --
    debug("yellow", "Verwarming alle mogelijkheden en Verlichting vlag uit");
    -- Use colours like "white", "orange", "white, "green", "grey", "red", "blue".
    --
    --------------------------------------------------------------------------------
    debug("orange","scene start")


    -----Basis scene van petergebruers ----------------------
    local startSource = fibaro:getSourceTrigger()
    local DeurnaarSerre = 351

    fibaro:debug("Script started because of: " .. startSource["type"])

    Dagdelen     = fibaro:getGlobalValue("Dagdelen")
    Stookseizoen = fibaro:getGlobalValue("Stookseizoen")
    LocatieGezin = fibaro:getGlobalValue("LocatieGezin")
    HuisStatus   = fibaro:getGlobalValue("HuisStatus")

    fibaro:debug("Dagdelen: " .. Dagdelen)
    fibaro:debug("Stookseizoen: " .. Stookseizoen)
    fibaro:debug("LocatieGezin: " .. LocatieGezin)
    fibaro:debug("HuisStatus: " .. HuisStatus)

    --if ( Dagdelen == "Morgen" )
     -- then

    -- fibaro:debug("Nacht scenario zie bedtijd")
     

    --fibaro:debug("yellow", "Verwarming opstaan , verwarming start);
    if
      ( Dagdelen == "Opstaan" )
    -- fibaro:debug("Verwarming Opstaan")
    and
        (Stookseizoen == "Ja" )
    and
       ( tonumber(fibaro:getValue(351, "value")) == 0 )
    and
        (LocatieGezin == "Aanwezig" )
    then
        --aanroepen http request
    local http = net.HTTPClient()

    function call(url)
      http:request(url, {
          options = { method = 'GET' },
          success =function() fibaro:debug(url.." ,done.") end,
          error = function(errorcode) fibaro:debug("error=" .. errorcode) end
        })

    call("http://192.168.1.101/data.json?heater=0&setpoint=167&thermostat=0")
    end
    ------
      -- 279 is the Virtual Device ID
    -- 28 is the Process button ID
    local sid, bid = 249, 28
    -- Create TTS params object
    local params = {
      -- TTS Message
      message = "Hallo en goede morgen, Saartje zet de verwarmingsthermostaat naar thuis 21,7°C",  
      duration = 'auto',    -- Duration: "auto", xx seconds
      language = "nl-nl",    -- Language: fr-FR
      volume = 50            -- Volume
    }
    local _f = fibaro
    local _x ={root="x_sonos_object",load=function(b)local c=_f:getGlobalValue(b.root)if string.len(c)>0 then local d=json.decode(c)if d and type(d)=="table"then return d else _f:debug("Unable to process data, check variable")end else _f:debug("No data found!")end end,set=function(b,e,d)local f=b:load()if f[e]then for g,h in pairs(d)do f[e][g]=h end else f[e]=d end;_f:setGlobal(b.root,json.encode(f))end,get=function(b,e)local f=b:load()if f and type(f)=="table"then for g,h in pairs(f)do if tostring(g)==tostring(e or"")then return h end end end;return nil end}
    -- Make a request to the remote to process params object instantly
    _x:set(tostring(sid), { tts = params })
    _f:call(sid, "pressButton", bid)
    ----
    ----

    elseif ( Dagdelen == "Middag")
      --debug("yellow", "Verwarming middag setting");

      and
    -- ( fibaro:getGlobalValue("Dagdelen") == "Middag" )

        (Stookseizoen == "Ja" )
    and
     
        ( tonumber(fibaro:getValue(351, "value")) == 0 )
    and
          (LocatieGezin == "Aanwezig" )

    then
        --aanroepen http request
    local http = net.HTTPClient()

    function call(url)
      http:request(url, {
          options = { method = 'GET' },
          success =function() fibaro:debug(url.." ,done.") end,
          error = function(errorcode) fibaro:debug("error=" .. errorcode) end
        })

     

    call("http://192.168.1.101/data.json?heater=0&setpoint=169&thermostat=0")

    ------
      -- 279 is the Virtual Device ID
    -- 28 is the Process button ID
    local sid, bid = 249, 28
    -- Create TTS params object
    local params = {
      -- TTS Message
      message = "Hallo, Saartje zet de verwarmingsthermostaat naar 21,9°C",  
      duration = 'auto',    -- Duration: "auto", xx seconds
      language = "nl-nl",    -- Language: fr-FR
      volume = 50            -- Volume
    }
    local _f = fibaro
    local _x ={root="x_sonos_object",load=function(b)local c=_f:getGlobalValue(b.root)if string.len(c)>0 then local d=json.decode(c)if d and type(d)=="table"then return d else _f:debug("Unable to process data, check variable")end else _f:debug("No data found!")end end,set=function(b,e,d)local f=b:load()if f[e]then for g,h in pairs(d)do f[e][g]=h end else f[e]=d end;_f:setGlobal(b.root,json.encode(f))end,get=function(b,e)local f=b:load()if f and type(f)=="table"then for g,h in pairs(f)do if tostring(g)==tostring(e or"")then return h end end end;return nil end}
    -- Make a request to the remote to process params object instantly
    _x:set(tostring(sid), { tts = params })
    _f:call(sid, "pressButton", bid)
    ----
    ------

    end

    elseif ( Dagdelen == "Avond" )
    --debug("yellow", "Verwarming avond instelling");
      -- fibaro:debug("orange","scene start, Verwarming op nachtstand als deur eetkamer naar serre is geopend")
    and
        (Stookseizoen == "Ja" )
    and
         (LocatieGezin == "Aanwezig" )  
    and
         ( tonumber(fibaro:getValue(351, "value")) == 0 )

    then
            --aanroepen http request
    local http = net.HTTPClient()

    function call(url)
      http:request(url, {
          options = { method = 'GET' },
          success =function() fibaro:debug(url.." ,done.") end,
          error = function(errorcode) fibaro:debug("error=" .. errorcode) end
        })

     

    call("http://192.168.1.101/data.json?heater=0&setpoint=171&thermostat=0")

    ------
      -- 279 is the Virtual Device ID
    -- 28 is the Process button ID
    local sid, bid = 249, 28
    -- Create TTS params object
    local params = {
      -- TTS Message
      message = "Hallo, Saartje zet de verwarmingsthermostaat naar comfort avond 22,1 °C",  
      duration = 'auto',    -- Duration: "auto", xx seconds
      language = "nl-nl",    -- Language: fr-FR
      volume = 50            -- Volume
    }
    local _f = fibaro
    local _x ={root="x_sonos_object",load=function(b)local c=_f:getGlobalValue(b.root)if string.len(c)>0 then local d=json.decode(c)if d and type(d)=="table"then return d else _f:debug("Unable to process data, check variable")end else _f:debug("No data found!")end end,set=function(b,e,d)local f=b:load()if f[e]then for g,h in pairs(d)do f[e][g]=h end else f[e]=d end;_f:setGlobal(b.root,json.encode(f))end,get=function(b,e)local f=b:load()if f and type(f)=="table"then for g,h in pairs(f)do if tostring(g)==tostring(e or"")then return h end end end;return nil end}
    -- Make a request to the remote to process params object instantly
    _x:set(tostring(sid), { tts = params })
    _f:call(sid, "pressButton", bid)
    ----
    end
     
     
    elseif
         ( Dagdelen == "Avond" )
    and
    --debug("yellow", "Kliko aankondiging");  
     
     (currentDate.wday == 4)

    then
    ------
      -- 279 is the Virtual Device ID
    -- 28 is the Process button ID
    local sid, bid = 249, 28
    -- Create TTS params object
    local params = {
      -- TTS Message
      message = "Hallo, Saartje zegt let op er moet een kliko buiten gezet worden",  
      duration = 'auto',    -- Duration: "auto", xx seconds
      language = "nl-nl",    -- Language: fr-FR
      volume = 50            -- Volume
    }
    local _f = fibaro
    local _x ={root="x_sonos_object",load=function(b)local c=_f:getGlobalValue(b.root)if string.len(c)>0 then local d=json.decode(c)if d and type(d)=="table"then return d else _f:debug("Unable to process data, check variable")end else _f:debug("No data found!")end end,set=function(b,e,d)local f=b:load()if f[e]then for g,h in pairs(d)do f[e][g]=h end else f[e]=d end;_f:setGlobal(b.root,json.encode(f))end,get=function(b,e)local f=b:load()if f and type(f)=="table"then for g,h in pairs(f)do if tostring(g)==tostring(e or"")then return h end end end;return nil end}
    -- Make a request to the remote to process params object instantly
    _x:set(tostring(sid), { tts = params })
    _f:call(sid, "pressButton", bid)
    ----
    ------
    --end

    elseif
          ( Dagdelen == "Bedtijd" )
    --  debug("yellow", "Verwarming nacht instelling ")
    --    or
     --   (fibaro:getGlobalValue("Dagdelen") == "Nacht" )
    --     or
    --    (fibaro:getGlobalValue("Dagdelen") == "Morgen" )
    and
        (Stookseizoen == "Ja" )
    and
         (LocatieGezin == "Aanwezig" )
    then
     
     
        --aanroepen http request
    local http = net.HTTPClient()

    function call(url)
      http:request(url, {
          options = { method = 'GET' },
          success =function() fibaro:debug(url.." ,done.") end,
          error = function(errorcode) fibaro:debug("error=" .. errorcode) end
        })

     

    call("http://192.168.1.101/data.json?heater=0&setpoint=115&thermostat=0")
    --
      -- 279 is the Virtual Device ID
    -- 28 is the Process button ID
    local sid, bid = 249, 28
    -- Create TTS params object
    local params = {
      -- TTS Message
      message = "Hallo, Saartje zet de verwarmingsthermostaat naar slaapstand 16,5°C en wenst jullie een goede nacht",  
      duration = 'auto',    -- Duration: "auto", xx seconds
      language = "nl-nl",    -- Language: fr-FR
      volume = 50            -- Volume
    }
    local _f = fibaro
    local _x ={root="x_sonos_object",load=function(b)local c=_f:getGlobalValue(b.root)if string.len(c)>0 then local d=json.decode(c)if d and type(d)=="table"then return d else _f:debug("Unable to process data, check variable")end else _f:debug("No data found!")end end,set=function(b,e,d)local f=b:load()if f[e]then for g,h in pairs(d)do f[e][g]=h end else f[e]=d end;_f:setGlobal(b.root,json.encode(f))end,get=function(b,e)local f=b:load()if f and type(f)=="table"then for g,h in pairs(f)do if tostring(g)==tostring(e or"")then return h end end end;return nil end}
    -- Make a request to the remote to process params object instantly
    _x:set(tostring(sid), { tts = params })
    _f:call(sid, "pressButton", bid)
    ------
    end
     
     
     
     


    elseif
          ( Dagdelen == "Bedtijd" ) or ( Dagdelen == "Nacht")

    then
        fibaro:call(96, "turnOff");
      debug("green","VerlichtingVlag, uit");

    -----------------
     
    -- end

    elseif  
           (HuisStatus == "Arm" )
    and
           (Stookseizoen == "Ja" )
    and
            (LocatieGezin == "KortAfwezig" )

    then
        --aanroepen http request
    local http = net.HTTPClient()

    function call(url)
      http:request(url, {
          options = { method = 'GET' },
          success =function() fibaro:debug(url.." ,done.") end,
          error = function(errorcode) fibaro:debug("error=" .. errorcode) end
        })

     

    call("http://192.168.1.101/data.json?heater=0&setpoint=150&thermostat=0")
    ------
    end
     
    elseif
          (HuisStatus == "Arm" )
    and
          (Stookseizoen == "Ja" )
    and
           (LocatieGezin == "Vakantie" )

    then
            --aanroepen http request
    local http = net.HTTPClient()

    function call(url)
      http:request(url, {
          options = { method = 'GET' },
          success =function() fibaro:debug(url.." ,done.") end,
          error = function(errorcode) fibaro:debug("error=" .. errorcode) end
        })

     

    call("http://192.168.1.101/data.json?heater=0&setpoint=20&thermostat=0")
    end
    -----------------

    else

     fibaro:debug ("No idea if I am doing it right? Dagdelen == "..
       Dagdelen)
    end
    debug("orange","scene beeindigt")

    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...