SignalK / signalk-server

An implementation of a Signal K central server for boats.
http://signalk.org
Apache License 2.0
317 stars 154 forks source link

RFE: SignalK integration with homeassistant or ioBroker #1374

Open mgrouch opened 2 years ago

mgrouch commented 2 years ago

SignalK integration with homeassistant would be a nice feature.

https://github.com/home-assistant/core

Probably most work is to be done on homeassistant side.

Thanks

tkurki commented 2 years ago

'Nice' is pretty vague. Any ideas about how it would work? Some example use cases? What problems would it solve?

mgrouch commented 2 years ago

Homeassistant has much bigger support community than SignalK so there is potentially better options to create dashboards.

It’s also more flexible for automation tasks, voice alerts via text to speech, integration with Alexa, Google devices.

Much easier to make voice commands

let’s say “Alexa: turn on navigation lights”

In a sense there is some overlap between homeassistant and SignalK in dashboard, timeseries data and so on

in many areas homeassistant is way ahead.

One example

https://boathackers.com/boat-energy-management-using-victron-and-home-assistant/

integrating both will open opportunities for implementing new use cases much easier without reinventing everything on SignalK side. As homeassistant gives much functionality already.

If homeassistant could find a SignalK installation like it finds other IoT devices it really opens up for more ideas.

tingles2233 commented 12 months ago

I would second this having a home assistant addon for SignalK would be great and prevent running two rpi's that one could do easily on our boat.

I don`t believe it would be a huge leap from the current docker containers to the hass docker based containers

mgrouch commented 12 months ago

I would second this having a home assistant addon for SignalK would be great and prevent running two rpi's that one could do easily on our boat.

I don`t believe it would be a huge leap from the current docker containers to the hass docker based containers

You can have just one pi with SignalK and homeassistant with BBN OS which comes with both.

https://github.com/bareboat-necessities/my-bareboat/blob/master/docs/bareboat-os.adoc#145-homeassistant

tingles2233 commented 12 months ago

