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:
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.
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.
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.
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.
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".