# Type Error Cannot read undefined

**URL:** <https://discourse.nodered.org/t/type-error-cannot-read-undefined/45232>\
**Category:** General\
**Created:** [5 May 2021 19:09 UTC](https://discourse.nodered.org/t/type-error-cannot-read-undefined/45232 "2021-05-05T19:09:15Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![TurokenX](https://avatars.discourse-cdn.com/v4/letter/t/b9e5f3/32.png) [@TurokenX](https://discourse.nodered.org/u/TurokenX)\
**Post date:** [5 May 2021 19:09 UTC](https://discourse.nodered.org/t/type-error-cannot-read-undefined/45232/1 "2021-05-05T19:09:15Z")

</div>

Been working on this for a bit, started out ensuring I changed the values from my ac/dryer outputs to values that did not share similar names.

I am now having an issue with my function which compares the values to engage an on off function.  
I have a function just like this one below to adapt my dryer values, and its working properly for both of these.  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/6/56ad5f5c415ef5d80469cdf5eb24fe7b636dcacb.png)

Then we come to my compare function below. I continue to get TypeError: Cannot read property 'dry\_e/ac\_e' of undefined.  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/4/8408c27518492ec0092cc49f484eb78db7723797.png)

Any insight on this would be greatly appreciate, just learning java/node red and gotten as far as I could, appreciate your help!

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [5 May 2021 19:18 UTC](https://discourse.nodered.org/t/type-error-cannot-read-undefined/45232/2 "2021-05-05T19:18:37Z")

</div>

I guess these functions that make the AC and dry messages are in different functions?

You might need a join node it you might just need to combine the functions but it is difficult to say as you have not shared enough info.

If you make s small flow (using injects to simulate the AC/dry messages) that demonstrates the issue and post it in a reply, someone will help out.

---

<div class="post-metadata">

**Author:** ![TurokenX](https://avatars.discourse-cdn.com/v4/letter/t/b9e5f3/32.png) [@TurokenX](https://discourse.nodered.org/u/TurokenX)\
**Post date:** [5 May 2021 19:56 UTC](https://discourse.nodered.org/t/type-error-cannot-read-undefined/45232/3 "2021-05-05T19:56:28Z")

</div>

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/f/ffb8542268ec4d7d3008e494d572d99534323088.png)  
Here is the current node setup

---

<div class="post-metadata">

**Author:** ![TurokenX](https://avatars.discourse-cdn.com/v4/letter/t/b9e5f3/32.png) [@TurokenX](https://discourse.nodered.org/u/TurokenX)\
**Post date:** [5 May 2021 19:57 UTC](https://discourse.nodered.org/t/type-error-cannot-read-undefined/45232/4 "2021-05-05T19:57:00Z")

</div>

dryer function:  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/a/2a10d7566f35d4e2873399750dfbcaa68a1fd538.png)  
Dryer Output from function:  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/1/f14eb2e30aa79d3d342802a506cb256e86f359e5.png)

---

<div class="post-metadata">

**Author:** ![TurokenX](https://avatars.discourse-cdn.com/v4/letter/t/b9e5f3/32.png) [@TurokenX](https://discourse.nodered.org/u/TurokenX)\
**Post date:** [5 May 2021 19:58 UTC](https://discourse.nodered.org/t/type-error-cannot-read-undefined/45232/5 "2021-05-05T19:58:35Z")

</div>

ac function:  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/b/5beb57148f5bd11340aeab18a72065bb030da72b.png)  
ac output from function:  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/5/95dafe33e702a751642a9485ccbbd365bee5a024.png)

---

<div class="post-metadata">

**Author:** ![TurokenX](https://avatars.discourse-cdn.com/v4/letter/t/b9e5f3/32.png) [@TurokenX](https://discourse.nodered.org/u/TurokenX)\
**Post date:** [5 May 2021 20:02 UTC](https://discourse.nodered.org/t/type-error-cannot-read-undefined/45232/6 "2021-05-05T20:02:32Z")

</div>

Compare Function:  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/7/57af3a3477f115eb696e874c9d618454d52c3d66.png)  
Compare function Output:  
TypeError: Cannot read property 'ac\_e' of undefined  
TypeError: Cannot read property 'dry\_e' of undefined

Hopefully that is clearer, if i forgot any details i apologize

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [5 May 2021 20:06 UTC](https://discourse.nodered.org/t/type-error-cannot-read-undefined/45232/7 "2021-05-05T20:06:49Z")

</div>

Not really. Can you capture a message coming out of the blue nodes on the left (use a debug node and the copy button that appears under your mouse pointer when you hover over the debug message) paste them into inject nodes and export a working example flow. I can't make your flow and demonstrate how to improve it from pictures.

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [5 May 2021 20:15 UTC](https://discourse.nodered.org/t/type-error-cannot-read-undefined/45232/8 "2021-05-05T20:15:24Z")

</div>

Ps. I just want to say, I can see the problem, you definitely need a join node (set to key/value mode) if you want to try figure this out yourself.

See [this article in the cookbook](https://cookbook.nodered.org/basic/join-streams) for an example of how to join messages into one object.

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [5 May 2021 20:34 UTC](https://discourse.nodered.org/t/type-error-cannot-read-undefined/45232/9 "2021-05-05T20:34:30Z")

</div>

~~As both entities are at `msg.data.new_state.state` and your logic is `or` as in either of these will turn on /off. No need to join the messages.  
This could just be as simple as the example below.~~  
strike that I just saw the and in the lower statement.

Here is an updated version using a join. It uses the `msg.payload.data.entity_id` to join the messages. In the example they are `sensor.t81_ac_b_watts` and `sensor.t81_drier_b_watts`, they may need editing to your entity\_id's in the function node.

```auto
[{"id":"e2b74283.5c6e2","type":"inject","z":"9b3f9f31.c45298","name":"Dryer 1","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"data\":{\"entity_id\":\"sensor.t81_drier_b_watts\",\"old_state\":{\"entity_id\":\"sensor.t81_drier_b_watts\",\"state\":null,\"attributes\":{\"unit_of_measurement\":\"W\",\"friendly_name\":\"T81 Drier B Watts\",\"icon\":\"mdi:flash-circle\"},\"last_changed\":\"2021-05-06T03:27:46.134297+00:00\",\"last_updated\":\"2021-05-06T03:27:46.134297+00:00\",\"context\":{\"id\":\"c7b7478527321dd3d9a5fda8fa6f42a4\",\"parent_id\":null,\"user_id\":null},\"original_state\":\"unavailable\"},\"new_state\":{\"entity_id\":\"sensor.t81_drier_b_watts\",\"state\":1,\"attributes\":{\"unit_of_measurement\":\"W\",\"friendly_name\":\"T81 Drier B Watts\",\"icon\":\"mdi:flash-circle\"},\"last_changed\":\"2021-05-06T03:27:47.104005+00:00\",\"last_updated\":\"2021-05-06T03:27:47.104005+00:00\",\"context\":{\"id\":\"2cb5aabcdc80736d22d35bbc7d8c4e2c\",\"parent_id\":null,\"user_id\":null},\"original_state\":\"1\",\"timeSinceChangedMs\":9}},\"_msgid\":\"cc606cbb.5e02f\"}","payloadType":"json","x":100,"y":2200,"wires":[["ad8b58bf.9c7da"]]},{"id":"ad8b58bf.9c7da","type":"join","z":"9b3f9f31.c45298","name":"","mode":"custom","build":"object","property":"payload.data","propertyType":"msg","key":"payload.data.entity_id","joiner":"\\n","joinerType":"str","accumulate":true,"timeout":"","count":"2","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":350,"y":2220,"wires":[["20c3429c.6a62d6"]]},{"id":"20c3429c.6a62d6","type":"function","z":"9b3f9f31.c45298","name":"","func":"if(msg.payload.data[\"sensor.t81_ac_b_watts\"].new_state.state >= 1000 || msg.payload.data[\"sensor.t81_drier_b_watts\"].new_state.state >= 1000) {\n return {topic: \"solar_engaged\", payload: 1000};\n}else if(msg.payload.data[\"sensor.t81_ac_b_watts\"].new_state.state < 1000 && msg.payload.data[\"sensor.t81_drier_b_watts\"].new_state.state < 1000){\n return {topic: \"solar_disengaged\", payload: 0}; \n}else {\n return {topic: \"solar_disengaged\", payload: 0};\n}\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":510,"y":2220,"wires":[["6a027541.bca3a4"]]},{"id":"afa9e146.e614c8","type":"inject","z":"9b3f9f31.c45298","name":"Dryer 1001","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"data\":{\"entity_id\":\"sensor.t81_drier_b_watts\",\"old_state\":{\"entity_id\":\"sensor.t81_drier_b_watts\",\"state\":null,\"attributes\":{\"unit_of_measurement\":\"W\",\"friendly_name\":\"T81 Drier B Watts\",\"icon\":\"mdi:flash-circle\"},\"last_changed\":\"2021-05-06T03:27:46.134297+00:00\",\"last_updated\":\"2021-05-06T03:27:46.134297+00:00\",\"context\":{\"id\":\"c7b7478527321dd3d9a5fda8fa6f42a4\",\"parent_id\":null,\"user_id\":null},\"original_state\":\"unavailable\"},\"new_state\":{\"entity_id\":\"sensor.t81_drier_b_watts\",\"state\":1001,\"attributes\":{\"unit_of_measurement\":\"W\",\"friendly_name\":\"T81 Drier B Watts\",\"icon\":\"mdi:flash-circle\"},\"last_changed\":\"2021-05-06T03:27:47.104005+00:00\",\"last_updated\":\"2021-05-06T03:27:47.104005+00:00\",\"context\":{\"id\":\"2cb5aabcdc80736d22d35bbc7d8c4e2c\",\"parent_id\":null,\"user_id\":null},\"original_state\":\"1\",\"timeSinceChangedMs\":9}},\"_msgid\":\"cc606cbb.5e02f\"}","payloadType":"json","x":110,"y":2240,"wires":[["ad8b58bf.9c7da"]]},{"id":"28bb699a.8b6166","type":"inject","z":"9b3f9f31.c45298","name":"AC 1","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"data\":{\"entity_id\":\"sensor.t81_ac_b_watts\",\"old_state\":{\"entity_id\":\"sensor.t81_ac_b_watts\",\"state\":0,\"attributes\":{\"unit_of_measurement\":\"W\",\"friendly_name\":\"T81 AC B Watts\",\"icon\":\"mdi:flash-circle\"},\"last_changed\":\"2021-05-06T03:35:59.022534+00:00\",\"last_updated\":\"2021-05-06T03:35:59.022534+00:00\",\"context\":{\"id\":\"efd26752a3ee6018693141c9f16641fd\",\"parent_id\":null,\"user_id\":null},\"original_state\":\"0\"},\"new_state\":{\"entity_id\":\"sensor.t81_ac_b_watts\",\"state\":null,\"attributes\":{\"unit_of_measurement\":\"W\",\"friendly_name\":\"T81 AC B Watts\",\"icon\":\"mdi:flash-circle\"},\"last_changed\":\"2021-05-06T03:38:28.497425+00:00\",\"last_updated\":\"2021-05-06T03:38:28.497425+00:00\",\"context\":{\"id\":\"9a8ec78c5914768f665d63c82dc63b34\",\"parent_id\":null,\"user_id\":null},\"original_state\":\"unavailable\",\"timeSinceChangedMs\":89}},\"_msgid\":\"d49ce331.88412\"}","payloadType":"json","x":110,"y":2280,"wires":[["ad8b58bf.9c7da"]]},{"id":"699aeb2f.caa14c","type":"inject","z":"9b3f9f31.c45298","name":"AC 1001","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"data\":{\"entity_id\":\"sensor.t81_ac_b_watts\",\"old_state\":{\"entity_id\":\"sensor.t81_ac_b_watts\",\"state\":0,\"attributes\":{\"unit_of_measurement\":\"W\",\"friendly_name\":\"T81 AC B Watts\",\"icon\":\"mdi:flash-circle\"},\"last_changed\":\"2021-05-06T03:35:59.022534+00:00\",\"last_updated\":\"2021-05-06T03:35:59.022534+00:00\",\"context\":{\"id\":\"efd26752a3ee6018693141c9f16641fd\",\"parent_id\":null,\"user_id\":null},\"original_state\":\"0\"},\"new_state\":{\"entity_id\":\"sensor.t81_ac_b_watts\",\"state\":1001,\"attributes\":{\"unit_of_measurement\":\"W\",\"friendly_name\":\"T81 AC B Watts\",\"icon\":\"mdi:flash-circle\"},\"last_changed\":\"2021-05-06T03:38:28.497425+00:00\",\"last_updated\":\"2021-05-06T03:38:28.497425+00:00\",\"context\":{\"id\":\"9a8ec78c5914768f665d63c82dc63b34\",\"parent_id\":null,\"user_id\":null},\"original_state\":\"unavailable\",\"timeSinceChangedMs\":89}},\"_msgid\":\"d49ce331.88412\"}","payloadType":"json","x":100,"y":2320,"wires":[["ad8b58bf.9c7da"]]},{"id":"6a027541.bca3a4","type":"switch","z":"9b3f9f31.c45298","name":"","property":"payload","propertyType":"msg","rules":[{"t":"gte","v":"1000","vt":"str"},{"t":"lt","v":"1000","vt":"str"}],"checkall":"false","repair":false,"outputs":2,"x":660,"y":2220,"wires":[["97a432a4.3efc48"],["97a432a4.3efc48"]]},{"id":"97a432a4.3efc48","type":"debug","z":"9b3f9f31.c45298","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":650,"y":2160,"wires":[]}]

```

 ![Screenshot_20210505-215248](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/8/f84fe5983bcd82b8baa603fdf4829e05d7ee1421.png)

---

<div class="post-metadata">

**Author:** ![TurokenX](https://avatars.discourse-cdn.com/v4/letter/t/b9e5f3/32.png) [@TurokenX](https://discourse.nodered.org/u/TurokenX)\
**Post date:** [6 May 2021 03:39 UTC](https://discourse.nodered.org/t/type-error-cannot-read-undefined/45232/10 "2021-05-06T03:39:28Z")

</div>

Sorry for the late reply here is my flow:

```auto
[{"id":"22a897f.d306de8","type":"tab","label":"Flow 2","disabled":false,"info":""},{"id":"931bdc3f.506f1","type":"switch","z":"22a897f.d306de8","name":"","property":"payload","propertyType":"msg","rules":[{"t":"gte","v":"1000","vt":"str"},{"t":"lt","v":"1000","vt":"str"}],"checkall":"false","repair":false,"outputs":2,"x":770,"y":180,"wires":[["a3d9be8e.a85668"],["7025ccb4.170f84"]]},{"id":"917b8a1a.1b15b","type":"function","z":"22a897f.d306de8","name":"","func":"ac = msg.data.entity_id\nenergy = Number(msg.data.new_state.state)\n\nvar topic = {topic: \"Usage\", payload: energy}\n\nreturn {topic};","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":440,"y":220,"wires":[["80a82a60.ffe31"]]},{"id":"1dcd157e.c1f933","type":"function","z":"22a897f.d306de8","name":"","func":"dryer = msg.data.entity_id\nenergy = msg.data.new_state.state\n\nvar topic = {topic: \"Usage\", payload: energy}\n\nreturn {topic};","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":440,"y":140,"wires":[["80a82a60.ffe31"]]},{"id":"80a82a60.ffe31","type":"function","z":"22a897f.d306de8","name":"","func":"ac = \"AC\"\ndry = \"Dryer\"\nenergy = msg.topic.payload\n\nvar on = {topic: \"Solar Engaged\", msg: 1000}\nvar off = {topic:\"Solar Disengaged\", msg: 0}\n\n\nif (energy >= 1000)\n{\n return (on)\n Break;\n}\nelse if (energy < 1000)\n{\n return (off)\n Break;\n}\nelse\n{\n return (off);\n}","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":640,"y":180,"wires":[["931bdc3f.506f1"]]},{"id":"a3d9be8e.a85668","type":"api-call-service","z":"22a897f.d306de8","name":"Phase B Watts High","server":"42c46992.e7d5f8","version":1,"debugenabled":false,"service_domain":"switch","service":"turn_on","entityId":"switch.circut1_output","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":1040,"y":140,"wires":[[]]},{"id":"7025ccb4.170f84","type":"api-call-service","z":"22a897f.d306de8","name":"Phase B Watts Low ","server":"42c46992.e7d5f8","version":1,"debugenabled":false,"service_domain":"switch","service":"turn_off","entityId":"switch.circut1_output","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":1030,"y":220,"wires":[[]]},{"id":"8404dc0b.c02a68","type":"inject","z":"22a897f.d306de8","name":"Dryer","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"topic\":\"sensor.t81_drier_b_watts\",\"payload\":1,\"data\":{\"entity_id\":\"sensor.t81_drier_b_watts\",\"old_state\":{\"entity_id\":\"sensor.t81_drier_b_watts\",\"state\":null,\"attributes\":{\"unit_of_measurement\":\"W\",\"friendly_name\":\"T81 Drier B Watts\",\"icon\":\"mdi:flash-circle\"},\"last_changed\":\"2021-05-06T03:27:46.134297+00:00\",\"last_updated\":\"2021-05-06T03:27:46.134297+00:00\",\"context\":{\"id\":\"c7b7478527321dd3d9a5fda8fa6f42a4\",\"parent_id\":null,\"user_id\":null},\"original_state\":\"unavailable\"},\"new_state\":{\"entity_id\":\"sensor.t81_drier_b_watts\",\"state\":1,\"attributes\":{\"unit_of_measurement\":\"W\",\"friendly_name\":\"T81 Drier B Watts\",\"icon\":\"mdi:flash-circle\"},\"last_changed\":\"2021-05-06T03:27:47.104005+00:00\",\"last_updated\":\"2021-05-06T03:27:47.104005+00:00\",\"context\":{\"id\":\"2cb5aabcdc80736d22d35bbc7d8c4e2c\",\"parent_id\":null,\"user_id\":null},\"original_state\":\"1\",\"timeSinceChangedMs\":9}},\"_msgid\":\"cc606cbb.5e02f\"}","payloadType":"json","x":210,"y":140,"wires":[["1dcd157e.c1f933","400337b2.e68aa8"]]},{"id":"f2b858ca.f76b38","type":"inject","z":"22a897f.d306de8","name":"AC","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"topic\":\"sensor.t81_ac_b_watts\",\"payload\":null,\"data\":{\"entity_id\":\"sensor.t81_ac_b_watts\",\"old_state\":{\"entity_id\":\"sensor.t81_ac_b_watts\",\"state\":0,\"attributes\":{\"unit_of_measurement\":\"W\",\"friendly_name\":\"T81 AC B Watts\",\"icon\":\"mdi:flash-circle\"},\"last_changed\":\"2021-05-06T03:35:59.022534+00:00\",\"last_updated\":\"2021-05-06T03:35:59.022534+00:00\",\"context\":{\"id\":\"efd26752a3ee6018693141c9f16641fd\",\"parent_id\":null,\"user_id\":null},\"original_state\":\"0\"},\"new_state\":{\"entity_id\":\"sensor.t81_ac_b_watts\",\"state\":null,\"attributes\":{\"unit_of_measurement\":\"W\",\"friendly_name\":\"T81 AC B Watts\",\"icon\":\"mdi:flash-circle\"},\"last_changed\":\"2021-05-06T03:38:28.497425+00:00\",\"last_updated\":\"2021-05-06T03:38:28.497425+00:00\",\"context\":{\"id\":\"9a8ec78c5914768f665d63c82dc63b34\",\"parent_id\":null,\"user_id\":null},\"original_state\":\"unavailable\",\"timeSinceChangedMs\":89}},\"_msgid\":\"d49ce331.88412\"}","payloadType":"json","x":210,"y":220,"wires":[["917b8a1a.1b15b"]]},{"id":"400337b2.e68aa8","type":"debug","z":"22a897f.d306de8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":430,"y":280,"wires":[]},{"id":"42c46992.e7d5f8","type":"server","name":"Home Assistant","addon":true}]

```

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [6 May 2021 06:27 UTC](https://discourse.nodered.org/t/type-error-cannot-read-undefined/45232/11 "2021-05-06T06:27:11Z")

</div>

Hi, in order to make code more readable and importable it is important to surround your code with three backticks  
`````  
`like this`  
`````

You can edit and correct your post by clicking the pencil icon.

See this post for more details - [How to share code or flow json](https://discourse.nodered.org/t/how-to-share-code-or-flow-json/506)

---

<div class="post-metadata">

**Author:** ![TurokenX](https://avatars.discourse-cdn.com/v4/letter/t/b9e5f3/32.png) [@TurokenX](https://discourse.nodered.org/u/TurokenX)\
**Post date:** [6 May 2021 06:46 UTC](https://discourse.nodered.org/t/type-error-cannot-read-undefined/45232/12 "2021-05-06T06:46:44Z")

</div>

Did i do that right?

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [6 May 2021 09:18 UTC](https://discourse.nodered.org/t/type-error-cannot-read-undefined/45232/13 "2021-05-06T09:18:40Z")

</div>

In your function node you have:  
`dryer = msg.data.entity_id`  
if you run the flow and open up the debug output do you see msg.data.entity\_id? (hint hint)

---

<div class="post-metadata">

**Author:** ![TurokenX](https://avatars.discourse-cdn.com/v4/letter/t/b9e5f3/32.png) [@TurokenX](https://discourse.nodered.org/u/TurokenX)\
**Post date:** [6 May 2021 20:52 UTC](https://discourse.nodered.org/t/type-error-cannot-read-undefined/45232/14 "2021-05-06T20:52:18Z")

</div>

Was up pretty late but here is the working code in case anyone has to do a similar adapation:  
`[{"id":"b9b8d064.f12b2","type":"tab","label":"Automatic AC/Dryer","disabled":false,"info":""},{"id":"ed050281.a38a3","type":"server-state-changed","z":"b9b8d064.f12b2","name":"AC Phase B Watts","server":"42c46992.e7d5f8","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"sensor.t81_ac_b_watts","entityidfiltertype":"exact","outputinitially":false,"state_type":"num","haltifstate":"","halt_if_type":"num","halt_if_compare":"gte","outputs":1,"output_only_on_state_change":true,"for":"","forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"x":130,"y":160,"wires":[["e7851e47.435bf"]]},{"id":"4c2b39b7.1cddb8","type":"debug","z":"b9b8d064.f12b2","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":570,"y":240,"wires":[]},{"id":"133add48.f1a6c3","type":"server-state-changed","z":"b9b8d064.f12b2","name":"Dryer Phase B Watts","server":"42c46992.e7d5f8","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"sensor.t81_drier_b_watts","entityidfiltertype":"exact","outputinitially":false,"state_type":"num","haltifstate":"","halt_if_type":"num","halt_if_compare":"gte","outputs":1,"output_only_on_state_change":true,"for":"","forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"x":130,"y":80,"wires":[["ce0df4b7.d6428"]]},{"id":"c9a28208.a1c6","type":"switch","z":"b9b8d064.f12b2","name":"","property":"payload","propertyType":"msg","rules":[{"t":"gte","v":"1000","vt":"str"},{"t":"lt","v":"1000","vt":"str"}],"checkall":"false","repair":false,"outputs":2,"x":670,"y":120,"wires":[["358d31c4.0a4e2e"],["6da5a730.585a58"]]},{"id":"358d31c4.0a4e2e","type":"api-call-service","z":"b9b8d064.f12b2","name":"Phase B Watts High","server":"42c46992.e7d5f8","version":1,"debugenabled":false,"service_domain":"switch","service":"turn_on","entityId":"switch.circut1_output","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":880,"y":80,"wires":[[]]},{"id":"6da5a730.585a58","type":"api-call-service","z":"b9b8d064.f12b2","name":"Phase B Watts Low ","server":"42c46992.e7d5f8","version":1,"debugenabled":false,"service_domain":"switch","service":"turn_off","entityId":"switch.circut1_output","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":870,"y":160,"wires":[[]]},{"id":"e7851e47.435bf","type":"function","z":"b9b8d064.f12b2","name":"","func":"energy = msg.payload\n\nreturn {topic: \"AC\", a_e: energy};","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":300,"y":160,"wires":[["8604dc2e.bffcd"]]},{"id":"ce0df4b7.d6428","type":"function","z":"b9b8d064.f12b2","name":"","func":"energy = msg.payload\n\nreturn {topic: \"Dryer\", d_e: energy};","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":300,"y":80,"wires":[["8604dc2e.bffcd"]]},{"id":"8604dc2e.bffcd","type":"function","z":"b9b8d064.f12b2","name":"","func":"ac = \"AC\"\ndry = \"Dryer\"\n\nA_E = msg.a_e\nD_E = msg.d_e\n\nif (ac == msg.topic)\n{\n if (A_E >= 1000)\n {\n return {topic: \"Solar Engaged\", payload: 1000};\n }\n\nelse if (dry == msg.topic)\n{\n if (D_E >= 1000)\n {\n return {topic: \"Solar Engaged\", payload: 1000};\n }\n}\n}\nelse if (D_E <1000 && A_E <1000)\n{\n return {topic:\"Solar Disengaged\", payload: 0};\n}","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":460,"y":120,"wires":[["c9a28208.a1c6","4c2b39b7.1cddb8"]]},{"id":"42c46992.e7d5f8","type":"server","name":"Home Assistant","addon":true}]`

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [20 May 2021 20:52 UTC](https://discourse.nodered.org/t/type-error-cannot-read-undefined/45232/15 "2021-05-20T20:52:52Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
