Solar Assistant MQTT - How to use it with Node Red?

Hi, I'm very new to Node Red and on the wrong end of the learning curve. Hoping for some help to understand how to read data from and send instructions via MQTT.

Node-RED Current version: 13.3.2 (running inside Home Assistant).

I have an off-grid Solar PV and battery system which is monitored and partly controlled with Solar Assistant, which resides on a dedicated Raspberry Pi. It enables communication of key system data as well as control of some functions of the inverter and charge controller.

Solar Assistant uses MQTT to interface with Home Assistant, and that works well. This is their help page on setting it up:

I am hoping with the aid of Node Red (rather than Home Assistant) to deign some automations for managing the solar PV/battery system and figured it made sense to read and send instructions via the MQTT directly with Node Red, instead of via HA.

But I know little of how it works. This is what I have so far:

The node shows a green "connected" indicator which I'm taking as a good sign. The node has the following properties/set up:

But that's about it. If I try to trigger the node and send output to a debug mode, I just get an error:

"Error: Invalid action specified"

And that's about as far as I've got.

I'd be grateful for any tips, clues or suggestions to make sense of it.

Thanks

and to add to the above, if I click the edit option in the node editor here are some more details of what I have set up so far:

This is not how MQTT works. It is a publish subscribe protocol. In other words, you simply subscribe to a topic & messages will arrive when a publisher publishes. I.e. you do not ask for messages (with an inject node) you get them when sent by a publisher.

Add an MQTT in node, select the broker, set the topic to #, press done, connect a debug node to the output of the MQTT node, deploy.

Thanks.

You'll have to forgive my ignorance. When I enter in a hash symbol in the topic field, the field turns red and when I attempt to deploy Node Red tells me the node in incorrectly configured.

That is the birth message for the broker connection not the mqtt in node topic to subscribe to.

When you first open the mqtt in node, there is an empty topic, put the # in there.

Here is the basics...

OK thanks. Unfortunately it has broken my Node Red and I am unable to access it at all now. All i get is a bad gateway message.

I've not clue why, what it means or how to recover.

This is the log entry. Make little sense to me.

3 Sep 16:41:49 - [info] Node-RED version: v3.0.2
3 Sep 16:41:49 - [info] Node.js  version: v16.16.0
3 Sep 16:41:49 - [info] Linux 5.15.32-v8 arm64 LE
3 Sep 16:41:50 - [info] Loading palette nodes
3 Sep 16:41:57 - [info] Dashboard version 3.1.7 started at /endpoint/ui
3 Sep 16:41:59 - [info] Settings file  : /etc/node-red/config.js
3 Sep 16:41:59 - [info] Context store  : 'default' [module=memory]
3 Sep 16:41:59 - [info] User directory : /config/node-red/
3 Sep 16:41:59 - [warn] Projects disabled : editorTheme.projects.enabled=false
3 Sep 16:41:59 - [info] Flows file     : /config/node-red/flows.json
3 Sep 16:41:59 - [info] Server now running at http://127.0.0.1:46836/
3 Sep 16:41:59 - [info] Starting flows
[16:42:00] INFO: Starting NGinx...
3 Sep 16:42:00 - [info] Started flows
3 Sep 16:42:00 - [info] [mqtt-broker:Solar Assistant MQTT] Connected to broker: mqtt://192.168.0.102:1883
3 Sep 16:42:00 - [red] Uncaught Exception:
3 Sep 16:42:00 - [error] TypeError: done is not a function
    at MQTTBrokerNode.node.publish (/opt/node_modules/@node-red/nodes/core/network/10-mqtt.js:1001:21)
    at MqttClient.<anonymous> (/opt/node_modules/@node-red/nodes/core/network/10-mqtt.js:785:34)
    at MqttClient.emit (node:events:539:35)
    at Readable.<anonymous> (/opt/node_modules/mqtt/lib/client.js:1863:14)
    at Readable.emit (node:events:527:28)
    at endReadableNT (/opt/node_modules/readable-stream/lib/_stream_readable.js:1094:12)
    at processTicksAndRejections (node:internal/process/task_queues:83:21)
