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


Idea how to monitor people at home


Recommended Posts

Guest Roman
Posted

Hi, I want to share some idea.

This example works for me, and probably it will be helpful for others.

 

Me and my wife always use Wi-Fi on our cellphones.

There is a script which allows to scan network and detect if mobile phone connected at this moment.

 

This idea allows to change the behavior of house according to it. Only one thing you need to set up mac address of device.

Please login or register to see this code.

Posted

So I guess that you are running this as a Virtual Device. Are you running this every X minutes or so?

Guest Roman
  • Topic Author
  • Posted

    Yes exactly.
    So there is possibility to:

    - turn everything off, if there is no people at home.

    - adapt climate according to preverences.

    - allow to turn on the light only in one room, if there is only one person at home.

    - use different voice notifications according to people at home.

     

    These are only several ideas how to use this.

    Posted

    Looks Like a good idea would this work on the HCL as a virtual device ??

    Posted

    I've no real need for it as I'm using tasker (Android app) to handel all this stuff, but looks like your code might work.

    Only problem with running it ever X minutes is that it will put some strain/stress on the HC2.

    Posted

    I am doing exactly the same thing, but also checking bluetooth. Wifi on iPhones tend to go to sleep after a while, but bluetooth low energy is always on. I have a raspberry pi and a script that checks every 1 minute if our phones are home. If there is a change then it updates a variable in HCL according to presence. Lighting and heating is turned off and alarm is armed if we leave.

    Posted

    Hi Marton, could you please give us more info on the approach your are using to detect BT with your rasp? Did you had the chance to try it with iphones?

    Thank you very much for your feedback!!

    Posted

    Sure! It works with iPhones, we have two and no problem! So I run a script every minute to check if the phones are home or not. It updates a database and also runs a scene in HCL. In the database I store the bluetooth mac addresses of the phones and their static ip addresses. I set it up in my router so that the phones get the same ip address every time. With this I just add another line in the database and I can check 3 phones, and so on.

     

    I am using a file to store if someone was home, so I won't update the HCL every minute, just when a change happens.

     

     

    Here is the script, but please forgive me for any coding nonsense as I have very-very little knowledge about how to code. However this works

    Please login or register to see this image.

    /emoticons/default_smile.png" alt=":)" srcset="https://forum.fibaro.com/uploads/emoticons/[email protected] 2x" width="20" height="20" />

     

     

    #/bin/bash

    file="/home/pi/yes"
    anybody_home=0
    date=$(date +"%H:%M");
     
    #check if someone was already home
    filecheck=$([ -f $file ])$?
     
    while read -a row
    do
        #echo "${row[0]} ${row[1]} ${row[2]} ${row[3]} ${row[4]}"
        #check for bluetooth and ping
        btcheck=$(hcitool name "${row[3]}" | grep -q "${row[0]}")$?
        ping=$(ping -q -c1 "${row[4]}" > /dev/null 2>&1)$?
        #echo "btcheck: $btcheck  ping: $ping"
        #someone is home but was not before
        if [ $btcheck = 0 ] || [ $ping = 0 ]
          then
          echo "${row[0]} is home"
          anybody_home=1
          if [ "${row[1]}" = "no" ]
            then
             mysql --user="user" --password="pass" --database="home_automation" --execute="UPDATE anybody_home SET ishome='yes', date='$date' WHERE who='${row[0]}';";
          fi
        fi
        #someone was home, but not anymore
        if [ $btcheck = 1 ] && [ $ping = 1 ] && [ "${row[1]}" = "yes" ]
          then
          echo "${row[0]} is away but was home before"
          mysql --user="user" --password="pass" --database="home_automation" --execute="UPDATE anybody_home SET ishome='no', date='0' WHERE who='${row[0]}';";
        fi
    done < <(echo "SELECT * FROM anybody_home" | mysql --database="home_automation" --user="user" --password="pass")
     
    echo "Anybody home: $anybody_home"
     
    if [ $anybody_home = 1 ] && [ $filecheck = 1 ]
    then
     #someone is home, but not before, updating fibaro
     echo "someone is home, but not before, updating fibaro"
     curl -G "

    Please login or register to see this link.

     touch $file
    fi
     
    if [ $anybody_home = 0 ] && [ $filecheck = 0 ]
    then
     #someone was home, but left, updating fibaro
     echo "someone was home, but left, updating fibaro"
     curl -G "

    Please login or register to see this link.

     rm -f $file
    fi
    • Thanks 1
    Posted

    There are a few scripts around that one can run on the router (AsusWRT from RMerlin or DD-WRT based routers) which checks if there is a specific MAC adress on the WLAN connection without ping or any sort of discovery (no battery usage on cellphone). As far as I know this works for all devices I know of, sleep or not sleep. My script is run every 5 seconds, and uses less than 1% CPU on the router - I guess I could run it even more frequent if I need. Anyway, combined with a VD, this gives a bit better solution in my installation.

    Posted

    Would this be possible to do on a HCL, without LUA?

    Any ideas on how?

    Posted

    Well, the VD is exportable, and if I remember correct a VD is importable in HCL?

     

    Edit: Well I guess one could rewrite the script in the router to call two different scripts to do "home" and "away" - never tried it though....

    Posted

    There are a few scripts around that one can run on the router (AsusWRT from RMerlin or DD-WRT based routers) which checks if there is a specific MAC adress on the WLAN connection without ping or any sort of discovery (no battery usage on cellphone). As far as I know this works for all devices I know of, sleep or not sleep. My script is run every 5 seconds, and uses less than 1% CPU on the router - I guess I could run it even more frequent if I need. Anyway, combined with a VD, this gives a bit better solution in my installation.

     

    I have a asus running on DD WRT firmware and check the phone's on MAC with a VD of Jompa86 (still thanks alot) and checking every 4 min. with GEA script (push the VD button) if me or my girlfriend are at home.

    Going to test this VD also.. love to play with those presented check with mobiles

    Please login or register to see this image.

    /emoticons/default_biggrin.png" alt=":D" srcset="https://forum.fibaro.com/uploads/emoticons/[email protected] 2x" width="20" height="20" />

    Posted

    Sure! It works with iPhones, we have two and no problem! So I run a script every minute to check if the phones are home or not. It updates a database and also runs a scene in HCL. In the database I store the bluetooth mac addresses of the phones and their static ip addresses. I set it up in my router so that the phones get the same ip address every time. With this I just add another line in the database and I can check 3 phones, and so on.

     

    I am using a file to store if someone was home, so I won't update the HCL every minute, just when a change happens.

     

     

    Here is the script, but please forgive me for any coding nonsense as I have very-very little knowledge about how to code. However this works

    Please login or register to see this image.

    /emoticons/default_smile.png" alt=":)" srcset="https://forum.fibaro.com/uploads/emoticons/[email protected] 2x" width="20" height="20" />

     

     

    #/bin/bash

    file="/home/pi/yes"

    anybody_home=0

    date=$(date +"%H:%M");

     

    #check if someone was already home

    filecheck=$([ -f $file ])$?

     

    while read -a row

    do

        #echo "${row[0]} ${row[1]} ${row[2]} ${row[3]} ${row[4]}"

        #check for bluetooth and ping

        btcheck=$(hcitool name "${row[3]}" | grep -q "${row[0]}")$?

        ping=$(ping -q -c1 "${row[4]}" > /dev/null 2>&1)$?

        #echo "btcheck: $btcheck  ping: $ping"

        #someone is home but was not before

        if [ $btcheck = 0 ] || [ $ping = 0 ]

          then

          echo "${row[0]} is home"

          anybody_home=1

          if [ "${row[1]}" = "no" ]

            then

             mysql --user="user" --password="pass" --database="home_automation" --execute="UPDATE anybody_home SET ishome='yes', date='$date' WHERE who='${row[0]}';";

          fi

        fi

        #someone was home, but not anymore

        if [ $btcheck = 1 ] && [ $ping = 1 ] && [ "${row[1]}" = "yes" ]

          then

          echo "${row[0]} is away but was home before"

          mysql --user="user" --password="pass" --database="home_automation" --execute="UPDATE anybody_home SET ishome='no', date='0' WHERE who='${row[0]}';";

        fi

    done < <(echo "SELECT * FROM anybody_home" | mysql --database="home_automation" --user="user" --password="pass")

     

    echo "Anybody home: $anybody_home"

     

    if [ $anybody_home = 1 ] && [ $filecheck = 1 ]

    then

     #someone is home, but not before, updating fibaro

     echo "someone is home, but not before, updating fibaro"

     curl -G "

    Please login or register to see this link.

     touch $file

    fi

     

    if [ $anybody_home = 0 ] && [ $filecheck = 0 ]

    then

     #someone was home, but left, updating fibaro

     echo "someone was home, but left, updating fibaro"

     curl -G "

    Please login or register to see this link.

     rm -f $file

    fi

    Thank you very much Marton, i'll test it!

    • 2 weeks later...
    Posted

    I have question, what if I forget my phone at home, or even better if I came home and realize that my phone is lost, or if my phone die on me?

    Posted

    I have question, what if I forget my phone at home, or even better if I came home and realize that my phone is lost, or if my phone die on me?

     

    Think you know the answer yourself, phone not with you then you can's check it

    Please login or register to see this image.

    /emoticons/default_wink.png" alt=";)" srcset="https://forum.fibaro.com/uploads/emoticons/[email protected] 2x" width="20" height="20" />

    Like you lost you keys of the house you can't enter it. But with this you can disable the phone check for some time and press a button home / away manually

     

    But with al this Lambik have a great VD Presence Detector that detects al motions sensors in the house if you are home or not. (no phones needed )

     

    Please login or register to see this link.

     

    Please read careful, change the bugs in script with the bug reporter at page 1 and you good to go!

     

    I do a triple check now, 2 of them are with the phones (at home global 1 or 0 and in combination with a last seen) and those combine with the presence detector makes it stable and independent of the phone with you or not. Or in my case when my mother take care of my lovely daughter at home when i'n at work  

    (codes are from jompa and lambik )

    Posted

     

    Hi, I want to share some idea.

    This example works for me, and probably it will be helpful for others.

     

    Me and my wife always use Wi-Fi on our cellphones.

    There is a script which allows to scan network and detect if mobile phone connected at this moment.

     

    This idea allows to change the behavior of house according to it. Only one thing you need to set up mac address of device.

    Please login or register to see this code.

    Hi Roman,

    Thanks for sharing this little code, it works flawlessly !!!

    I implemented it "my way" here: 

    Please login or register to see this link.

     with all the bells and whistles 

    Please login or register to see this image.

    /emoticons/default_icon_biggrin.gif" alt=":-D" />  :->

    Comments in the code are in english.

    Enjoy !

    Guest Roman
  • Topic Author
  • Posted

    You are welcome

    Please login or register to see this image.

    /emoticons/default_wink.png" alt=";)" srcset="https://forum.fibaro.com/uploads/emoticons/[email protected] 2x" width="20" height="20" />

    I am glad that this idea was useful for you.

     

    There is new idea. I use this code when some IP device doesn't allow to set static IP.

    This code allows to find IP if we know mac address.

     

    Several audio speakers do now allow to set static IP:

    Posted

    so if am ride

     

    local login = "login to HC2"; --> is your loginnaam HC2 Fibaro
    local pass = "pass to HC2"; --> is your password HC2 Fibaro
    local mac = "mac address of device";--> is mac adress of a phone

    local HC2 = Net.FHttp("127.0.0.1", 80); --> is your IP-adres HC2Fibaro
    HC2:setBasicAuthentication(login, pass); --> Calls the login and password HC2 Fibaro

    how does it find the mac adress, isn't that in your router

     

    try to understand

    Please login or register to see this image.

    /emoticons/default_icon_biggrin.gif" alt=":-D" />

    Guest Roman
  • Topic Author
  • Posted

    Thank you, sjauquet!

     

    I read your code and improved script. I didn't know about possibility to call Fibaro HC2 through port 11111 without login and pass. 

    Please login or register to see this code.

    To Kage.

    This script allows to call HC2 itself. 127.0.0.1 this is localhost (internal ip address of HC2).

    Please login or register to see this link.

     

    When I call:

    Please login or register to see this link.

    IP>/api/networkDiscovery/arp

     

    It returns json with all mac and ip addresses in network.

    Also helpfull info located here:

    Please login or register to see this link.

    Posted

    my local 127.0.0.1 is my server so i wil change it to my IP 192.168.0.123

    the mac adress is that also of the HC2

    Join the conversation

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

    Guest
    Reply to this topic...

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