While I don`t disagree it can be done with Bareboat or with Rasbian fresh install installing both. I do like the simplicity of running Home Assistant OS and it works flawless for all my other Node Red, Influx DB and other code requirements. SignalK is the only "Difficult" one requiring it to run from another machine.

I can FORCE it to be installed in a hidden container within Home Assistant OS but it can cause problems and is unsupported. A formal HA addon would solve this. I also see numerous other threads about this same request so I do know I am not alone.

tkurki commented 12 months ago

Can you help out by providing links to the numerous other threads to help people with no HA experience?

tkurki commented 12 months ago

What kind of problems?

Supported means somebody willing to support it in the open source ecosystem. This would need somebody willing to out their time in this.

tingles2233 commented 12 months ago

For sure.

Here are a few links of people asking for it and discussing the integration/addon between SignalK and Home Assistant.

https://community.home-assistant.io/t/connecting-to-signalk-server-marine-data-exchange-format/246391 https://community.home-assistant.io/t/homeassistant-integrations-for-a-boat/378857 https://community.home-assistant.io/t/nmea-2000-to-ha/84134 https://community.home-assistant.io/t/bridging-signalk-server-nmea-and-home-assistant-using-signalk-mqtt-bridge-and-mosquitto-mqtt/642640

tingles2233 commented 11 months ago

Alexbelgium has helped us out and we have a v0.1 available to test in HA.

So far things are working well with one exception of HA marking the signalk container as "stopped" during a reboot.

If anyone wants to test please check out the HA repo of alexbelgium below.

https://github.com/alexbelgium/hassio-addons

@mgrouch

tkurki commented 11 months ago

Great progress! Have you looked into device access? Namely access to socketcan, usb devices and gpio?

HEALTH url and port seem to be off? I'd use /signalk in the healt url.

Please keep us posted here about how you proceed and any problems you may encounter. Once the Add-on is stable we should include it in the SK server installation instructions as an additional method.

In addition I see these steps going forward:

mgrouch commented 11 months ago

Now each SignalK path needs to be mapped to HA sensor. Here is a list of SignalK paths

https://github.com/bareboat-necessities/my-bareboat/blob/master/homeassistant/signalk-paths.txt

Example mapping to MQTT:

https://github.com/bareboat-necessities/my-bareboat/blob/master/homeassistant/configuration.yaml

Subscribe topic:

+/+/#

Victron add-on can be coded similarly

mgrouch commented 11 months ago

@alexbelgium

It would be nice if HA could just discover SignalK via mDNS and connected to it via MQTT. SignalK has MQTT bridge plugin where it publishes all SignalK paths

https://github.com/bareboat-necessities/my-bareboat/blob/master/homeassistant/signalk-paths.txt

Those paths need to be mapped to HA sensors. and displayed on HA dashboards.

Similar integration could be done with Victron MQTT.

Also HA location needs to be set dynamically from GPS location known to SignalK. HA needs to handle unit conversions and display formatting.

alexbelgium commented 11 months ago

Hi, I'm sorry this would be the work of an Integration in HA (https://developers.home-assistant.io/docs/creating_component_index/) which is quite different from an addon (https://developers.home-assistant.io/docs/add-ons).

I do not know how to create integrations, and therefore won't be able to help there.

What the addon is doing is starting the signalk-server container within HA in a persistent manner, but it does not allow integration with HA. What can be done however is use custom sensors within HA that fetch the information from the addon (or any other available server).

mgrouch commented 11 months ago

@alexbelgium

Yes. HA SignalK integration would be more needed piece than just starting SignalK from within HA.

tkurki commented 11 months ago

EspHome uses https://github.com/esphome/esphome/blob/dev/esphome/components/api/api.proto to communicate with HA

Re: MQTT https://esphome.io/components/api.html#:~:text=The%20ESPHome%20native%20API%20has,MQTT)%3A

tkurki commented 11 months ago

discover SignalK via mDNS and connected to it via MQTT.

This is misleading - there is no way to "connect to SK via MQTT".

mgrouch commented 11 months ago

discover SignalK via mDNS and connected to it via MQTT.

This is misleading - there is no way to "connect to SK via MQTT".

@tkurki

There is. And I have done and tested it with SignalK MQTT plugin (HA bridge). See my posts above.

Here are brief instructions https://github.com/bareboat-necessities/my-bareboat/blob/master/docs/bareboat-os.adoc#1451-homeassistant-with-signalk

tkurki commented 11 months ago

@mgrouch Yes, you can add an MQTT server to SK server with a plugin. I said misleading because a plain SK Server without any additional components does not provide an MQTT interface. My no way was unclear.

Seems you are referring to signalk-mqtt-homeassisstant. It looks to be a fork of my signalk-mqtt-gateway plugin, don't know what is changed there, but definitely not under active development. I deprecated the original plugin because of multiple problems and nobody to take care of them. So I don't think that is a good way forward.

I would really appreciate input from people who are more experienced with HA internals as to what would be the best mechanism for integration in the future. What would be the place to discuss this with people with HA expertise?

@mgrouch just mapping the paths in the specification one by one to HA is not a solution, as SK is dynamic: some paths contain changeable identifiers and people can and do use whatever paths they want.

Experience from InfluxDb plugins tells me that the integrations needs a way to exclude/include certains paths and probably also downsample (send values to HA less often than there are updates in SK).

Is there support for unit conversions on the HA side? If not we should probably provide conversions on the SK side based on user preferences.

tingles2233 commented 11 months ago

@tkurki - I have been using the integration between Signalk via MQTT for over two years now, for the most part it has been flawless.

Here is the link to the node-red "pallete" as they are called which can be installed within node red on the signalk container.

https://flows.nodered.org/node/node-red-contrib-ha-mqtt (Last updated ~1 month ago)

You can then connect signalk to a data connection(example: Nema 2000), install node red on Signalk, install the above pallete, and build your flows.

The picture below is a screenshot of one of my flows page taking my ~50 nema devices over to MQTT and then into HA. From HA we setup numerous automations, visual cues, dashboards, switches and full logging into a influxDB database for long term analysis.

image

Hopefully this helps get you moving in the right direction.

mgrouch commented 11 months ago

@mgrouch Yes, you can add an MQTT server to SK server with a plugin. I said misleading because a plain SK Server without any additional components does not provide an MQTT interface. My no way was unclear.

Seems you are referring to signalk-mqtt-homeassisstant. It looks to be a fork of my signalk-mqtt-gateway plugin, don't know what is changed there, but definitely not under active development. I deprecated the original plugin because of multiple problems and nobody to take care of them. So I don't think that is a good way forward.

I would really appreciate input from people who are more experienced with HA internals as to what would be the best mechanism for integration in the future. What would be the place to discuss this with people with HA expertise?

@mgrouch just mapping the paths in the specification one by one to HA is not a solution, as SK is dynamic: some paths contain changeable identifiers and people can and do use whatever paths they want.

Experience from InfluxDb plugins tells me that the integrations needs a way to exclude/include certains paths and probably also downsample (send values to HA less often than there are updates in SK).

Is there support for unit conversions on the HA side? If not we should probably provide conversions on the SK side based on user preferences.

@tkurki

MQTT would be the most suitable protocol for HA integration IMHO. Unit conversion logically should be done on HA side (consumer of the data). There is some support (not too great)

Dynamic paths need to be made configurable. But default configuration should handle all well known paths right out-of-the-box to make it easier for users.

tedenda commented 11 months ago

Hi @tkurki

There is a discord server for Home Assistant Add-on support and development.

https://discord.gg/9rGPUusnyt

There is also a discord server for everything else regarding Home Assistant.

https://discord.gg/home-assistant

tkurki commented 11 months ago

@mgrouch since you have everything all working and figured out it seems I can stop using my time on this.

henripalmroth commented 9 months ago

Hi,

I have been recently trying to create HA local addon running SignalK from provided docker image and stumbled upon this thread. Great to see already some progress on this area.

I could give my 5 cents on the discussion. As a background I have been running quite extensive HA setups in multiple locations for multiple years. Every once in a while I have also checked what is going on marine open source scene (SignalK, Open Plotter, BBN, etc), but couldn't get anything deployed. For this summer I'm going to finally go for it to my parents' boat.

@tkurki was earlier on this discussion seeking for use cases so let me try to give few. The killer feature for us this time on the setup would be remote monitoring.

For us everything else would be bonus but SignalK is huge opportunity not to waste. Home Assistant addon would be a really nice option to manage SignalK on same hardware along with other dockered addons like MQTT server or Zigbee2MQTT. With better hardware also InfluxDB and Grafana fits easily on same setup as HA addon.

If I get this working not sure how I would utilize navigation data on HA but it is quite nice and easy to use to get some dashboards with history data. I guess we will find together some use cases for it. Critical notification on iOS: "Engine oil temp too hot!" and so on. Probably I would just dump everything from SignalK to MQTT server and then start generating sensors in HA based on needs. There is plenty of options to make unit conversions when defining these sensors. They can be really frequently updated but we just have to make sure we are not saving that once-per-second data to db. That could generate some problems. For that we could use filter sensors to get e.g. 1-10 minute averages to db.

I don't want hijack the thread but I will just share my plans on the image below and let's see if we can find together more motivation on this combination.

image

tkurki commented 9 months ago

What I've been pondering is what would be the most fruitful way to connect Signal K with HA and the other way around.

FYI there is already a custom Signal K HA add-on: https://github.com/alexbelgium/hassio-addons/tree/master/signalk.

Remote monitoring: SK and HA are fundamentally really similar, they are local data hubs. Neither provide out of the box remote monitoring, but you can do push alerts and arrange remote access with similar tools (ZeroTier, Tailscale, ngrok etc). HA provides easy to deploy add-ons, with SK you are configuring them yourself.

Both HA and SK have their own unit management methods that should/could be connected so that the end users needs to do as little as possible.

Yes, you can do everything via MQTT, but HA's integration framework makes it also possible to replicate the experience the end user has when they add a mainstream HA integration, like BTHome or Wiz: the SK server could be discovered automatically and the available SK paths made available as HA entities.

As SK Server stores only the latest values there would be clear value with HA built in history storage. As you said there's potential for problems with very frequently updating data. I remember reading somewhere that the db sqlite, but HA has also InfluxDb & Grafana as add-ons, making them easier than diy with vanilla SK server.

One potential area for fruitful cooperation would be light & power control, connecting HAs various integrations to N2K switching with SK as the middleman.

Not strictly HA, but there's also https://esphome.io/ for low code sensor & display integration that could be used directly with SK.

I think this would be great cooperation, now we just need some HA-savvy developers to push this forward!

tedenda commented 9 months ago

Home Assistant has remote access built in, via Nabu Casa. It's not free of charge, but works great. With it, Home Assistant app on iOS/MacOS/Android are always connected to the server and receives notifications and you can see all data live and control entities. You can also access Grafana and other add-ons you have installed, most likely also Signal K. If you run HA both on the boat and at home you can register both servers in HA app and easy switch between them.

ESP-Home is really great and is fully integrated in HA and is easy to use, I love it!

tkurki commented 9 months ago

Another option used in the wild is HA Node-RED integration https://zachowj.github.io/node-red-contrib-home-assistant-websocket/.

KEGustafsson commented 8 months ago

I took old signalk-mqtt-gw under upgrade process and now it can be connected to HA fine. SignalK broker can be used from HA and HA can publish back to broker. Based on Aedes, mqtt, and mqtt-jsonl-store (in-flight). Broker publish own SK deltas, but new parts are that MQTT client part can send vessels/self and vessels to other broker in addition old JSON publishing. E.g. two SK servers can be connected with MQTT.

image

Testing starts to be so much completed that I will make a PR. https://github.com/tkurki/signalk-mqtt-gw/pull/40

tkurki commented 8 months ago

signalk-mqtt-gw published as https://www.npmjs.com/package/signalk-mqtt-gw/v/2.0.0

mgrouch commented 7 months ago

Might be integration with ioBroker would be more attractive than with HomeAssistant.

There seems to be good progress already done.

https://github.com/ioBroker/ioBroker.nmea/

a video

https://youtu.be/flp_-mypbRU