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

Calculate traveltime


Question

Posted

Hello, since I am not a programmer I have a question for the programmers on this forum. In the introduction video from Fibaro there is a scene where the travel time between 2 locations (i.e. where ever you are and home) is calculated. I know it is possible using google maps to calculate the travel time between 2 coordinates. See this example which calculates the travel time between two city centers by car:

Please login or register to see this link.

See

Please login or register to see this link.

for explanation of the parameters

Is there someone who is willing to write a script that pulls the location of a user from his phone and calculates the travel time to Home and store this in a variable to be used in other scripts as timer? Maybe it is even possible to recalculate the traveltime every 15 minutes if the original traveltime is more than 15 minutes, since the traveltime will change depending on how fast you drive

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" /> and the trafic situation.

The goal is to start scenes when you are close to home, i.e. start the coffeemaker when you are 5 minutes from home.

6 answers to this question

Recommended Posts

  • 0
Posted

+1

  • 0
  • Inquirer
  • Posted

    I have been playing arround a bit and got this code so far in a virtual device button:

    Please login or register to see this code.

    It is generating a response from Google, but I do not know how to get the duration value out of the response. Can anyone help? Please.

    [ Added: 2014-03-13, 14:31 ]

    This is the response from Google Maps Api:

    Please login or register to see this code.

    I tried with json.decode to retrieve the duration value "2451" (this is the travel time in seconds), but it just won't work. Can anyone show me the proper way to decode this?

    • 0
    Posted

    Hello, great code!

    Try replacing your last line with this:

    Please login or register to see this code.

    That should do the trick!

    Good luck!

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

    • 0
    Posted

    to calculate the distance you could just use:

    Please login or register to see this code.

    Please login or register to see this code.

    • 0
  • Inquirer
  • Posted

    @lundan: Thanks lundan. Yes, that did the trick. Now I can continue.

    @stevenvd: Steven, I do not want to know the distance, I want to know the time it takes to travel that distance. I want to use that time as timer input to start scenes.

    I.e. my heater takes about 30 min. to heat up the house (it's well isolated). It takes me about 40 min. to travel home from work at normal traffic. In case of traffic jams it can take over 2 hours to get home, like yesterday when the A50 was closed in both directions because of accidents. Yesterday it took me about 1.5 hours to get home. I can not tell the distance I have to travel when I am 30 minutes from home. For 200 meters your method is possible, but how about 30 km? A lot can happen in 30 km. If I used your method yesterday, my heater would have been running for one hour for no one. A waste of energy.

    [ Added: 2014-03-14, 19:45 ]

    For those of you who want to experiment with it. Make a virtual device with just a label and put the code below in the main loop.

    Please login or register to see this code.

    Now you can call the travel time value for use in your scenes with:

    fibaro:getValue(123, ˝ui.Label1.value˝)

    where 123 is the virtual device ID. You can find the ID in the address bar when you have opened the virtual device (should have been listed in the device panel like with all other devices!!).

    • 0
    Posted
    to calculate the distance you could just use:

    Please login or register to see this code.

    calculateDistance doesn't work in Virtual Device...

    Please login or register to see this image.

    /emoticons/default_icon_cry.gif" alt=":cry:" />

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