# Reading values of variables - Error undefined

**URL:** <https://discourse.nodered.org/t/reading-values-of-variables-error-undefined/74542>\
**Category:** General\
**Tags:** function-node, home-assistant\
**Created:** [1 February 2023 09:56 UTC](https://discourse.nodered.org/t/reading-values-of-variables-error-undefined/74542 "2023-02-01T09:56:49Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![kravalli](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/kravalli/32/75357_2.png) [@kravalli](https://discourse.nodered.org/u/kravalli)\
**Post date:** [1 February 2023 09:56 UTC](https://discourse.nodered.org/t/reading-values-of-variables-error-undefined/74542/1 "2023-02-01T09:56:50Z")

</div>

Hi,

I am trying to read the value of an input\_text from homeassistant. The value my function node is returning is "undefined".

```auto
var temp1 = global.get("homeassistant.homeAssistant.states['input_text.temp_1'].state");

var newMsg = { payload: temp1};

return newMsg;

```

I have tried another method:

```auto
var states = global.get('homeassistant.homeAssistant.states');

var temp1 = states["input_text.temp_1"].state;

var newMsg = {payload: temp1};

return newMsg;

```

However this just gives me this error:  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/3/d33fbe9994a390809d81f670d9cd1d5893f6dfed.png)

---

<div class="post-metadata">

**Author:** ![marcus-j-davies](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marcus-j-davies/32/103435_2.png) [@marcus-j-davies](https://discourse.nodered.org/u/marcus-j-davies)\
**Post date:** [1 February 2023 10:03 UTC](https://discourse.nodered.org/t/reading-values-of-variables-error-undefined/74542/2 "2023-02-01T10:03:40Z")

</div>

Hi

What is in your global context?  
if nothing, but you expect there to be, then you may need to seek support from the HA Community.

 ![Screenshot 2023-02-01 at 10.01.48](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/0/703d35ee8e269c43e80921c686fc7294b3d6d491.png)

---

<div class="post-metadata">

**Author:** ![kravalli](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/kravalli/32/75357_2.png) [@kravalli](https://discourse.nodered.org/u/kravalli)\
**Post date:** [1 February 2023 10:23 UTC](https://discourse.nodered.org/t/reading-values-of-variables-error-undefined/74542/3 "2023-02-01T10:23:28Z")

</div>

I have some context there and it reports the state but it is still undefined in the debug menu. Although as you can see in the context menu there is a value.

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/6/765ac5d65ac313e9e2bf1f7f39df8036f86075dd.png)  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/7/7739d04dd9e24e5c0fd449cc78ac21abf78df1a5.png)

---

<div class="post-metadata">

**Author:** ![kravalli](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/kravalli/32/75357_2.png) [@kravalli](https://discourse.nodered.org/u/kravalli)\
**Post date:** [1 February 2023 10:26 UTC](https://discourse.nodered.org/t/reading-values-of-variables-error-undefined/74542/4 "2023-02-01T10:26:01Z")

</div>

Now that I typed that message I saw my error. In the function I wrote homeassistant.homeAssistant, but as you can see in the context menu it's homeassistant.hA.

Thanks

---

<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:** [15 February 2023 10:26 UTC](https://discourse.nodered.org/t/reading-values-of-variables-error-undefined/74542/5 "2023-02-15T10:26:36Z")

</div>

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