Update zone location for boats, rv’s (not home zone)

Hi all,

Currently I have build a proof of concept working to integrate CZone equipment into HA. It reads out the CZone configuration and uses MQTT autodiscovery to polpulate a separate zone with sensors and switches.

The boat in this case is equipped with a 4G router, wireguard vpn (boat is a subnet of my home network). As the 4G router is running openwrt it is possible to run a small Python daemon eliminating the need for a separate computer.

The CZone COI is permanently powered, as is the the 4G router and a nmea2000 gps unit. It is all connected via a NMEA2000 to ethernet converter by Yacht Devices.

I created a separate zone in my HA with the name of the boat. Both me and my wife have an iPhone with the HA app. This works all great, and I have some working automations like if it is dark (ie 45 minutes before sunset etc) and either of us enters the zone around our boat, HA commands to switch on the deck lights and some interior lights).

This will work for as long as the boat is in the home port, as the position of the zone is set on my spot in the harbor. Since CZone is basically a marine grade boat automation solution there is no real need to add a HA instance.

The home zone has a “set_location” service, but I can not find such a thing for other zones. Most ideal would be to add some logic to my script to include some logic in my python script which uses the GPS unit to update the zone position using MQTT in an intelligent way. So leaving/entering the zone also works in places other than my home port.

I have searched all over the place and could not really find a workable solution for connecting Boats, RV’s etc to a zone and make it move, when the HA installation is NOT on the vehicle.

I am perfectly capable of modifying HA but for multiple reasons not interested in learning how to use git, (I am heavily confused by therminology, tried before and never was able to make that work.) just to copy the “set_location” logic or what is needed to give zones other than the home zone the same functionality. For now I am puzzled on how to update the location using MQTT

Any hints or tips on how to make this work?

Martijn

As an admittedly hacky interim solution, you can use customize.yaml to change the lat/long of a zone (although the changes don’t show up when you edit zones via the UI). Therefore, in customize.yaml you could have the following:

zone.boat: !include customize_zone_boat.yaml

And then in the included file:

latitude: -37
longitude: 144

Then when you want to update the location:

  1. Update the file with a new location
  2. Call homeassistant.reload_core_config to reload customizations.
  3. Call homeassistant.update_entity for the zone and if you’ve got a map open, the boat’s location should automatically update.

Having said that, I haven’t tested how long it takes to update the people within the zone (or if it even works properly), because I’m at home and of the way overlapping zones works. You would also have to deal with this if your boat/RV is parked at home.

That is an interesting approach.

I was looking at using the api to change it (like doing it from the UI) but I use MQTT …

I have a very long lived home assistant installation and no customize yaml but I will look into that. Also calling a service from MQTT is something I d not know about.

I have a proof of concept config free MQTT autodiscovery program running on my openwrt router. It reads/writes nmea2000 (and CZone) values. On the router there is barely space for Python. But it all works. I.e. if I arrive at the boat when it’s dark, the deck lights and interior lights turn on. All with no HA installation/mqtt to my house.

Fortunately, there is no suitable water near my house for a sea going vessel, so overlapping zones -in my case- is no issue. I see issues however when the zone is moving with the onboard phones, entering and leaving all the time due to delays. I could use the arp on the router to see if the phones are connected to wifi … but they both have an unlimited data plan en do not connect to the boat’s wifi. Maybe a Bluetooth tag will do the trick.

Everything is working nice this way, and I try to avoid running an HA instance on my boat, just to solve the zone location issue. Currently the 4G router, CZone coi and a few sensors are powered when I am away. Easily running from batteries/solar (even in Dutch short day winter). Eliminating shore power at the moment.

I guess to run this solution at home I will probably need to run a python script as a daemon looking at the location in MQTT and update the yaml and call the reload service.

I have dug into the source of HA but the home zone and zones in general seem to be unrelated and not based on an object/class (I could be wrong, did not spend that much time) as I thought it was an easy hack to give zones support for “set_location”. And share that in the forums for someone to pick up.

Thank you for sharing this!

Martijn

This works for home zone (below) but if homeassistant is not on the boat, it might be easier to use some other form of binary sensor via your phone. Eg. a bluetooth beacon on the boat, and when your phone is connected to it, then HA back home knows you’re “on the boat” and responds accordingly

If you wanted something longer range (to trigger automations before stepping onto the boat) I think you might need a 2nd instance of HA running on the boat

Did you ever figure out an easy way to do this?
I want to update the position of a zone via a script.

Added a feature for updating zones in Spook:

https://github.com/frenck/spook

3 Likes