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

**URL:** <https://discourse.nodered.org/t/solar-assistant-mqtt-how-to-use-it-with-node-red/67281>\
**Category:** General\
**Tags:** mqtt\
**Created:** [3 September 2022 02:31 UTC](https://discourse.nodered.org/t/solar-assistant-mqtt-how-to-use-it-with-node-red/67281 "2022-09-03T02:31:21Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![wattmatters](https://avatars.discourse-cdn.com/v4/letter/w/46a35a/32.png) [@wattmatters](https://discourse.nodered.org/u/wattmatters)\
**Post date:** [3 September 2022 02:31 UTC](https://discourse.nodered.org/t/solar-assistant-mqtt-how-to-use-it-with-node-red/67281/1 "2022-09-03T02:31:21Z")

</div>

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:

> **[SolarAssistant MQTT output](https://solar-assistant.io/help/integration/mqtt#bridge)**
>
> SolarAssistant can output your all data via MQTT to allow hobbyists and developers to build custom integrations.

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:

 ![Screen Shot 2022-09-03 at 12.11.45 pm](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/4/742eb6cc4c17fc9df4ce302e2a22ce9cf901e1aa.png)

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

 ![Screen Shot 2022-09-03 at 12.11.59 pm](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/9/394150f7f8e615657eb0a56df5602d5ef3b85c6b.png)

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

---

<div class="post-metadata">

**Author:** ![wattmatters](https://avatars.discourse-cdn.com/v4/letter/w/46a35a/32.png) [@wattmatters](https://discourse.nodered.org/u/wattmatters)\
**Post date:** [3 September 2022 02:33 UTC](https://discourse.nodered.org/t/solar-assistant-mqtt-how-to-use-it-with-node-red/67281/2 "2022-09-03T02:33:15Z")

</div>

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:

 ![Screen Shot 2022-09-03 at 12.12.11 pm](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/1/a1485c23f1a4cb336175cb2934d881f6b17d6e30.png)

 ![Screen Shot 2022-09-03 at 12.12.34 pm](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/2/8210ddf57e6d6b57c6c82e8ac385bba3a6d699aa.png)

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [3 September 2022 06:23 UTC](https://discourse.nodered.org/t/solar-assistant-mqtt-how-to-use-it-with-node-red/67281/3 "2022-09-03T06:23:21Z")

</div>

> [@wattmatters](#):
>
> If I try to trigger the node and send output to a debug mode, I just get an error:

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.

---

<div class="post-metadata">

**Author:** ![wattmatters](https://avatars.discourse-cdn.com/v4/letter/w/46a35a/32.png) [@wattmatters](https://discourse.nodered.org/u/wattmatters)\
**Post date:** [3 September 2022 06:38 UTC](https://discourse.nodered.org/t/solar-assistant-mqtt-how-to-use-it-with-node-red/67281/4 "2022-09-03T06:38:18Z")

</div>

> [@Steve-Mcl](#):
>
> 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.

 ![Screen Shot 2022-09-03 at 4.34.55 pm](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/5/c5b5ffe17007f71558fd5b73e6feaffd5261bf3a.png)

 ![Screen Shot 2022-09-03 at 4.37.32 pm](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/e/bedb6b8cf539560dcaf369c07cd28fd535d17848.png)

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [3 September 2022 06:40 UTC](https://discourse.nodered.org/t/solar-assistant-mqtt-how-to-use-it-with-node-red/67281/5 "2022-09-03T06:40:09Z")

</div>

> [@wattmatters](#):
>
> incorrectly configured.
> 
> ![Screen Shot 2022-09-03 at 4.34.55 pm](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/5/c5b5ffe17007f71558fd5b73e6feaffd5261bf3a.png)

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.

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [3 September 2022 06:43 UTC](https://discourse.nodered.org/t/solar-assistant-mqtt-how-to-use-it-with-node-red/67281/6 "2022-09-03T06:43:38Z")

</div>

Here is the basics...

[![](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/9/197caa369e0c9258b7391fff82c5b690fb290360.jpeg "Simple Node-RED and MQTT Tutorial") ](https://www.youtube.com/watch?v=LXA-Ge3-ewo)

---

<div class="post-metadata">

**Author:** ![wattmatters](https://avatars.discourse-cdn.com/v4/letter/w/46a35a/32.png) [@wattmatters](https://discourse.nodered.org/u/wattmatters)\
**Post date:** [3 September 2022 06:43 UTC](https://discourse.nodered.org/t/solar-assistant-mqtt-how-to-use-it-with-node-red/67281/7 "2022-09-03T06:43:54Z")

</div>

> [@Steve-Mcl](#):
>
> 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.

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.

---

<div class="post-metadata">

**Author:** ![wattmatters](https://avatars.discourse-cdn.com/v4/letter/w/46a35a/32.png) [@wattmatters](https://discourse.nodered.org/u/wattmatters)\
**Post date:** [3 September 2022 06:47 UTC](https://discourse.nodered.org/t/solar-assistant-mqtt-how-to-use-it-with-node-red/67281/8 "2022-09-03T06:47:19Z")

</div>

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

```auto
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

```

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [3 September 2022 06:47 UTC](https://discourse.nodered.org/t/solar-assistant-mqtt-how-to-use-it-with-node-red/67281/9 "2022-09-03T06:47:25Z")

</div>

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

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

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [3 September 2022 06:47 UTC](https://discourse.nodered.org/t/solar-assistant-mqtt-how-to-use-it-with-node-red/67281/10 "2022-09-03T06:47:46Z")

</div>

> [@wattmatters](#):
>
> All i get is a bad gateway message.
> 
> I've not clue why, what it means or how to recover

I don't use home assistant so cannot give you the answer. However, this is a very [popular topic](https://gprivate.com/60pf8) on the internet

---

<div class="post-metadata">

**Author:** ![wattmatters](https://avatars.discourse-cdn.com/v4/letter/w/46a35a/32.png) [@wattmatters](https://discourse.nodered.org/u/wattmatters)\
**Post date:** [3 September 2022 06:53 UTC](https://discourse.nodered.org/t/solar-assistant-mqtt-how-to-use-it-with-node-red/67281/11 "2022-09-03T06:53:01Z")

</div>

> [@Steve-Mcl](#):
>
> I don't use home assistant so cannot give you the answer. However, this is a very [popular topic](https://gprivate.com/60pf8) on the internet

😕

Most of that is meaningless to me unfortunately.

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [3 September 2022 07:06 UTC](https://discourse.nodered.org/t/solar-assistant-mqtt-how-to-use-it-with-node-red/67281/12 "2022-09-03T07:06:09Z")

</div>

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

 ![Untitled 1](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/7/778120a4c7d3a66f1fffece2510dcb5c0e809ee1.jpeg)

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)

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [3 September 2022 07:11 UTC](https://discourse.nodered.org/t/solar-assistant-mqtt-how-to-use-it-with-node-red/67281/13 "2022-09-03T07:11:09Z")

</div>

> [@wattmatters](#):
>
> ```auto
> 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)
> 
> ```

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](https://community.home-assistant.io/t/node-red-safe-mode-start/387204)

---

<div class="post-metadata">

**Author:** ![wattmatters](https://avatars.discourse-cdn.com/v4/letter/w/46a35a/32.png) [@wattmatters](https://discourse.nodered.org/u/wattmatters)\
**Post date:** [3 September 2022 07:34 UTC](https://discourse.nodered.org/t/solar-assistant-mqtt-how-to-use-it-with-node-red/67281/14 "2022-09-03T07:34:29Z")

</div>

> [@Steve-Mcl](#):
>
> 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.

Yes, that would be the case.

> [@Steve-Mcl](#):
>
> How to start node-red in safe mode on home assistant: [Node-red Safe mode start - Node-RED - Home Assistant Community](https://community.home-assistant.io/t/node-red-safe-mode-start/387204)

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.

 ![Screen Shot 2022-09-03 at 5.28.05 pm](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/5/f5de748cf6bb0ec37a9a9b18e1bc5827e57e543f.png)

I have now removed the offending # character.

---

<div class="post-metadata">

**Author:** ![wattmatters](https://avatars.discourse-cdn.com/v4/letter/w/46a35a/32.png) [@wattmatters](https://discourse.nodered.org/u/wattmatters)\
**Post date:** [3 September 2022 07:41 UTC](https://discourse.nodered.org/t/solar-assistant-mqtt-how-to-use-it-with-node-red/67281/15 "2022-09-03T07:41:30Z")

</div>

> [@jbudd](#):
>
> In your MQTT In node change Action to "Subscribe to single topic".
> 
> ps And get rid of birth, close and will messages for now.

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

 ![Screen Shot 2022-09-03 at 5.36.44 pm](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/b/8bd12d681d86f7de2f4ee9a7ea0e24004bd7a870.png)

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

Now to learn how to use it....

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [3 September 2022 09:02 UTC](https://discourse.nodered.org/t/solar-assistant-mqtt-how-to-use-it-with-node-red/67281/16 "2022-09-03T09:02:09Z")

</div>

This is a great tutorial that will tell you pretty much all you need to know about MQTT [MQTT Essentials - All Core Concepts explained](https://www.hivemq.com/mqtt-essentials/)

---

<div class="post-metadata">

**Author:** ![wattmatters](https://avatars.discourse-cdn.com/v4/letter/w/46a35a/32.png) [@wattmatters](https://discourse.nodered.org/u/wattmatters)\
**Post date:** [3 September 2022 09:05 UTC](https://discourse.nodered.org/t/solar-assistant-mqtt-how-to-use-it-with-node-red/67281/17 "2022-09-03T09:05:47Z")

</div>

Thanks for that, will take a look.

---

<div class="post-metadata">

**Author:** ![wattmatters](https://avatars.discourse-cdn.com/v4/letter/w/46a35a/32.png) [@wattmatters](https://discourse.nodered.org/u/wattmatters)\
**Post date:** [3 September 2022 22:42 UTC](https://discourse.nodered.org/t/solar-assistant-mqtt-how-to-use-it-with-node-red/67281/18 "2022-09-03T22:42:52Z")

</div>

> [@Colin](#):
>
> This is a great tutorial that will tell you pretty much all you need to know about MQTT [MQTT Essentials - All Core Concepts explained](https://www.hivemq.com/mqtt-essentials/)

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.

---

<div class="post-metadata">

**Author:** ![wattmatters](https://avatars.discourse-cdn.com/v4/letter/w/46a35a/32.png) [@wattmatters](https://discourse.nodered.org/u/wattmatters)\
**Post date:** [15 September 2022 11:20 UTC](https://discourse.nodered.org/t/solar-assistant-mqtt-how-to-use-it-with-node-red/67281/19 "2022-09-15T11:20:50Z")

</div>

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.

> **[SolarAssistant MQTT output](https://solar-assistant.io/help/integration/mqtt)**
>
> SolarAssistant can output your all data via MQTT to allow hobbyists and developers to build custom integrations.

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

---

<div class="post-metadata">

**Author:** ![wattmatters](https://avatars.discourse-cdn.com/v4/letter/w/46a35a/32.png) [@wattmatters](https://discourse.nodered.org/u/wattmatters)\
**Post date:** [16 September 2022 03:48 UTC](https://discourse.nodered.org/t/solar-assistant-mqtt-how-to-use-it-with-node-red/67281/20 "2022-09-16T03:48:59Z")

</div>

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.

 ![Screen Shot 2022-09-16 at 1.23.20 pm](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/1/31cfc18619985419644246843c60193fecd1fc96.png)

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

 ![Screen Shot 2022-09-16 at 1.23.53 pm](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/4/04855df11dacf7578754a201c95a9747318308ed.png)

and the settings for the MQTT out node:

 ![Screen Shot 2022-09-16 at 1.24.14 pm](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/e/de52543a3c65bf23d93dc13d17a92f130056ae64.png)

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.

[Next page](https://discourse.nodered.org/t/solar-assistant-mqtt-how-to-use-it-with-node-red/67281.md?page=2)
