Bridging SignalK server (NMEA) and Home Assistant using signalk-mqtt-bridge and mosquitto (MQTT)

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:

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:
2023-11-18 19_48_05-Overview – Home Assistant - Iron

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.

Hi, I do not see anything published in HA, can’t understand why.

seems connected


Jan 18 08:26:08 GET /skServer/plugins 200 72.096 ms - -
Jan 18 08:26:10 2024-01-18T08:26:10.740Z signalk-mqtt-bridge Plugin stopped
Jan 18 08:26:10 2024-01-18T08:26:10.751Z signalk-mqtt-bridge Plugin starting
Jan 18 08:26:10 POST /skServer/plugins/signalk-mqtt-bridge/config 200 21.832 ms - 50
Jan 18 08:26:10 2024-01-18T08:26:10.866Z signalk-mqtt-bridge MQTT connection closed
Jan 18 08:26:10 GET /skServer/plugins 304 47.632 ms - -
Jan 18 08:26:10 2024-01-18T08:26:10.975Z signalk-mqtt-bridge MQTT connected

Tried the other signal k plugin (nqtt for home assistant), and that is publishing but the topics are separated by dots, and I can’t extract any data.

Hints?

Hi, have you set up everything like I described it in my post? The set-up is finnicky, so if there is a small deviation it might not work.

I know there are six MQTT plugins for SignalK, but the only one that i got to work properly is:
signalk-mqtt-bridge
SignalK Node server plugin that acts as a bridge between SignalK data and MQTT by Iuri Aranda
but this works reilably and the author Iuri Aranda is here on the HA forum as well.

So coming to your problem - what’s your set-up?

What you can do to start to analyse whether messages are arriving in HA is to click on “Configure” in your MQTT integration:

Then you enter “+/+/#” in “Topic to subscribe to” and click on “Start Listening”. Then all messages should show up:

thanks it was a typo in the topics, all fine

So it works now?

1 Like

yes from SK to HA all is well. Will try now to do the opposite, it’s for a boat, so can be dangerous to change things remotely, looking for “safe” ideas". Have NMEA2000 Garmin products and Victron (which I control through MQTT from Cerbo GX)

To send from HA to SK you have to set up an automation in HA that pushes the data that you wanna send to the MQTT queue as described above:

alias: SignalK data push
description: Automation MQTT
trigger:
  - platform: time_pattern
    minutes: /1
condition: []
action:
  - service: mqtt.publish
    data:
      topic: R/signalk/85fcd8b464bb/keepalive
      payload: "[\"vessels/self/#\"]"
  - service: mqtt.publish
    data:
      topic: W/signalk/85fcd8b464bb/vessels/self/environment/aishub/ships
      payload_template: "{{ states('sensor.aishub_ships_in_coverage') }}"
  - service: mqtt.publish
    data:
      topic: W/signalk/85fcd8b464bb/vessels/self/environment/aishub/distinct
      payload_template: "{{ states('sensor.aishub_unique_ships') }}"

You’ll find the neccessary identifier “85fcd8b464bb” in the SK data browser under “uuid”. And then you can see the data in SK data browser:

Unfortunately I’m not on a boat (yet) :wink:

1 Like