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

Ping iPhone instead of GPS localization


Question

Posted

Instead of using the GPS localization which consumes enormous amounts of power from the iPhone, I want to let the HC2 ping every minute if it can find the iPhone on my local network.

And based on that set a value if somebody is home or not.

Since 3.486 os.execute doesn't work.

Anybody have an idea how to use that function?

This is what I want to do:

Please login or register to see this code.

Edit:forgot the while true do.

  • Answers 102
  • Created
  • Last Reply

Top Posters For This Question

Top Posters For This Question

Posted Images

Recommended Posts

  • 0
Posted

ok so ive god mine to welcome me home that wont keep turning the lights on every minute, so it checks to see if ive been welcomed already.

is there anyway to speed this up ? especially the iphone poll.. i find it can take up to two minuted to switch the lights on presumably because it can take upto a minute to poll the iphone and then another minute to check if the variable is 1 before the lights come on.

regards

john

  • 0
Posted
ok so ive god mine to welcome me home that wont keep turning the lights on every minute, so it checks to see if ive been welcomed already.

is there anyway to speed this up ? especially the iphone poll.. i find it can take up to two minuted to switch the lights on presumably because it can take upto a minute to poll the iphone and then another minute to check if the variable is 1 before the lights come on.

regards

john

I think if you write this in LUA, you can determine yourself how long the delay is between subsequent checks... There's typically a fibaro:sleep(60*1000) statement in there... Change 60 to 15, and it'll check every 15 seconds. Not sure what that will eventually do to the performance of the box but give that a try...

  • 0
Posted

thats better, that took about 5 seconds XD now if only i can increase the range of my wifi so that my iphone can pick it up at the end of my road i can then use it to activate the driveway lights before i actually get on the driveway. Thanks for your help everyone

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" />

for your help i shall post my scenes

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" />

This is the code to find out if your iPhone is within the range of wifi every 10 seconds

Please login or register to see this code.

And here is the scene for activating the Hall lights

Please login or register to see this code.

finally this one checks to see if you are home and if not, turns off all of the lights and reset the "Welcomed" flag

Please login or register to see this code.

  • 0
Posted
Is there a way to adapt this for more than 1 iPhone? So if my girlfriend comes over and I pop to the shop all of the lights don't switch off when I leave ?

So it could say something like

If john_at_home = 0 and kat_at_home = 0 then switch off the lights

I have this programmed is 6 scenes and a bunch of global variables:

If Ronald or Katja gets home, and it's dark, switch on Kitchen light

When both of us left, switch off the light in the kitchen

I have separated the coming home & leaving detection for both of us. Just like you, I keep two variables to remember the status. When either one of use comes home, I call a "ArrivingLogic" scene. When either one of us leave, I call a "LeavingLogic" scene. In those two logic scenes I do my 'OR' (he OR she are home) or 'AND' (he AND she are gone) logic, where I also check if it is dark outside before the lights go on... Pretty neat!

DM me if you want the scripts; a bit too much to post them all 6 here...

  • 0
Posted

Do you still use that code to check the iPhone presence? Does it work properly?

In my case very often the check shows that I'm out even if I'm at home with my iPhone connected to WiFi!?

  • 0
Posted

It's because iPhone is visible and respond to ping only when it try to sync with mail and cloud every xx minutes, it's the limitation of this script...

  • 0
Posted

Anyone have any idea how to make sure that it will work more raliable?

  • 0
Posted
Anyone have any idea how to make sure that it will work more raliable?

Well... that's not my experience. I do use the script to determine if either my girlfriend or me are coming home, at home or leaving home, and switch on and off some lights as a result.

It appears to me that my iPhone remains connected to my WiFi, also if I am not using it. As a result, the ping succeeds whenever I am at home. I am checking my iphone every 20 seconds

Here's the ping scripts I use in my virtual device:

tcpSocket = Net.FTcpSocket("192.168.1.100", 62078)

bytes, errorCode = tcpSocket:write("test")

if errorCode == 0

then

fibaro:setGlobal("RonaldThuis", "1");

fibaro:log("Ronald is thuis");

else

fibaro:setGlobal("RonaldThuis", "0");

fibaro:log("Ronald is niet thuis");

end

And then I have this very basic LUA script which runs every 15 seconds. Button 1 my my iPhone, button 2 is the boss' phone:

--[[

%% autostart

%% properties

%% globals

--]]

local sourceTrigger = fibaro:getSourceTrigger();

if (sourceTrigger["type"] == "autostart")

then

while true do

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

local startSource = fibaro:getSourceTrigger();

fibaro:call(86, "pressButton", "1");

fibaro:call(86, "pressButton", "2");

fibaro:sleep(15*1000);

end

else

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

local startSource = fibaro:getSourceTrigger();

if (startSource["type"] == "other")

then

