Experimenting with HTML Geolocation API

Hi folks,

Recently some forum members helped me controlling my garage door openers via Node-RED, which works fine at the moment. However using the dashboard for this purpose is currently a bit impractical: I need to grab my smartphone, open the dashboard app, navigate to the button to open the ports. So the whole process is a bit slow ...

So the wife asked: is it possible to have the dashboard open a popup dialog automatically (to ask whether the garage door should be opened), as soon as we approach our house at e.g. 200 meters. Although there are nice tutorials (e.g. to use the OwnTracks app) to determine your location, I would like to create a custom UI node because:

  • I always try to avoid having to install multiple tools to get the job done.
  • I would like to have it fully integrated into Node-RED to be able to control everything.
  • I just like to develop fun stuff ...

So the last two hours I quickly wrote a node-red-contrib-ui-geolocation node:

  • Since it is fully experimental, it is not on Github available yet.
  • It is based on the HTML5 GeoLocation API.
  • Would like to have in the future multiple trigger types (to specify when a message needs to be send to my Node-RED flow):
    image
  • Currently it shows some ugly output in the dashboard:
    image
  • And it sends an output message already to my Node-RED flow:
    image

But I don't know at the moment whether it is useful anyway to continue the development of this node...
Because this would mean my Node-RED dashboard should be active all the time on my smartphone.
So there might be issues with power consumption, connection lost, gsm in sleep mode, and so on ...

Would like to know how I can use the dashboard to make things like this possible?

Thanks !!!
Bart

As you spotted already, as this is running browser side it has to keep running and consuming power. Dedicated apps like owntracks run in the background nicely and can be set to report at intervals as well.
Feel free to try using dashboard and do the experiment if you have time....
(Or maybe just ask siri,Alexa etc to turn on the heating)

I would like to suggest a different approach.

What about a esp32 or similar board inside the car?
When it finds your wifi send a signal to open the gate?

You may put a led that alerts that is connected.

As an experiment I tried this a while ago. Unfortunately, by the time a signal is confirmed and a connection is made I had been sitting waiting for some seconds (longer than it would take to manually press the remote). Went back to a manual system.

Some things are just not worth the hassle of trying to automate with iot, imo.

For a completely different approach, have you thought about using a phone app such as Telegram (or pushcuts if you happen to be on iOS as it fits perfectly for this use case) and get an incoming message/notification send to this app with a link inside connecting to your node-red install that offers the open/close aspect?

So keep all the logic handling inside node-red as much as possible, then trigger an outgoing message to the device. On iOS, especially iOS 13, you can utilise location triggers for this, such as arriving at/leaving location, without too much overhead. However I don’t know a good equivalent for other platforms. I have my own tracker with me if I need to :slight_smile:

Another option that hasn’t been mentioned yet: a beacon on a keychain, with periodic scanning done by a local device that warns node-red when a specific beacon comes in range or goes out of range.

Another possibility, although not 100% reliable, might be something based on WUDS (Wifi User Detection System). It means having Wifi scanning enabled on your phone, but you can then check the MAC address and use that to signal your garage doors.

There are a few implementations around, mostly based on Raspberry Pi and Python, but I did a quick hack into C++ for an ESP8266, and it works pretty well.

1 Like

I suppose if it's the phone doing the scanning there is nothing to prevent you detecting someone else's access point a bit away from your house to give you extra time :-)... though of course you need to ensure it knows that you are arriving and not leaving ...

1 Like

BartButenaers

What about Iftt?

I have a Dragino Lora GPS tracker, the LGT-92-LI version, updates every minute (can be changed) to The Things Network, drop it in the car. Lasts about 10 days. Unless you drive with 120km/h to your home, it could be useful. Coverage in BE is ok-ish depending on where you are. But yes, siri can do it automagically.

@dceejay: Tja thought so... But hoped there was perhaps a solution using background worker or whatever.
But seems I will have to abandon this mechanism. What a pitty...

Well that might be an interesting idea. Then I don't have to try finding any buttons to press. Will need to start playing with this ... Thanks!

@paulohlp: that could indeed be a solution. Similar to the proposals of @molesworth and @bakman2 . But the advantage of an app is that everybody in our familly always have their smartphone with them. E.g. when we go for a walk or ... we just need our smart phone and we will be able to open the garage door. But good proposal!

@afelix: yes but I need to make sure that the garage door is opening automatically. I just want to get a 'proposal' to open it. For example when I accidentally pass by my house with the car, I don't want the doors to open automatically ...

@paulohlp: IFTT could indeed warn my Node-RED flow automatically, but then my Node-RED flow still cannot show a popup on my Smartphone (to let me choose whether I want to open the door or not). Or did I misunderstood your idea?

Was I that forgot that you need a popup. To be honest I don´t know if Iftt has this option.

The "WUDS" approach I mentioned has the device in your house, and it detects when a phone with WiFi scanning enabled comes close. It pretends to be a WiFi access point, and phones or other devices will send "probe" packets to get info.

In my version I white-list my own and friends and family's devices, and only raise an alert when an unknown device with a high signal strength is detected. (I also have a green-list for e.g. the postman, so I know if I'm likely to have mail when I get home :slightly_smiling_face:)

For your application you'd do the opposite, and could trigger events when a family phone is detected - although as @dceejay mentioned, you'd need some logic to figure out whether it's someone arriving.

I'm now thinking about what I can do in my setup when a "friendly" device appears...

1 Like

ESP-NOW would handle this. The handshaking for esp-now is milliseconds.

1 Like

But more than that, the range seems to be triple that of normal wifi. Curious now to try it out.

Nice find, thanks.

1 Like

Most of the suggestions here suffer from a timing problem. Many of the ones for phones also suffer from a power problem. IFTTT only claims a time accuracy to 15 minutes. Telegram is better but is ocassionally delayed by maybe 10-20sec (a lot at 200m @ 2-30kph).

Also, you cannot really guarantee GPS either, especially on a phone since they will prefer to manage power over location accuracy. Best I've ever been able to do is a geofence of about 500m where we are. That might work for you but not really for us as we are in a dense urban area.

Owntracks would be best since you can also work out whether you are coming or going. Or maybe ESP-Now (I've not tried that).

Hi Bart - I'm interested in the node-red-contrib-ui-geolocation I would like to use it to get my location from the UI so I can log the location for commissioning a device.

What you have shown in your post is ideal, is there any chance you could release the node please.

Thanks
Marshall

Hello @marshall,
The problem is that this node is FAR from complete:

  • It uses lots of energy, so not ideal for a smartphone.
  • Currently the dashboard needs to be open, otherwise I doesn't send any locations. Should run as a background worker in the browser somehow.
  • ...

So unfortunately not much to publish...

thanks for the quick reponse.

Do you have any tips on how to get the current location from the device, using a function or template node?

All I am really looking for is to click a button, and it returns the location. I actually don't want it to be dynamic.

Thanks for the pointers.

Regards
Marshall

In my first post above you can find the link to the Javascript Geolocation API. It is very easy, and indeed you can call it in a template node (if a button is clicked).

THanks, I'm too dumb to figure out how to it. I'll try a bit harder.,..