[16:42:00] WARNING: Node-RED crashed, halting add-on
s6-rc: info: service legacy-services: stopping
[16:42:00] INFO: Node-RED stoped, restarting...
[16:42:00] INFO: Node-RED stoped, restarting...
s6-svwait: fatal: supervisor died
s6-rc: info: service legacy-services successfully stopped
s6-rc: info: service legacy-cont-init: stopping
s6-rc: info: service legacy-cont-init successfully stopped
s6-rc: info: service fix-attrs: stopping
s6-rc: info: service fix-attrs successfully stopped
s6-rc: info: service s6rc-oneshot-runner: stopping
s6-rc: info: service s6rc-oneshot-runner successfully stopped

In your MQTT In node change Action to "Subscribe to single topic".

ps And get rid of birth, close and will messages for now.

I don't use home assistant so cannot give you the answer. However, this is a very popular topic on the internet

:confused:

Most of that is meaningless to me unfortunately.

If Node-red is crashing you have to start it in safe mode. For me that's node-red safe at the command line.
You should be able to load the editor and delete things till it will work. Probably that means deleting your MQTT broker.

Once it's running again, define a new broker.
Use a simple flow like this to get it working. Note no input wires to MQTT-n

The inject node sets msg.topic to test/inject
MQTT out has topic blank (because it's in the message)
MQTT in has topic test/# (ie subscribe to test/everything)

This error should be handled in node-red however I know why its happened - you still have # in the birth topic & you have deployed. So when node-red runtime starts the node, it tries to send a birth message on an invalid topic.

In basic terms, if you start node-red in safe mode, you can remove that "bad topic" from the birth setting.

How to start node-red in safe mode on home assistant: Node-red Safe mode start - Node-RED - Home Assistant Community

Yes, that would be the case.

I have it back, thanks for the tip!

I added the safe mode option to config, restarted NR but got the same error. But it just needed a bit of time it seems and after a bit it came back up.

I have now removed the offending # character.

Thanks. I have made that change and the debug window is not getting a constant stream of messages from my Solar Assistant.

Also manage to get it to just provide a stream of data from one parameter.

Now to learn how to use it....

This is a great tutorial that will tell you pretty much all you need to know about MQTT MQTT Essentials - All Core Concepts explained

Thanks for that, will take a look.

Just wanted to say I've read the first two of this ten part series and the introductions are well written and I'm finding them helpful.

MQTT, at least in a very rudimentary way, makes a bit more sense to me today than it did yesterday. Much to learn, thanks again for the link.

2 Likes

Just bumping this thread as I expect some more discussion shortly and I don't want it closed just yet.

Solar Assistant have released a little more info on the MQTT protocols they require.

But I am still deciphering on how to use with Node Red.

OK, it sometimes works, but often not. Which is pretty frustrating.

I have the following occasionally working, most of the time it doesn't.

When it does work the response time to confirm the setting was accepted and saved is long, might take a minute, sometimes 5 minutes. Mostly I get nothing and my inverter does not change mode of operation.

I have various inject nodes, two to change the Charger Source Priority and two to change the Output Source Priority.

These pass the relevant command to the MQTT-out node.

When the Solar Assistant system receives and saves the command, it publishes a string to the MQTT broker saying "Saved".

This is picked up and displayed by the MQTT-in node listening for the response message. I confirm this node works. When a command has been successfully sent to Solar Assistant it does indeed respond with "Saved".

Here is the sequence.

And the settings for the Set to Solar Only Charging inject node:

and the settings for the MQTT out node:

Now I have triggered this sequence and it sometimes works, but often it doesn't.

I have no clue as to why it mostly doesn't work but occasionally does.