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


Question

Posted

Hello all,

 

Just started with LUA. And now thing how to make the second thing. 

 

I have 1 motion sensors, and 4 relay in ZONE1(maybe in future it will be more, relays).
I need to change a state for 4 relays in ZONE1 but not to opposite state, but +1 status. 

 

For exmaple. Start position is 0,1,1,0 after motion sensor detect movement state will be 0,0,1,1, next time it will be 1,0,0,1. 

8 answers to this question

Recommended Posts

  • 0
Posted

It's not exactly +1 status, looks like you just moving 1,1 around the position:

0110 -> 0011 -> 1001 -> 1100 -> back to beginning.

Am I understanding correctly?

 

  • 0
Posted

It sound like on each motion, the zone relays switch to a following zone. Sounds a bit like magic to me, but probably there is a reason. 

  • Like 1
  • 0
  • Inquirer
  • Posted
    On 6/23/2023 at 4:30 AM, cag014 said:

    It's not exactly +1 status, looks like you just moving 1,1 around the position:

    0110 -> 0011 -> 1001 -> 1100 -> back to beginning.

    Am I understanding correctly?

     

    Yes. But for in one day it can be like 0110, on second day it can be 0001, and et.c

     

    On 6/23/2023 at 8:59 AM, SmartHomeEddy said:

    It sound like on each motion, the zone relays switch to a following zone. Sounds a bit like magic to me, but probably there is a reason. 

    Yes i have a reason for that. We have a lighting salon. And in 1 zone we have 4 relay, and total we have 5 zones, each of them have from 3 to 5 relay. And for couple zones we want make to auto-light who react to human detection. 😃

    • 0
    Posted

    @Aleksejs from GM 

    something like this?

    Each time the button is pressed, the QA will continue the sequence. Then you can easily make it do this instead of the button after every detected motion. To turn on/off relays just swap the text in pos1/pos2/pos3/pos4 with actions to turn on and off relays... i hope i help in some way :)

     

    function QuickApp:onInit()
        self:updateView("label","text""1100")
    end
     
    function QuickApp:pos1()
        out1 = "1"
        out2 = "1"
        out3 = "0"
        out4 = "0"
            self:updateView("label","text", out1..out2..out3..out4)
    end
     
    function QuickApp:pos2()
        out1 = "0"
        out2 = "1"
        out3 = "1"
        out4 = "0"
            self:updateView("label","text", out1..out2..out3..out4)
    end
     
    function QuickApp:pos3()
        out1 = "0"
        out2 = "0"
        out3 = "1"
        out4 = "1"
            self:updateView("label","text", out1..out2..out3..out4)
    end
     
    function QuickApp:pos4()
        out1 = "1"
        out2 = "0"
        out3 = "0"
        out4 = "1"
            self:updateView("label","text", out1..out2..out3..out4)
    end



     
    temp = 0
    function QuickApp:button() --onReleased name: button
        
        temp = temp + 1
        if (temp > 3then
            temp = 0
        end
        print(temp)
     
        if (temp == 0then
            self:pos1()
            else
            if (temp == 1then
                self:pos2()
                else
                if (temp == 2then
                    self:pos3()
                    else
                    if (temp == 3then
                        self:pos4()
                    end
                end
            end
        end
    end 
    • 0
    Posted (edited)

    To make same code short

    Please login or register to see this code.

     

    Edited by cag014
    • 0
    Posted
    6 hours ago, JureZ said:

    @Aleksejs from GM 

    something like this?

    Each time the button is pressed, the QA will continue the sequence. Then you can easily make it do this instead of the button after every detected motion. To turn on/off relays just swap the text in pos1/pos2/pos3/pos4 with actions to turn on and off relays... i hope i help in some way :)

     

    function QuickApp:onInit()
        self:updateView("label","text""1100")
    end
     
    function QuickApp:pos1()
        out1 = "1"
        out2 = "1"
        out3 = "0"
        out4 = "0"
            self:updateView("label","text", out1..out2..out3..out4)
    end
     
    function QuickApp:pos2()
        out1 = "0"
        out2 = "1"
        out3 = "1"
        out4 = "0"
            self:updateView("label","text", out1..out2..out3..out4)
    end
     
    function QuickApp:pos3()
        out1 = "0"
        out2 = "0"
        out3 = "1"
        out4 = "1"
            self:updateView("label","text", out1..out2..out3..out4)
    end
     
    function QuickApp:pos4()
        out1 = "1"
        out2 = "0"
        out3 = "0"
        out4 = "1"
            self:updateView("label","text", out1..out2..out3..out4)
    end



     
    temp = 0
    function QuickApp:button() --onReleased name: button
        
        temp = temp + 1
        if (temp > 3then
            temp = 0
        end
        print(temp)
     
        if (temp == 0then
            self:pos1()
            else
            if (temp == 1then
                self:pos2()
                else
                if (temp == 2then
                    self:pos3()
                    else
                    if (temp == 3then
                        self:pos4()
                    end
                end
            end
        end
    end 

    In any case, I do suggest using elseif statement, no need to count how many times you need to close IF... it's always confusing.

     
    temp = 0
    function QuickApp:button() --onReleased name: button
        temp = temp + 1
        if (temp > 3then
            temp = 0
        end
        print(temp)
     
    if (temp == 0then
            self:pos1()
     elseif (temp == 1then 
                 self:pos2()
     elseif (temp == 2then
                    self:pos3()
      elseif (temp == 3then
                        self:pos4()
        end
      end
    • Like 1
    • 0
    Posted

    @cag014

    Thank you. Im still learning to code so i apreciate the tip :) 

    • 0
    Posted
    10 hours ago, JureZ said:

    @cag014

    Thank you. Im still learning to code so i apreciate the tip :) 

    By the way you can try using

    Please login or register to see this link.

    , no LUA knowledge required and since HCL3 is limited for number of devices, it's just one QA does almost everything. 

    • Like 1

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