Duplicating sensor entity inside a subflow on every redeploy

Hey

I’m facing some awkward behavior while using the entity node on node-red. I have this flow below:

[{"id":"99cf638.ca84ba","type":"tab","label":"Test","disabled":false,"info":""},{"id":"62ff83b9.826a2c","type":"ha-entity","z":"99cf638.ca84ba","name":"","server":"da4d7014.288ef","version":1,"debugenabled":true,"outputs":1,"entityType":"sensor","config":[{"property":"name","value":"test_sensor"},{"property":"device_class","value":""},{"property":"icon","value":""},{"property":"unit_of_measurement","value":""}],"state":"payload","stateType":"msg","attributes":[],"resend":true,"outputLocation":"","outputLocationType":"none","inputOverride":"allow","outputOnStateChange":false,"outputPayload":"$entity().state ? \"on\": \"off\"","outputPayloadType":"jsonata","x":530,"y":440,"wires":[[]]},{"id":"83b60715.0f5648","type":"inject","z":"99cf638.ca84ba","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"5","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":280,"y":440,"wires":[["62ff83b9.826a2c"]]},{"id":"da4d7014.288ef","type":"server","name":"Home Assistant","legacy":false,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true}]

It’s work like a charm (I know it doesn’t nothing, it’s just to simplify my explanation here), but if I put it in a subflow, everytime I redeploy the flows using it, a new sensor is created on the home assistant side:

2021-05-06 09:12:47 INFO (MainThread) [custom_components.nodered] Entity removed: sensor.test_sensor_5
2021-05-06 09:12:54 INFO (MainThread) [custom_components.nodered.discovery] Creating sensor da4d7014.288ef a44bfbce.7f0dc8
2021-05-06 09:12:54 INFO (MainThread) [homeassistant.helpers.entity_registry] Registered new sensor.nodered entity: sensor.test_sensor_5
2021-05-06 09:13:05 INFO (MainThread) [custom_components.nodered.discovery] Creating sensor da4d7014.288ef 3c4d3195.d83a1e
2021-05-06 09:13:05 INFO (MainThread) [homeassistant.helpers.entity_registry] Registered new sensor.nodered entity: sensor.test_sensor_6

This brings me two problems:

  • The old entities are not being removed (even if the log tells that)
  • I’m referencing the sensor on a template_light, so as it keeps appending a “_1”, “_2”, etc. the reference is lost.

https://zachowj.github.io/node-red-contrib-home-assistant-websocket/node/entity.html#home-assistant-config

WARNING

Entity nodes will not work in a subflow due to the way they register themselves with Home Assistant. After a Node-RED restart, a new entity will be created in Home Assistant.

Ok, that’s a bummer :frowning:

Thank you :slight_smile: