Under the roof of my house I’m hosting an AIS receiver station with a RaspberryPi (currently a 3B), a dAISy HAT and a Sirio GP3E antenna. This station receives AIS signals from passing ships and feeds the NMEA data into the ship data networks AIS Hub, MarineTraffic, VesselFinder and FleetMon (see this post). In order to have a strong antenna signal this RaspberryPi 3B needs to be close to the antenna and is connected via WiFi to my home network. To process the NMEA data I’m running a SignalK server on this RaspberryPi. In addition, there is a Bosch BME280 sensor connected to measure relative (outside) humidity, barometric pressure and ambient (outside) temperature.
On another RaspberryPi (currently a Pi 4/2GB) - connected to the home LAN - I am running Home Assistant Core. Now I wanted to connect the SignalK server with the Home Assistant server to be able to exchange data between the two servers. MQTT is the protocol to achieve this and both servers offer plugins to exchange data per MQTT.
Here’s the installation to bridge SignalK server (NMEA data) and Home Assistant using signalk-mqtt-bridge and mosquitto (MQTT):
On the Rooftop RaspberryPi 3B:
- Installation of SignalK server
- Installation of plugin signalk-mqtt-bridge
- Configuration of the SignalK plugin is very simple:
On the LAN RaspberryPi 4:
- Installation of mosquitto server, follow this guide
- Installation of the HA MQTT integration - only the MQTT client is needed (i.e. RUN YOUR OWN). On an HA OS installation (and only there) you have the choice of installing an MQTT server as HA add-on, this is not needed if mosquitto has been installed on the underlying system
Now the data that I am bridging between the two systems is the following:
From HA to SK (HA pushes it to MQTT, and SK reads it from the MQTT queue):
- AISHub number of all ships in coverage from HA sensor sensor.aishub_ships_in_coverage to SK path vessels/self/environment/aishub/ships
- AISHub number of unique ships in coverage from HA sensor sensor.aishub_unique_ships to SK path vessels/self/environment/aishub/distinct
- Pool data pH-value from HA sensor sensor.oxilife_modbus_ph to SK path vessels/self/environment/pool/ph
- Pool data Redox-value from HA sensor sensor.oxilife_modbus_rx to SK path vessels/self/environment/pool/rx
- Pool data water temperature from HA sensor sensor.oxilife_modbus_wt to SK path vessels/self/environment/pool/wt
with the following set-up in /home/homeassistant/.homeassistant/automations.yaml
:
- id: Automation_MQTT
alias: SignalK keepalive
description: Automation MQTT
trigger:
- platform: time_pattern
seconds: '30'
condition: []
action:
- service: mqtt.publish
data:
topic: R/signalk/62476ad06245/keepalive
payload: '["vessels/self/#"]'
- service: mqtt.publish
data:
topic: R/signalk/07bff3446f4a/keepalive
payload: '["vessels/self/#"]'
- service: mqtt.publish
data:
topic: W/signalk/07bff3446f4a/vessels/self/environment/aishub/ships
payload_template: '{{ states(''sensor.aishub_ships_in_coverage'') }}'
- service: mqtt.publish
data:
topic: W/signalk/07bff3446f4a/vessels/self/environment/aishub/distinct
payload_template: '{{ states(''sensor.aishub_unique_ships'') }}'
- service: mqtt.publish
data:
topic: W/signalk/07bff3446f4a/vessels/self/environment/pool/ph
payload_template: '{{ states(''sensor.oxilife_modbus_ph'') }}'
- service: mqtt.publish
data:
topic: W/signalk/07bff3446f4a/vessels/self/environment/pool/rx
payload_template: '{{ states(''sensor.oxilife_modbus_rx'') }}'
- service: mqtt.publish
data:
topic: W/signalk/07bff3446f4a/vessels/self/environment/pool/wt
payload_template: '{{ states(''sensor.oxilife_modbus_wt'') }}'
mode: single
From SK to HA (SK pushes it to MQTT, and HA reads it from the MQTT queue):
- Outside barometric pressure from SK path vessels/self/environment/outside/pressure to HA sensor sensor.raspi0_32gb_lan_pressure
- Outside ambient temperature from SK path vessels/self/environment/outside/temperature to HA sensor sensor.raspi0_32gb_lan_temperature
- Outside relative humidity from SK path vessels/self/environment/outside/humidity to HA sensor sensor.raspi0_32gb_lan_humidity
with the following set-up in /home/homeassistant/.homeassistant/configuration.yaml
:
mqtt: # SignalK MQTT HA Bridge
# https://developers.home-assistant.io/docs/core/entity/sensor/
sensor:
- name: "RasPi0-32GB-LAN Pressure"
unique_id: "RasPi0-32GB-LAN_pressure"
state_topic: "N/signalk/07bff3446f4a/vessels/self/environment/outside/pressure"
value_template: "{{ value_json.value/100 }}"
unit_of_measurement: "hPa"
- name: "RasPi0-32GB-LAN Temperature"
unique_id: "RasPi0-32GB-LAN_temperature"
state_topic: "N/signalk/07bff3446f4a/vessels/self/environment/outside/temperature"
value_template: "{{ value_json.value-273.15 }}"
unit_of_measurement: "C"
- name: "RasPi0-32GB-LAN Humidity"
unique_id: "RasPi0-32GB-LAN_humidity"
state_topic: "N/signalk/07bff3446f4a/vessels/self/environment/outside/humidity"
value_template: "{{ value_json.value*100 }}"
unit_of_measurement: "%"
This set-up allows me to receive certain data from HA in SK:
and to receive at the same time SK data in HA:
On SK side I use Node-RED to modify the values into specific formats (e.g. adjust the number of decimal places). On HA side I’m using a Glance Card to display the data of my outside BME280 sensor:
A good tool to monitor the MQTT queues and which was very helpful in setting everything up is MQTT Explorer. Now this set-up works very stable and reliable.