node-red-contrib-home-assistant-websocket
node-red-contrib-home-assistant-websocket copied to clipboard
Uncaught Exception: TypeError: Cannot read properties of undefined
Describe the bug
Using a state changed node matching entities using a regex is causing NodeRed to crash.
The regex test returns:
switch.steves_office_switch_heat_boost switch.steves_office_switch_heat_comfort switch.steves_office_switch_heat_off switch.steves_office_switch_heat_setback switch.steves_office_switch_heat_setback_2
originally I had an entity called switch.steves_office_switch_heat_set_back but decided to rename the entity to ...setback to simplify conditional logic. Attempts to rename the entity (from NR and HA) resulted in reported duplicate and locked entities over several restarts today that have finally cleared. The setback_2 is a new node to allow me to carry on coding.
The four entities are created by the switch entity node (node-red-contrib-home-assistant-websocket : ha-switch) used to simulate a set of four radio buttons.
This was stable, today I attempted to rename an entity and I have the idea that changing the entity_id is not synchronised between node red and home assistant.
18 Feb 15:03:21 - [info]
Welcome to Node-RED
===================
18 Feb 15:03:21 - [info] Node-RED version: v3.1.5
18 Feb 15:03:21 - [info] Node.js version: v18.19.0
18 Feb 15:03:21 - [info] Linux 6.1.63-haos-raspi arm64 LE
18 Feb 15:03:22 - [info] Loading palette nodes
18 Feb 15:03:23 - [info] Node-RED Contrib Theme Collection version: v3.1.9
18 Feb 15:03:26 - [info] Dashboard version 3.6.1 started at /endpoint/ui
18 Feb 15:03:29 - [info] Settings file : /etc/node-red/config.js
18 Feb 15:03:29 - [info] Context store : 'default' [module=memory]
18 Feb 15:03:29 - [info] User directory : /config/
18 Feb 15:03:29 - [warn] Projects disabled : editorTheme.projects.enabled=false
18 Feb 15:03:29 - [info] Flows file : /config/flows.json
18 Feb 15:03:29 - [info] Server now running at http://127.0.0.1:46836/
[15:03:29] INFO: Starting NGinx...
18 Feb 15:03:30 - [info] Starting flows
18 Feb 15:03:33 - [info] Started flows
18 Feb 15:03:33 - [info] [server:Home Assistant] Connecting to http://supervisor/core
18 Feb 15:03:34 - [info] [server:Home Assistant BasAdmin] Connecting to http://supervisor/core
18 Feb 15:03:34 - [info] [server:Home Assistant] Connected to http://supervisor/core
18 Feb 15:03:34 - [info] [server:Home Assistant BasAdmin] Connected to http://supervisor/core
18 Feb 15:04:14 - [red] Uncaught Exception:
18 Feb 15:04:14 - [error] TypeError: Cannot read properties of undefined (reading 'heating')
at /opt/node_modules/@node-red/util/lib/util.js:430:29
at Array.reduce (<anonymous>)
at getObjectProperty (/opt/node_modules/@node-red/util/lib/util.js:429:18)
at Object.getMessageProperty (/opt/node_modules/@node-red/util/lib/util.js:401:12)
at NodeRedContextService.get (/config/node_modules/node-red-contrib-home-assistant-websocket/dist/common/services/NodeRedContextService.js:36:39)
at ComparatorService.getComparatorResult (/config/node_modules/node-red-contrib-home-assistant-websocket/dist/common/services/ComparatorService.js:39:98)
at GetEntities.getComparatorResult (/config/node_modules/node-red-contrib-home-assistant-websocket/dist/nodes/BaseNode.js:128:39)
at /config/node_modules/node-red-contrib-home-assistant-websocket/dist/nodes/get-entities/controller.js:114:47
at Array.reduce (<anonymous>)
at GetEntities.onInput (/config/node_modules/node-red-contrib-home-assistant-websocket/dist/nodes/get-entities/controller.js:108:52)
[15:04:14] INFO: Service Node-RED exited with code 1 (by signal 0)
s6-rc: info: service legacy-services: stopping
s6-rc: info: service legacy-services successfully stopped
s6-rc: info: service nginx: stopping
[15:04:14] INFO: Service NGINX exited with code 0 (by signal 0)
s6-rc: info: service nginx successfully stopped
s6-rc: info: service init-nginx: stopping
s6-rc: info: service nodered: stopping
s6-rc: info: service nodered successfully stopped
s6-rc: info: service init-nodered: stopping
s6-rc: info: service init-nginx successfully stopped
s6-rc: info: service init-nodered successfully stopped
s6-rc: info: service init-customizations: stopping
s6-rc: info: service init-customizations 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 base-addon-log-level: stopping
s6-rc: info: service fix-attrs successfully stopped
s6-rc: info: service base-addon-log-level successfully stopped
s6-rc: info: service base-addon-banner: stopping
s6-rc: info: service base-addon-banner successfully stopped
s6-rc: info: service s6rc-oneshot-runner: stopping
s6-rc: info: service s6rc-oneshot-runner successfully stopped
Disabling the state changed node prevents this crash the next time one of the matching switches is turned on.
To Reproduce
Create a switch node, deploy it.
Refer to the switch node in an events all node.
Rename the entity if of the switch node
Turn the switch on
Expected behavior
An error message, not a node red crash restart.
Screenshots
Example Flow
[{"id":"46521d02505d6ea7","type":"ha-switch","z":"12b919271b59722d","g":"448078f89b50756a","name":"off","version":0,"debugenabled":false,"inputs":0,"outputs":2,"entityConfig":"0c94a3a8bae58dc6","enableInput":false,"outputOnStateChange":true,"outputProperties":[{"property":"entityId","propertyType":"msg","value":"switch.steves_office_switch_heat_off","valueType":"str"}],"x":170,"y":4140,"wires":[["75369883853df271","b2383961a57ffb09","fcee452cc8f1d099"],[]]},{"id":"aa8388ed3f918558","type":"ha-switch","z":"12b919271b59722d","d":true,"g":"448078f89b50756a","name":"set back","version":0,"debugenabled":false,"inputs":0,"outputs":2,"entityConfig":"120c1877e3f7732c","enableInput":false,"outputOnStateChange":true,"outputProperties":[{"property":"entityId","propertyType":"msg","value":"switch.steves_office_switch_heat_setback","valueType":"str"}],"x":200,"y":4260,"wires":[["cbb8b2b6dfca5a18","b2383961a57ffb09","fcee452cc8f1d099"],[]]},{"id":"2fd108f9b903a013","type":"ha-switch","z":"12b919271b59722d","g":"448078f89b50756a","name":"warm","version":0,"debugenabled":false,"inputs":0,"outputs":2,"entityConfig":"391c5289cfd48f8d","enableInput":false,"outputOnStateChange":true,"outputProperties":[{"property":"entityId","propertyType":"msg","value":"switch.steves_office_switch_heat_comfort","valueType":"str"}],"x":170,"y":4320,"wires":[["50f964910831c6c7","b2383961a57ffb09","fcee452cc8f1d099"],[]]},{"id":"623cdb2e64b410d0","type":"ha-switch","z":"12b919271b59722d","g":"448078f89b50756a","name":"boost","version":0,"debugenabled":false,"inputs":0,"outputs":2,"entityConfig":"098487e6c83099a9","enableInput":false,"outputOnStateChange":true,"outputProperties":[{"property":"entityId","propertyType":"msg","value":"switch.steves_office_switch_heat_boost","valueType":"str"}],"x":170,"y":4380,"wires":[["5c72a8ca78628afd","b2383961a57ffb09","fcee452cc8f1d099"],[]]},{"id":"5627f2f445b14561","type":"ha-switch","z":"12b919271b59722d","g":"448078f89b50756a","name":"set back new","version":0,"debugenabled":false,"inputs":0,"outputs":2,"entityConfig":"65842c2ad8adb03c","enableInput":false,"outputOnStateChange":true,"outputProperties":[{"property":"entityId","propertyType":"msg","value":"switch.steves_office_switch_heat_setback_2","valueType":"str"}],"x":190,"y":4200,"wires":[["b2383961a57ffb09","cbb8b2b6dfca5a18","fcee452cc8f1d099"],[]]},{"id":"8c3f924288f27d54","type":"server-state-changed","z":"12b919271b59722d","d":true,"name":"","server":"2be748d3.da7088","version":5,"outputs":2,"exposeAsEntityConfig":"","entityId":"switch.steves_office_switch_heat*","entityIdType":"regex","outputInitially":false,"stateType":"str","ifState":"on","ifStateType":"str","ifStateOperator":"is","outputOnlyOnStateChange":false,"for":"0","forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"data","propertyType":"msg","value":"","valueType":"eventData"},{"property":"payload","propertyType":"msg","value":"$split(data.entity_id, \"_\")[-1]","valueType":"jsonata"}],"x":310,"y":5140,"wires":[["76a792182baa9a75"],[]]},{"id":"58858e4b4a7eb327","type":"server-state-changed","z":"12b919271b59722d","d":true,"name":"","server":"2be748d3.da7088","version":5,"outputs":1,"exposeAsEntityConfig":"","entityId":"switch.steves_office_switch_heat*","entityIdType":"regex","outputInitially":false,"stateType":"str","ifState":"","ifStateType":"str","ifStateOperator":"is","outputOnlyOnStateChange":true,"for":"0","forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"triggerId"}],"x":290,"y":5200,"wires":[["76a792182baa9a75"]]},{"id":"76a792182baa9a75","type":"function","z":"12b919271b59722d","d":true,"name":"TODO Fix _2","func":"\nvar payload = msg.payload.split('_').pop();\n\nif ( payload == '2' )\n msg.payload = 'setback';\n\nreturn msg;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":670,"y":5140,"wires":[["276febd8c0a9465d","b2aca8336ebd50db"]]},{"id":"276febd8c0a9465d","type":"debug","z":"12b919271b59722d","d":true,"name":"debug 2490","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":990,"y":5140,"wires":[]},{"id":"0c94a3a8bae58dc6","type":"ha-entity-config","server":"2be748d3.da7088","deviceConfig":"d370aa2c653d8c50","name":"switch.steves_office_heating_off","version":"6","entityType":"switch","haConfig":[{"property":"name","value":"Steve's Office Switch Heat Off"},{"property":"icon","value":""},{"property":"entity_category","value":""},{"property":"entity_picture","value":""},{"property":"device_class","value":""}],"resend":false,"debugEnabled":false},{"id":"120c1877e3f7732c","type":"ha-entity-config","server":"2be748d3.da7088","deviceConfig":"","name":"switch.steves_office_switch_heat_setback","version":"6","entityType":"switch","haConfig":[{"property":"name","value":"Steve's Office Switch Heat Set Back"},{"property":"icon","value":""},{"property":"entity_category","value":""},{"property":"entity_picture","value":""},{"property":"device_class","value":""}],"resend":false,"debugEnabled":false},{"id":"391c5289cfd48f8d","type":"ha-entity-config","server":"2be748d3.da7088","deviceConfig":"d370aa2c653d8c50","name":"switch.steves_office_heating_comfort","version":"6","entityType":"switch","haConfig":[{"property":"name","value":"Steve's Office Switch Heat Comfort"},{"property":"icon","value":""},{"property":"entity_category","value":""},{"property":"entity_picture","value":""},{"property":"device_class","value":""}],"resend":false,"debugEnabled":false},{"id":"098487e6c83099a9","type":"ha-entity-config","server":"2be748d3.da7088","deviceConfig":"d370aa2c653d8c50","name":"switch.steves_office_heating_boost","version":"6","entityType":"switch","haConfig":[{"property":"name","value":"Steve's Office Switch Heat Boost"},{"property":"icon","value":""},{"property":"entity_category","value":""},{"property":"entity_picture","value":""},{"property":"device_class","value":""}],"resend":false,"debugEnabled":false},{"id":"65842c2ad8adb03c","type":"ha-entity-config","server":"2be748d3.da7088","deviceConfig":"","name":"switch.steves_office_switch_heat_setback2","version":"6","entityType":"switch","haConfig":[{"property":"name","value":"Steves Office Switch Heat Setback 2"},{"property":"icon","value":""},{"property":"entity_category","value":""},{"property":"entity_picture","value":""},{"property":"device_class","value":""}],"resend":false,"debugEnabled":false},{"id":"2be748d3.da7088","type":"server","name":"Home Assistant","addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"","connectionDelay":false,"cacheJson":false,"heartbeat":true,"heartbeatInterval":"10","statusSeparator":"","enableGlobalContextStore":false},{"id":"d370aa2c653d8c50","type":"ha-device-config","name":"Steve's Office Heating Selector","hwVersion":"","manufacturer":"Steve","model":"","swVersion":""}]
Environment Information
HA Yellow Version: 17.0.7
Home Assistant version: 2024.1.5 Companion version: 3.1.3
Node-RED version: Docker: no Add-on: no
Node.js version: OS:
Additional context
No response
Update your Home Assistant nodes and see if the problems persist.
Updated to HA 2024.2.3, all NodeRed related maintenance was already on latest version. Could not reproduce the problem though.
This issue has been automatically marked as abandoned because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.