Integration development using existing JS code

I’d like to develop an integration for my alarm panel. I’ve written all the code in JS(it’s a nodeJS CLI app to be specific) because I didn’t plan to make it an integration in the beginning, but this code interfaces with the alarm panel and i can control it and receive data from in through MQTT in the form of JSON.

I’ve seen that HASS uses Python for integrations, so I’d like to know if I should make an addon that runs the nodeJS app and have an integration that interfaces with it via MQTT, or if there’s a way to use the JS code directly in an integration.

I’d like to avoid rewriting everything in Python as it’s almost 1000 lines of code and it would take months.

1 Like

You can put your node js application into docker and bundle it as supervisor add on. Rather than writing a custom integration to communicate with your docker, your docker can communicate with mqtt server, there is a specific way of managing entities over mqtt. Docker will be responsible for lifecycle, state and events for entities.

2 Likes

Nicomedia, come posso contattarti? Ho provato a mandarti un messaggio privato su PLC forum… qui non riesco a mandare messaggi privati e non capisco se è una limitazione di questo forum o se è un problema mio.

Please use English

Nice! Seems exactly what I need. I’d just need to write the code for the MQTT discovery and HASS would handle the rest, right?

Yes, there are some specific commands as birth to inform HA about your entity and by incoming message, HA will create entities accordingly. Most MQTT based add-ons are using this. Most popular one; zigbee2mqtt and zwave2mqtt

Another example: https://github.com/posixx/hass_addons/blob/e70b97658f4ce889a4afc89ae023112ff5994123/comfort2mqtt/comfort2.py

1 Like

Thank you so much, I’ll definitely look into this, seems like the way to go.

1 Like

How did you write the MQTT to JSON interface?
I have a protocol which has been translated in a Homebridge module, but I’d like to integrate it or control it via HA.
See https://community.home-assistant.io/t/nikobus-support/2143/9