fibaro:call(86, "pressButton", "1");

fibaro:call(86, "pressButton", "2");

end

end

I was a bit afraid that long term failing of these tcpSocket:Write() calls would make the box hang eventually, but it's been stable ever since I started using it.

  • 0
Guest jrkalf
Posted
It's because iPhone is visible and respond to ping only when it try to sync with mail and cloud every xx minutes, it's the limitation of this script...

This is correct, it's build in to the OS to conserve battery life

Please login or register to see this image.

/emoticons/default_icon_curve.gif" alt=":-/" />

Perhaps, but that's a long shot and a bit off a stretch that would require some coding, have a raspberry Pi with a Bluetooth dongle attached and pair it up with your iphone. As long as you're paired with the iPhone, you're home. And range of the bluetooth dongles can go up with 100m for a class A device?

As far as I know the intermittent issue as with WiFi isn't implemented for bluetooth.

I hope you find a solution for that.

[ Added: 2013-04-03, 15:33 ]

I was a bit afraid that long term failing of these tcpSocket:Write() calls would make the box hang eventually, but it's been stable ever since I started using it.

Ronald,

What iOS version are you using on your phone. Is it iOS 6.x or are you running an older phone with iOS5? The ping issue is a known issue I've been briefed on by a network expert at a previous consulting job. It's hardcoded to drop WiFi if the phone is locked for a period of time to conserve battery.

  • 0
Posted
Well... that's not my experience. I do use the script to determine if either my girlfriend or me are coming home, at home or leaving home, and switch on and off some lights as a result.

This is an iOS 6.x issue in sleep mode, the wifi is disabled...The IP no longer responds about 10 seconds after the phone going to sleep. But from apple forum (non checked...) It seems if the phone is plugged into a charger, the WIFI stays active.

No problem with iOS 5.x.

Please login or register to see this image.

/emoticons/default_icon_wink.gif" alt=";-)" />

All the best.

  • 0
Posted

I've been "pinging" my iPhones every 10mins and if I have left it for half an hour it would usually, but not always, stop responding.

Maybe if you ping it every 15 seconds as rvorsten is doing it would keep it awaken? I will try it and let you know.

PS

I'm using iOS 6.1.3

  • 0
  • Inquirer
  • Posted

    Works here 99,9% of the time.

    With an iPhone 4 and 5 both running 6.1.2.

    Couple of times it said it was not online.

    But my wife came home 3 hours ago iPhone is still in her bag and HC2 pings it just fine.

    I run the script every 10 seconds. See no extra battery drain.

    E-mails get pushed to the device like always when they arrive.

    • 0
    Posted

    After changing to 15 seconds so far so good

    Please login or register to see this image.

    /emoticons/default_icon_smile.gif" alt=":-)" />

    Thanks for the tip - now it's usable !

    • 0
    Posted

    Works also fine here.

    It will be great to have direct ping without checking a port.

    I like to se the status of more devices. some of this devices hase no open poort

    • 0
  • Inquirer
  • Posted
    Works also fine here.

    It will be great to have direct ping without checking a port.

    I like to se the status of more devices. some of this devices hase no open poort

    +1 Indeed, would be nice if Fibaro just created this function.

    • 0
    Guest deraaij
    Posted
    Works also fine here.

    It will be great to have direct ping without checking a port.

    I like to se the status of more devices. some of this devices hase no open poort

    I agree! I was using os.execute before, needing open ports feels like a work around. Hopefully they implement something like fibaro:ping(192.168.1.1). We should submit a feature request.

    • 0
    Posted

    +1

    We should submit a feature request.

    Please login or register to see this link.

    Please login or register to see this image.

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

    • 0
    Posted

    Thank you...Fibaro I hope we can see this in the next beta..

    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" />

    Some more options are also welcome

    - ICMP

    - TCP

    Create devices for every IP unit and display the status

    Like Laptop Online (since 0:4:23)(D:H:M:)

    Printer Offline (since 2:10:15)

    Webserver (www) online since 14:5:15)

    iPhone online since…..

    Also more control from the scenes will be great

    Something like

    When iPhone becomes offline after 5 times ping…

    User is not at home

    When laptop becomes offline after 2 time ping

    turn off the desk light

    When Laptop online

    Turn on the Printer (power on/off)

    When TV offline

    Turn Off the settopbox

    This are all domitica related.....

    • 0
    Guest deraaij
    Posted
    +1
    We should submit a feature request.

    Please login or register to see this link.

    Please login or register to see this image.

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

    thnx, sorry was busy .....

    • 0
    Posted

    My wife was quite surprised when the garden door has opened, and lights at the hall has switched on at her arrival close to our house. Start to like this solution

    Please login or register to see this image.

    /emoticons/default_icon_mrgreen.gif" alt=":mrgreen:" />

    Anyway, real PING would be even more usefull.

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