Node-red crashes when I activate a Home Assistant node

Since I upgraded node red to 10.2.0 node-red crashes and restarts (not by watchdog, it restarts in the container itself) over and over again. I then set all flows to disabled directly in the flows.json and activated the flows one after another until it crashed again. In the suspicious flow, I again started with all nodes deactivated and activated again one after another until it crashed.

The node that made node-red crash was a Home Assistant “entity” node. But the wired thing was, it is not the only “entity”-node in this flow. The other two have been activated before without crashing.

The code of the crashing node is as follows.

[{"id":"02efef8caeccc6c7","type":"ha-entity","z":"3079ee36.02c2d2","d":true,"name":"OilFox Liters Delta","server":"fbb2f3e2.d6216","version":1,"debugenabled":false,"outputs":1,"entityType":"sensor","config":[{"property":"name","value":""},{"property":"device_class","value":""},{"property":"icon","value":""},{"property":"unit_of_measurement","value":"l"}],"state":"payload","stateType":"msg","attributes":[{"property":"timeSinceChangedHours","value":"$round(data.timeSinceChangedMs / (1000 * 60 * 60), 1)","valueType":"jsonata"}],"resend":true,"outputLocation":"","outputLocationType":"none","inputOverride":"allow","outputOnStateChange":false,"outputPayload":"$entity().state ? \"on\": \"off\"","outputPayloadType":"jsonata","x":450,"y":540,"wires":[["1dfde7880bd0708c","7a5849945ad55047"]]},{"id":"fbb2f3e2.d6216","type":"server","name":"Home Assistant","version":2,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true,"heartbeat":false,"heartbeatInterval":"30"}]

This is what is written in the Log of node-red in supervisor:

6 Dec 00:01:55 - [red] Uncaught Exception:
6 Dec 00:01:55 - [error] UnhandledPromiseRejection: This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). The promise rejected with the reason "#<Object>".
[00:01:55] INFO: Starting Node-RED...

Does anybody have an idea, what is going wrong here and why it is only happening with this special node?

Thanks for any guidance in advance.

Do you know if it is crashing right after the node loads or when the node receives input?

It crashes directly after loading, no input needed.

Anything in your HA logs about the NR integration?

Can you turn on logging for the NR integration and see that node is sending over its discovery payload before the crash?

custom_components.nodered: debug

Your export node loads fine for me on the latest NR/component/HA dev branches. The only difference would be if you have a saved state being sent with the discovery message.

What version of HA/NR/component are you running?

Hi Kermit,

my versions are:
HA: core-2021.11.5
Node: 10.2.0
node-red-contrib-home-assistant-websocket: 0.38.0
node-red companion (from HACS): v0.5.4

If I would know, how to turn on the logging you asked for… Is this to be put in configuration.yaml?

custom_components.nodered: debug

Regards,
Daniel

yes

logger:
  default: info
  logs:
    custom_components.nodered: debug

You can also try the latest release 0.38.1 where I added error handling when entity nodes are registering themselves.

Thank you both! I took the fast lane and upgraded to 0.38.1.
Fortunately (or not), it told me the following:

7 Dec 00:51:59 - [error] [ha-entity:OilFox Liters Delta] Error registering entity.  Error Message: expected bool for dictionary value @ data['state']. Got None

But I have no clue, what it wants to tell me… Here is, what the GUI displays:
image

Again without receiving an input after redeploy.

This would suggest it was expecting a value of true or false. Could you just confirm that the entity node is still set to sensor.

Somehow the saved state is empty. You can attempt to fix this by unchecking the Resend State and Attributes and deploying. Then once the sensor has been updated you can recheck it and deploy it again.

I find it unusual that an error is reported because your above export of the node is of type sensor which should allow any type of state. I would expect the entity node to be of type binary sensor for that error to occur.

Hi Kermit,

unsetting the “Resend state and attributes” deploying, setting again and deploying first seemed to resolve the issue. It showed registered at for a short time, but the error appeared again in the log and the node got a red state again.

I now simply deleted the node and added a new one, copying over the settings one by one from the old node (before deleting it). Now, everything looks fine.

This is the JSON part from the malfunctioning node:

	{
		"id": "02efef8caeccc6c7",
		"type": "ha-entity",
		"z": "3079ee36.02c2d2",
		"d": true,
		"name": "OilFox Liters Delta",
		"server": "fbb2f3e2.d6216",
		"version": 1,
		"debugenabled": false,
		"outputs": 1,
		"entityType": "sensor",
		"config": [
			{
				"property": "name",
				"value": ""
			},
			{
				"property": "device_class",
				"value": ""
			},
			{
				"property": "icon",
				"value": ""
			},
			{
				"property": "unit_of_measurement",
				"value": "l"
			}
		],
		"state": "payload",
		"stateType": "msg",
		"attributes": [
			{
				"property": "timeSinceChangedHours",
				"value": "$round(data.timeSinceChangedMs / (1000 * 60 * 60), 1)",
				"valueType": "jsonata"
			}
		],
		"resend": true,
		"outputLocation": "",
		"outputLocationType": "none",
		"inputOverride": "allow",
		"outputOnStateChange": false,
		"outputPayload": "$entity().state ? \"on\": \"off\"",
		"outputPayloadType": "jsonata",
		"x": 450,
		"y": 540,
		"wires": [
			[
				"1dfde7880bd0708c",
				"7a5849945ad55047"
			]
		]
	},

And here the one from the re-generated one:

	{
		"id": "6babb94afc662a7c",
		"type": "ha-entity",
		"z": "3079ee36.02c2d2",
		"name": "OilFox Liters Delta",
		"server": "fbb2f3e2.d6216",
		"version": 1,
		"debugenabled": false,
		"outputs": 1,
		"entityType": "sensor",
		"config": [
			{
				"property": "name",
				"value": ""
			},
			{
				"property": "device_class",
				"value": ""
			},
			{
				"property": "icon",
				"value": ""
			},
			{
				"property": "unit_of_measurement",
				"value": "l"
			}
		],
		"state": "payload",
		"stateType": "msg",
		"attributes": [
			{
				"property": "timeSinceChangedHours",
				"value": "$round(data.timeSinceChangedMs / (1000 * 60 * 60), 1)",
				"valueType": "jsonata"
			}
		],
		"resend": true,
		"outputLocation": "payload",
		"outputLocationType": "none",
		"inputOverride": "allow",
		"outputOnStateChange": false,
		"outputPayload": "$entity().state ? \"on\": \"off\"",
		"outputPayloadType": "jsonata",
		"x": 410,
		"y": 540,
		"wires": [
			[
				"1dfde7880bd0708c"
			]
		]
	},

The diff is as follows (left new, right old):

I see the main difference in the d: true

Thanks for your help. Problem seems to be solved now. And this was lightning fast!!!

Same problem. Newest version of NR, newest plugin and NR is in dead loop :frowning:

If I delete plugin directory from data/mode_modules, and start NR, I cannot initiate Inject node:
image