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 code for geolocation


Question

Posted

Hi to All!

 

I have a problem to get my mobile location, and some issue with the calculateDistance function.

I have HC3, here is my mobile registered, location is set. On my mobile is the location all the time allowed. It seems to me, when I get closer to my house, that a Fibaro-Icon is showing but for 1 sec only, and nothing happened after this.

 

My code is the following:
Line 1: local userID = 2
Line 2: local homeLocation = "xx.xxxxxxxxxxxxxxx;xx.xxxxxxxxxxxxxxx"
Line 3: local userLocation = fibaro:getValue(userID, "Location")
Line 4: local distance     = fibaro:calculateDistance(userLocation, homeLocation)

 

The error what I got:
for Line 3: "Assertion failed: Expected number". Here I have tried also: local userLocation = fibaro:getValue(tonumber(userID), "Location")
for Line 4: "attempt to call a nil value (method 'calculateDistance')"

 

What could be the problem here?


Thank you for your help!
Zsolt

4 answers to this question

Recommended Posts

  • 0
Posted (edited)
4 hours ago, BernhardtZs said:

I have HC3, here is my mobile registered, location is set. On my mobile is the location all the time allowed. It seems to me, when I get closer to my house, that a Fibaro-Icon is showing but for 1 sec only, and nothing happened after this.

 

My code is the following:

 

HC3, but what you using is HC2 example (fibaro:getValue vs fibaro.getValue or hub.getValue)

 

Afaik there is no calculateDistance on HC3, so you need to code your own, e.g.

 

Please login or register to see this code.

 

This is based on perfect sphere, there is as well WGS84 elipsoid model, used by GPS itself. However, we talking about 10cm more accuracy each every 100m (in Berlin).
Besides of that the location radius in Yubii app is reduced to 150m, no idea it the data is being updated once one arrived at home location.

Edited by tinman
  • 0
  • Inquirer
  • Posted (edited)

    Thank you for your answer.

    It is still not working :(

    Error message is: "14: bad argument #1 to 'find' (string expected, got nil)"

     

    I think because the "hub.getValue(userID, "Location")" get no value is null.

    What could be here the problem?

     

    I have checked the API:

    http://<IP_ADDRESS>/api/users/2

     

    Here is no value for Location. That could be a problem. But I understood not why is not there?

    Edited by BernhardtZs
    • 0
    Posted (edited)

    From my experience: hub.getValue(userID, "Location") does not work at all - as you noticed returns nil. So, there’s no way to retrieve user position on HC3 (and compute the distance from home). One and only you can count on is notification that user enter or leave geofence. 

    Simplest, You can use it in scenes.
    And in quickapps through the event mechanism. The latter certainly requires more knowledge about the HC3.

    And even this is still not a very reliable. 

    Edited by Łukasz997
    • 0
  • Inquirer
  • Posted

    Thank you for your answer.

    I wanted to try with this location query, because after I have created a scene, nothing happened.

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