Node Red Add on - do I need to install HACS and hass-node-red (getting error This node requires Node-RED custom integration version 1.1.0+)

Hi All

I am a long time node-red user, in fact I’ve used it significantly longer than home assistant, and I am now trying to get the 2 to work better together so that I can mix my config between the 2.

I am trying to create a home-assistant entity that is updated by my node-red flow. Currently I have the node red add on installed and working within home assistant and have home assistant events being received in node-red.

When I try to use an entity node in node-red to create a home assistant entity I get the error:

This node requires Node-RED custom integration version 1.1.0+ to be installed in Home Assistant for it to function.

I also get:

“NoConnectionError: No connection to Home Assistant”

“InputError: Integration not loaded”

from the sensor node when it tries to send a value

I have already tried to get this add on installed for my standalone install of node-red and it was a bit of a pain so in the end I gave up. I was hoping that installing the node-red add on from the official add on store would mean that I would not have to install this (which requires installation of ssl, hacs and another add on).

Currently when I search for node-red in the integrations list it does not appear. I assume that this is why I am getting the error.

So to confirm to get this to work correctly I need to:

Thanks

If you use that node, yes, you need that add-on. Personally I avoid it. Instead I have NR post messages to MQTT, and then create corresponding MQTT sensors in HA. This has the benefit that you can use MQTT Explorer (for example) to see what is going on. I like all HA entities to be managed in HA, and not automagically created by other tools.

can you share some more information how you integrate Node Red with Home Assistant via MQTT? I tried to add manually add a MQTT sensor and update it via Node Red, but it does not work. I think I am pretty shure I use the correct MQTT topic, since I use MQTT explorer to see what is published on Home Assistant.

Since you’re able to see the message in MQTT Explorer, I assume Node Red is correctly sending the message. Which means HA must not be seeing it. Can you post your definition of the MQTT Sensor? And confirm you did a reload of “manually configured MQTT entities” (or did a restart of HA).

Or are you seeing the message in MQTT Explorer because you are publishing a message from HA (either in Dev Tools or MQTT Explorer)? In this case it’s presumably Node Red not working. You just set msg.payload and msg.topic (to the MQTT topic) and pass it to the MQTT Out node.

Maybe start with the way you add a MQTT device in HA, how do you do that?

The way I add a device, is via the "MQTT’ integration, and then add Moquitto MQTT Broker and there “Add MQTT device”. I think that is not the correct way to do it? Because I do not know what you mean with “reload of manually configured MQTT entities”?

Thanks

What is working:

  • I created manually a MQTT binary sensor within HA as described above (device is “test02” and Entity “testbin”)
  • I see this MQTT device in MQTT explorer, with topic homeassistant/binary_sensor/test02_testbin/state
  • I see this state changing when I change it manually under Developer Tools/States within HA, I also see this changing when I create a MQTT node in in Node Red
  • When I create an MQTT node out in Node Red and change the value with an Inject Node within Node Red, I see the state changing in MQTT Explorer, but not in HA, so it looks that HA is not receiving it, or adapting the value.

What is wrong?

You should never set the state through Dev Tools as this is very misleading and it would be nice if they removed the ability to do so. Sensors are essentially read-only. By updating the state in HA you’re telling it the sensor has a different value, you’re not updating the sensor itself.

The “Add MQTT device” is listed in the documentation as “a work in progress”. I’ve only set up one test entity that way when it was originally released to see the capabilities. When I saw you could set the state but not the attributes of an entity, I went back to creating them manually.

In your case I’m guessing you’ve got something wrong with the value template - this is another disadvantage of creating them this way - it’s harder to share what you’ve got. It would be nice if the UI had an “Edit in YAML” option as exists for writing automations, but now I’m ranting. If you’ve left the value template empty for a binary sensor, by default the payload has to be either ON or OFF (unless you changed them). And they have to be uppercase. If they don’t match the values specified, the HA state will not change.

The manual way is to write YAML. On the assumption your configuration.yaml has the following line:

mqtt: !include mqtt.yaml

Then you could, for example, put the following in that file:

sensor:
  - name: My Test
    unique_id: my_test
    state_topic: "my/test"
    value_template: "{{ value_json.state }}"
    json_attributes_topic: "my/test"

You create (or update) the definition of this sensor in the YAML tab of Developer Tools by clicking the link to reload “Manually configured MQTT entities” (or by restarting HA).

The steps so far created the definition of the sensor, they did not give it a value, so it will currently be “undefined”. If a flow in Node Red uses an MQTT Out node to publish to the topic “my/sensor”, then this will set the value. So for example, publishing the following will set the state to “13” (all states are strings) and the attribute testattribute to “testing”.

{ "state": "13", "testattribute": "testing" }

The documentation I linked covers all of this. One final consideration is that if you restart HA, the sensor will be “unknown” until Node Red publishes another value. Since this is probably not what you want, if Node Red sets the “retain” flag to true when the publish is done, the MQTT Broker will ‘remember’ the value. Then when HA restarts and it connects to the broker, it will send the last retained value to HA (ie. no effort from Node Red at that point).

Thank you very much, will check that, did you forget to include the link to the documentation?

Many thanks, this works. Found also Integrations - Home Assistant.

One last question for know, earlier above you posted that you use MQTT to update sensors. Do you use the Home Assistant/Node Red integration (GitHub - zachowj/hass-node-red: Companion Component for node-red-contrib-home-assistant-websocket to help integrate Node-RED with Home Assistant Core) to retreive the states of the entities/events of Home Assistant in Node Red? Or are you also doing this with MQTT (even for buttons/switches?)

Thanks.