Exposing Node-Red Data to Home Assistant

Hello Everyone,

So I’ve been running Home Assistant now for the last 2 years, and things have been pretty solid (minus me breaking stuff :joy:)

The primary reason for Home Assistant is to manage a PV Solar System. Here’s an overview of the current flow of data

Inverter < Banana Pi > Data > MQTT > Node-Red > Home Assistant

The Banana Pi runs a small program (solpiplog) which reads data from the inverter and passed this via MQTT over to Home Assistant.

So here’s my big question. What is the best means of getting the data from Node-Red out onto Home Assistant? At the moment, I’ve got the Node-Red companion, and can “create” sensors that public to Home Assistant. But at times, during start up, Home Assistant API doesn’t seem to be up and running, and I get a ton of error logs.

I have played around with exporting all sensor data back into MQTT, and using .yml file to read those sensors, but then I lose the UI options to manage the sensors.

So which on of the two ways, would you guys say is best to use, or what do you use if you’re also running Node-Red and needing to expose data back to Lovelace dashboard?

Without an example of your sensor code, I’m guessing here. Does this apply?

No, that’s not what I’ve got.

Current data is output to HA via the below:

The alternative is to output the data via MQTT, and then use MQTT Sensor - Home Assistant

But the MQTT sensor needs to be defined via code.

What I’ve noticed is that with the MQTT way, statistics are available (min, mean, max) but with the Node-Red way I don’t

bare with me, just eliminating things. Have you explored these with any change…

image

It sounds like you have at least set up one MQTT sensor to test.

I use dynamic sensor creation in Node Red, which are for sensors that are not reacted to in HA, because they will not exist before Node Red creates them.
I use the HA nodes to create other sensors in HA from Node Red, which makes them available from boot up.
I have not looked into statistics, but I guess it is mainly a question about getting the format correct, like making sure that the right unit of measurement is used and so on.

This is normal with restarts, it can’t connect to what is not there. It also doesn’t know it’s just HA being restarted. It has no impact on the system.

If you add a unique_id to the yaml it will be managable from the UI

As for nodered, look for the mqtt in node and drag it out to the workspace. Open it and click the little pencil, add your mqtt server info. Enter the topic of the sensor. Connect that to the sensor node. When you first open the node, select the power config you posted above. Do not go to the config page.

On the same page there is an option to add attributes. Direct them to the corresponding message paths.

edit

statistics are available (min, mean, max) but with the Node-Red way I don’t

It just matters that you set the right device class.

The type of data a sensor returns impacts how it is displayed in the frontend. This is controlled by the sensor’s device class designation.