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 HC2->HC3 migrations doubts


Question

Posted

Hi,


I am trying to gradually migrate my scenes in LUA HC2 to LUA HC3 and I am having some doubts/problems:

 

How I can make a scene that always is running, for example, this infinity loop that checks if the door is open:

HC2:

if (fibaro:countScenes() > 2) then
  fibaro:abort()
  fibaro:debug ('There is a other scene running')
end
local startSource = fibaro:getSourceTrigger();
while true do
--Check door open
  if
      ( tonumber(fibaro:getValue(125, "value")) > 0 )
  then
      fibaro:call(234), "sendPush", "Door open");
  end
   fibaro:sleep(15*60000) --repeat each 15 minutes
end

 

HC3 (propose with errors):

Condition:

{
    conditions = {
      {
        type = "se-start",
        property = "start",
        operator = "==",
        value = true,
        isTrigger = true
      }
    },
    operator = "all",
}

 

Action:

while true do
   --Check door open
   if
      ( tonumber(fibaro:get(125, "value")) > 0 )
  then
       fibaro.alert('push', {[1] = 234, }, 'Door open')
  end
  fibaro:sleep(15*60000) --repeat each 15 minute
  end

 

It gives me this error:[03.11.2020] [21:43:29] [ERROR] [SCENE103]: (load):2: Assertion failed: Expected number

 

any idea where the problem is?

 

Thanks!

 

7 answers to this question

Recommended Posts

  • 0
Posted

I use:

 

Please login or register to see this code.


to check the value of a sensor (true or false)

 

(and fibaro.sleep, not with the : )

 

(or use the declarations to trigger the scene every 15 minutes)

 

  • 0
  • Inquirer
  • Posted

    Thanks for your reply!

     

     

    I have made the changes you comment and it has remained like this:

    Condition:

     

    {
      conditions = { {
        type = "date",
        property = "cron",
        operator = "matchInterval",
        value = {
            date = { "*""*""*""*""*""*" },  --every minute, hour, day, month and year
            interval = 900 -- repeat 15 minutes
        },
        isTrigger = true
        }},
      operator = "all"
    }

     

    Action:

     

    --Check door open
    if
          ( tonumber(fibaro:getValue(125"value")) > 0 )
    then
            fibaro.alert('push', {[1] = 234, }, 'Door open')
    end

     

    But I keep getting the same error:

    [03.11.2020] [23:46:00] [ERROR] [SCENE106]: (load):3: Assertion failed: Expected number

    • 0
    Posted

    Almost. There is still a : between the fibaro and getValue and it returns a true or false value. 

     

    Try:

     

    Please login or register to see this code.

     

    • 0
  • Inquirer
  • Posted

    Hi again,

     

    Thanks for your help, the ":" were the problem.

     

    How I can create negation? Following the example that you have indicated, it would be like this:

     

     

    Detect If a sensor is breached

    HC2: if tonumber(fibaro:getValue(125, "value")) > 0 then

    HC3: if fibaro.getValue(125,"value") then

     

    But I can get this one:

     

    Detect if a sensor is safe

    HC2: if tonumber(fibaro:getValue(125, "value")) == 0 then

    HC3: ¿?

     

    And how I can create this String concatenating current time with a string?

     

    HC2: local msg = currentTime .. " Alarma DESARMADA"

    [04.11.2020] [22:40:59] [ERROR] [SCENE113]: (load):7: attempt to concatenate a nil value (global 'currentTime')

     

    Thanks a lot!

     

    • 0
  • Inquirer
  • Posted

    Please login or register to see this code.

    local currentDate = os.date("*t");

    local currentTime = string.format("%02d", currentDate.hour) .. ":" .. string.format("%02d", currentDate.min);

        local msg = currentTime .. " <MSG TEXT>“

        fibaro.alert('push', {[1] = <MOBILE ID>, }, msg)

    Please login or register to see this code.

    Detect If a sensor is breached

    HC2: if tonumber(fibaro:getValue(125, "value")) > 0 then

    HC3: if fibaro.getValue(125,"value") then

     

    But I can get this one:

     

    Detect if a sensor is safe

    HC2: if tonumber(fibaro:getValue(125, "value")) == 0 then

    HC3: ¿?

     

    Best regards!

    • 0
    Posted
    1 hour ago, Juanjo said:

    HC3: ¿?

     if (fibaro.getValue(125, "value")) == false -- true
    • 0
  • Inquirer
  • Posted

    Effectively works as you indicate

    Please login or register to see this link.

    ! I have tried many times and I did not come up with that test. The reason is that the cast number misled me and I thought that the data type was integer not boolean. Many thanks!

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