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

Hi all

Thanks in advance…

I am fairly new to HA and MQTT and I am not able to figure out what I need to put in the yaml file.
SignalK is publishing data to the MQTT successfully, and this can be seen in the MQTT HA UI as below:

Message 3 received on environment.inside.humidity at 12:08 AM:
{
    "context": "vessels.urn:mrn:signalk:uuid:b75b3a9b-0ee8-47f1-bfff-5ef890aab660",
    "path": "environment.inside.humidity",
    "value": 0.6777249908447266,
    "timestamp": "2024-08-26T16:08:05.911Z",
    "$source": "ws-venuslocal3000.192.168.15.54:3000"
}
QoS: 0 - Retain: false
Message 2 received on environment.inside.pressure at 12:08 AM:
{
    "context": "vessels.urn:mrn:signalk:uuid:b75b3a9b-0ee8-47f1-bfff-5ef890aab660",
    "path": "environment.inside.pressure",
    "value": 100727.001953125,
    "timestamp": "2024-08-26T16:08:05.909Z",
    "$source": "ws-venuslocal3000.192.168.15.54:3000"
}
QoS: 0 - Retain: false

and I have added the below to the configuration.yaml file, but I do not get any values:

mqtt: # SignalK MQTT HA Bridge
  # https://developers.home-assistant.io/docs/core/entity/sensor/
  sensor:
    - name: "SK outside Pressure"
      unique_id: "SK_out_pressure"
      state_topic: "N/signalk/b75b3a9b-0ee8-47f1-bfff-5ef890aab660/vessels/self/environment/outside/pressure"
      value_template: "{{ value_json.value/100 }}"
      unit_of_measurement: "hPa"
    - name: "SK outside Temperature"
      unique_id: "SK_out_temp"
      state_topic: "N/signalk/b75b3a9b-0ee8-47f1-bfff-5ef890aab660/vessels/self/environment/outside/temperature"
      value_template: "{{ value_json.value-273.15 }}"
      unit_of_measurement: "C"
    - name: "SK outside Humidity"
      unique_id: "SK_out_humidity"
      state_topic: "N/vessels/signalk/b75b3a9b-0ee8-47f1-bfff-5ef890aab660/vessels/self/environment/outside/humidity"
      value_template: "{{ value_json.value*100 }}"
      unit_of_measurement: "%"

how can I identify the actual name, unique ID, “state_topic”, etc. that I should use?

Thanks again

Hi andreshs1,

I think the uuid that you are using is not correct.

You use
b75b3a9b-0ee8-47f1-bfff-5ef890aab660
I think it should be
5ef890aab660

You can find the correct uuid in SignalK under Server - Plugin Config - Bridge between SignalK and MQTT:

image

The other set-up looks good on first glance - please try this change and let me know…

Hi @Thonglor
Thank you for taking the time.

OK, when I posted yesterday, I was using a different SK to MQTT plugin. In order to match exactly your instructions I have now enabled the SK MQTT bridge plugin and I see the connection successful, as when I start the listener in HA I do see the keep alive and service messages.
That being said, I am not receiving any other message from SignalK, is there some additional configuration file that I should update?

In addition, I have realized that the UUID will change everytime that the Signalk server is restarted, this will force me to update the configuration.yaml file, correct?

Thanks
Andres

OK, if you use another plugin it won’t work :wink: Your set-up must be identical to the descriptions above, not only similar.

Can you post what you receive when you enter “+/+/# ” in “Topic to subscribe to” and click on “Start Listening” in the HA MQTT integration. All SK data should actually show up as message.

Running on a Raspberry Pi the uuid is SK-installation-dependent. It will not change after re-start. It should only change if you remove ~/settings.json or run signalk-server-setup again, see here

Hello, sorry, I am back :slight_smile:
I cannot figure out how to enable the signalk-mqtt-bridge to publish the SK data into MQTT :frowning:
I see the connection being stablished and the keep alive msgs being sent regularly, but it does not send any of the vessel…

Client mosq_sub1 sending PINGREQ
Client mosq_sub1 received PINGRESP
Client mosq_sub1 sending PINGREQ
Client mosq_sub1 received PINGRESP


Sep 09 17:27:55 2024-09-09T09:27:55.125Z signalk-mqtt-bridge Plugin stopped
Sep 09 17:27:55 2024-09-09T09:27:55.136Z signalk-mqtt-bridge Plugin starting
Sep 09 17:27:55 POST /skServer/plugins/signalk-mqtt-bridge/config 200 8.382 ms - 52
Sep 09 17:27:55 2024-09-09T09:27:55.145Z signalk-mqtt-bridge MQTT connection closed
Sep 09 17:27:55 2024-09-09T09:27:55.177Z signalk-mqtt-bridge MQTT connected

See below an example of the data I have in SK, basically, I have a CerboGX that publishes all the nmea2k data for the SK in the NUC to consume, and this in turn sending it to HA (well, that was the dream…)

Do I need to modify any files to enable the publishing?

Regards
Andres

Please post a picture of your configuration of SK plugin “Bridge between SignalK data and MQTT”.

Hi there

I am missing the part that SK publishes the data to MQTT.
I have added these 3 to sensors to the mqtt.yaml file, and I see the entities created.

but there is no data coming in.

I feel so useless :frowning:

Thanks

Are you missing mqtt: above the sensor section?

My configuration.yaml looks like follows:

mqtt: # SignalK MQTT HA Bridge
  sensor:
    - name: "HO Pressure (BME280)"
      unique_id: "homeoffice_pressure"
      state_topic: "N/signalk/uuiduuiduuid/vessels/self/environment/homeoffice/pressure/d"
      value_template: "{{ value_json.value }}"
      device_class: pressure
      unit_of_measurement: "hPa"
      state_class: measurement
      icon: mdi:chart-bell-curve-cumulative

Hello

I managed to get it to work eventually, in my installation, value_json.value does not work, but value_json works

Not sure if it is because I am running HA Core and the MQTT is sitting on the Windows side

But THANKS! Truly appreciated the effort and help you have provided.

Regards
Andres

1 Like

My pleasure, have fun sailing! Looking forward to that phase of my life, too :slight_smile: