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

activating scene with time delay


Question

Posted

I need your help guys, because i have no idea how to do it.

 

What i'm trying to achive is: after i'm NOT in home for at least 30 min, than after i open the front door, sonos speaks "welcome home" with 3 sec delay.

 

What i did so far: HC2 checks if my phone WIFI is within range, than sets the variable to "present", when it's not in range than it changes to "not present".

 

Now how do i make HC2 count down to -1800 sec and set variable parameter to "not present long", so the door sensor could set off sonos in the right time? Now it tels me "welcom home" whenever i open the door (from the inside or outside, no mater if i was home for long or not).

 

Any ideas?

6 answers to this question

Recommended Posts

  • 0
Posted

Hi

I'm sorry I can't help but - that scene sounds amazing any chance of sharing the code for it.

Cheers

  • 0
Posted

Don't now if it's helpfull but,

 

if (fibaro:countScenes()>1)
then
 fibaro:abort();
  end
local run = 0

local counter = 0

 

if ( phone is away) and run == 0 then
  local start = (os.time())
 run = 1
end


while run == 1 do

if ( phone is away)  then
     counter = counter + 1
    end
          if ( phone is home) then
      counter = 0
    end
       if ( phone is away) and counter > 1800 then
          fibaro:debug("Phone long away")
run = 0
       end
  fibaro:sleep(1*1000)
end

  • 0
  • Inquirer
  • Posted

    Thanks Kage for your help, i'll try to use your scene in my later experiments, but during last time i tried to solve this problem in another way. Maybe it's a bit strange way to do it, but my LUA knowledge is very limited.

     

    So now i have 2 variables:

    - "remik" - which checks if i'm home, which can have values - or + any number

    - "remikaway" - which checks if i'm long away with values 0 or 1

     

    I also have made virtual device with 2 buttons (one checks the state of my phone WIFI, and the other checks if i'm "long gone" or not), and 2 scenes which press each buton every 10sec.

     

    what it suposed to do:

    buton "wifi check" is pressed every 10sec by scene, LUA code in button checks if phone WIFI is in range (sends TCP command to phone and waits for return code),

    - if phone IS in range and it WASN'T before (no error return from phone and variable "remik" was a numer below "0"), than it changes variable remik to"1"

    - if phone IS in range and it WAS in range before (no error return from phone and variable "remik" was a numer above "0"), than it adds to variable value "+1"

    - if phone is NOT in range but it WAS in range before (phone returns some kind of error code and variable "remik" was a numer "1" or above), than variable remik changes to 0

    - if phone is NOT in range and it WASN'T in range before (phone returns some kind of error code and variable "remik" was a numer below "0"), than it adds "-1" to variable "remik"

     

    LUA code for "wifi check" button:

     

     

    tcpSocket = Net.FTcpSocket("192.168.0.5", 32000)
    bytes, errorCode = tcpSocket:write("test")

    if errorCode == 0
    and  fibaro:getGlobal("remik")<=0
    then
    fibaro:setGlobal("remik", "1");
    fibaro:log("Remik w domu");
    elseif errorCode == 0
    and  fibaro:getGlobal("remik")>=1
    then
    fibaro:setGlobal("remik", fibaro:getGlobal("remik") + 1);
    fibaro:log("Remik w domu");
    elseif errorCode ~= 0
    and  fibaro:getGlobal("remik")>=1
    then
    fibaro:setGlobal("remik", "0,");
    fibaro:log("Remik poza domem");
    else
    fibaro:setGlobal("remik", fibaro:getGlobal("remik") - 1);
    fibaro:log("Remik poza domem");
    end
    end
    end

     

     

     

    Second VD button sets "remikaway" variable. 

    - when variable "remik" is below "-180" (each "-1" represents 10sec, so my phone is not in range for 30min or more), than it sets variable "remikaway" to 1

    - when variable "remik" is over "60" (each "1" represents 10sec, so my phone is in range for 10min or more), than it sets variable "remikaway" to 0

     

    LUA code for this button:

     

     

     

    if fibaro:getGlobal("remik") <= -180
    then
    fibaro:setGlobal("remikaway", 1);
    elseif fibaro:getGlobal("remik") >= 60
    then
    fibaro:setGlobal("remikaway", 0);
    end
    end

     

     

     

    Now what should happen is, when main door are open and variable "remikaway=1" (so i'm not in home for more than 30min or i'm in home for less than 10min) and variable "remik>0" (my wifi is detected), thank sonos plays "welcome home Remik".

     

    Unfortunatly LUA code i've created does not work. Variables don't change when i turn on/off wifi.

     

    Could somebody tell me what i did wrong in LUA code, or maybe is my plan illogical somewhere?

    • 0
  • Inquirer
  • Posted

    Could anyone give me a hint what i'm doing wrong with that LUA code?

    • 0
    Posted

    Try building the code in block scene and change it to lua to edit with the code?

    • 0
    Posted

    Maybe you've found it already, but anyway:

    Please login or register to see this link.

     

    Regards, Erik

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