Full gate automation

For me, a “smart home” is when automation does all sorts of “routine” for you and does it without my participation.

In country life there are much more aspects subject to automation than in urban life. One of these automation objects is the gate for entering the site.

It is clear that any self-respecting homeowner will install automation on them, so that when returning home he does not have to get out of the car to open them and then close them. Radio control – everything is super.

But it's boring.

Geeks (like me) are starting to attach all sorts of automatic controls to this automation: starting from GSM modules (so that you can call the gate number and the gate will open to “your” one) to all sorts of systems that allow you to ask Siri, Alice or Google by voice (watches, phones , car radios, etc.).

But this is also somehow “sloppy”. I really want it to be “it itself.”

Initially, the idea was to extract images from the camera that controls the entrance to the site, then image recognition (that this is a car) and the license plate number of the car. But somehow there was no time to do this, and it looked like there would be certain difficulties (dirty rooms, etc.).

And it’s probably good that we never got around to this option, but instead made a GNSS device for a car.

The “bonus feature” of this device is a car tracker (support for the Wialon IPS protocol is implemented). Coordinates can be sent to the outside world anywhere. The device pushes data once every 10 seconds.

At first I used this function with a free account on the Ruhavik service – the service is excellent for testing. The functionality of a regular tracker is quite sufficient.

But then I came across several articles by @tananaev about various GPS tracker protocols and in all the articles there was a link to his Open Source project traccar.

After this, the following procedure took shape in my head:

  1. On the existing proxmox, lift the container with traccar.

  2. Expose the required port for the tracker to work (I have an external IP).

  3. Configure a GPS tracker to transmit geolocation to your server.

  4. Set up an event notification system (I was especially interested in “entering the geofence”), first in telegram.

  5. “Teach” traccar to send its events to mqtt.

  6. Using the existing node-red, receive the event “Monjaro has entered the “Home” geofence” and, based on this event, send the command “open the gate” to the smart home.

Then everything turned out to be quite simple.

I won’t describe the first three points – there are obvious things there (installation of traccar described on the project website, but everyone already knows how to configure a router for port forwarding and/or can find it using their favorite search engine; instructions for setting up a tracker are available, for example, here).

But I will describe the points, starting from the fourth:

The traccar configuration is located in the file /opt/traccar/conf/traccar.xml (I will provide it for the installation option on ubuntu).

To install the notification system in telegram, you need to add the following lines to this file:

  <entry key='notificator.types'>telegram</entry>
  <entry key='notificator.telegram.key'>YourChatBotAPIkey</entry>
  <entry key='notificator.telegram.chatId'>YourChatID</entry>
  <entry key='notificator.telegram.sendLocation'>true</entry>

If everything is done correctly, then telegram messages will already begin to arrive (don’t forget to put your key for the telegram bot and your chat ID. First, in the service’s web interface, you still need to configure the types of events that need to be notified. In my case, the most interesting ” entering the geofence.”

In order for events to be broadcast to MQTT, you need to add the following to the same config file:

  <entry key='forward.enable'>true</entry>
  <entry key='forward.type'>mqtt</entry>
  <entry key='event.forward.type'>mqtt</entry>
  <entry key='event.forward.url'>mqtt://IP-server:1883</entry>
  <entry key='event.forward.topic'>traccar/events</entry>

The parameters here are obvious: the penultimate line specifies the address of the mqtt server, and the last line specifies the topic where messages will be published.

Actually, after this, messages of the following type will arrive in MQTT
{"event":{"id":139,"attributes":{},"deviceId":1,"type":"geofenceEnter","eventTime":"2024-10-08T14:28:13.000+00:00","positionId":155,"geofenceId":1,"maintenanceId":0},"position":{"id":155,"attributes":{"batteryLevel":38.0,"distance":302.7380494307562,"totalDistance":944.8448214274459,"motion":false},"deviceId":1,"protocol":"osmand","serverTime":"2024-10-08T14:28:13.302+00:00","deviceTime":"2024-10-08T14:28:13.000+00:00","fixTime":"2024-10-08T14:28:13.000+00:00","outdated":false,"valid":true,"latitude":хх.хххххх,"longitude":yy.yyyyyy,"altitude":216.8000030517578,"speed":0.0,"course":0.0,"address":null,"accuracy":45.599998474121094,"network":null,"geofenceIds":[1]},"device":{"id":1,"attributes":{},"groupId":0,"calendarId":0,"name":"Monjaro","uniqueId":"zzzzzzzzzzzzzzz","status":"online","lastUpdate":"2024-10-08T14:28:13.302+00:00","positionId":119,"phone":null,"model":null,"contact":null,"category":null,"disabled":false,"expirationTime":null},"geofence":{"id":1,"attributes":{},"calendarId":0,"name":"Дом","description":null,"area":"LINESTRING (координаты-полигона-описывающего-геозону)"}}

Actually, then it’s a matter of technique – throwing cubes into nodered:

The flow was made as clear as possible: in the first "cube" we are looking for the target vehicle, in the second - the event "entrance to the zone"in the third - we check that this zone "House". Next comes the function call "open the gate" and publishing it in a topic for UD for execution.

The flow was made as clear as possible: in the first “cube” we look for the target vehicle, in the second – the “entering the zone” event, in the third – we check that this zone is “Home”. Next comes the call to the “open the gate” function and its publication in the topic for the UD for execution.

It’s also worth talking about the formation of the “Home” geofence:

I have access to the site from two sides. I wanted to make sure that the gates started opening early (so as not to wait, standing in front of them when they are still moving), but not too early to see the beginning of their movement.

In order for these “wishes” to work, I drew a geofence as follows:

Here, too, everything is obvious: into the geofence "House" grabbed two pieces of driveway.

Here, too, everything is obvious: two pieces of the access road were taken into the “House” geofence.

Since you are not driving too fast along the access road (20 km/h maximum), the frequency of sending data by the tracker (let me remind you, once every 10 seconds) turns out to be quite enough for the gate to open when you approach it.

This is the “magic”.

Now the gate opens on its own. It doesn’t matter whether it’s day/night, whether the rooms are clean, etc.

PS Now we still need to figure out how to make the gates open on their own when you need to leave the site 😉

P.P.S. Naturally, for such automation it is not necessary to use a hardware tracker – a software one (software for a phone and/or car radio/tablet, etc.) is also quite suitable.

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *