# Changing state of input\_number in Function Node - is it possible? - Revisited

**URL:** https://discourse.nodered.org/t/changing-state-of-input-number-in-function-node-is-it-possible-revisited/32686
**Category:** General
**Created:** [10 September 2020 11:32 UTC](https://discourse.nodered.org/t/changing-state-of-input-number-in-function-node-is-it-possible-revisited/32686 "2020-09-10T11:32:31Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![Boja](https://avatars.discourse-cdn.com/v4/letter/b/3be4f8/32.png) [@Boja](https://discourse.nodered.org/u/Boja)
#### Post date: [10 September 2020 11:32 UTC](https://discourse.nodered.org/t/changing-state-of-input-number-in-function-node-is-it-possible-revisited/32686/1 "2020-09-10T11:32:32Z")

</div>

I had a post up about this "problem" a month ago, and thought it was solved. It turns out that there is still problems.

I'm doing this in a Function Node:  
&nbsp;&nbsp;var ha = global.get('homeassistant');  
&nbsp;&nbsp;ha.homeAssistant.states['input\_number.x'].state = 1;  
&nbsp;&nbsp;global.set('homeassistant', ha);

Seen from the Context Tab in Home Assistant (under Global context) the variable changes as expected, but an Event-state node (Server-Change-State) monitoring input\_number.x do not react to the change.

If input\_number.x is altered using a Call-Service-Node (Api-Call-Service) everything works fine.

What I need, is to be able to alter input\_number and input\_boolean variables using a Function Node, instead of using a Call-Service-Node.

I'm running Node-Red on Home Assistant (Hassio) - all latest versions.

Any suggestions ?

Boja.

---

<div class="post-metadata">

### Author: ![greengolfer](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/greengolfer/32/28276_2.png) [@greengolfer](https://discourse.nodered.org/u/greengolfer)
#### Post date: [10 September 2020 12:17 UTC](https://discourse.nodered.org/t/changing-state-of-input-number-in-function-node-is-it-possible-revisited/32686/2 "2020-09-10T12:17:38Z")

</div>

If you want to change the state of sensors from nodered from a function, then you would have to go via the API route. In the function node, you prepare the message and through an HTTP or HTTPS API call you can change the states.

Something like:

```auto
    sensor = 'something';
    m.url = host + "/api/states/sensor." + sensor;
    m.method = "POST";
    m.headers = {
        'Authorization': 'Bearer ' + token,
        'content-type': 'application/json',
    };    
    m.payload = {
        "state": whatever
    };
    node.send(m); //send a msg to next node

```

Followed by an HTTP(S) call.

---

<div class="post-metadata">

### Author: ![Boja](https://avatars.discourse-cdn.com/v4/letter/b/3be4f8/32.png) [@Boja](https://discourse.nodered.org/u/Boja)
#### Post date: [10 September 2020 12:43 UTC](https://discourse.nodered.org/t/changing-state-of-input-number-in-function-node-is-it-possible-revisited/32686/3 "2020-09-10T12:43:04Z")

</div>

Does it matter that the input\_number variable is just a variable defined in configuration.yaml, not a device/sensor ?.

The purpose of doing it with a function, is to avoid having a Call-Service-Node for each input\_number variable.

---

<div class="post-metadata">

### Author: ![greengolfer](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/greengolfer/32/28276_2.png) [@greengolfer](https://discourse.nodered.org/u/greengolfer)
#### Post date: [10 September 2020 12:53 UTC](https://discourse.nodered.org/t/changing-state-of-input-number-in-function-node-is-it-possible-revisited/32686/4 "2020-09-10T12:53:08Z")

</div>

I have never done it. But, looking at the documentation for input\_number, it seems that you can change it like any other "sensor".  
Why not using the Call-Service in this situation?

---

<div class="post-metadata">

### Author: ![Boja](https://avatars.discourse-cdn.com/v4/letter/b/3be4f8/32.png) [@Boja](https://discourse.nodered.org/u/Boja)
#### Post date: [10 September 2020 13:17 UTC](https://discourse.nodered.org/t/changing-state-of-input-number-in-function-node-is-it-possible-revisited/32686/5 "2020-09-10T13:17:38Z")

</div>

There is many reasons to this. One is that handling very large numbers of Call-Service-Nodes in a flow, makes Node-red WAY to slow (on a Raspberry Pi 4).

---

<div class="post-metadata">

### Author: ![greengolfer](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/greengolfer/32/28276_2.png) [@greengolfer](https://discourse.nodered.org/u/greengolfer)
#### Post date: [10 September 2020 13:22 UTC](https://discourse.nodered.org/t/changing-state-of-input-number-in-function-node-is-it-possible-revisited/32686/6 "2020-09-10T13:22:30Z")

</div>

The way I understand the communication between nodered and HA, the call service is in fact using the API under the hood (websocket call)... So, I can't imagine it is going to make a difference from that point of view between the "call service" and the API call I suggested. Never compared it though, so I might be wrong. You may want to post this on the HA community forum. "Experts" (I am not!) might have a different take on this.

---

<div class="post-metadata">

### Author: ![Boja](https://avatars.discourse-cdn.com/v4/letter/b/3be4f8/32.png) [@Boja](https://discourse.nodered.org/u/Boja)
#### Post date: [10 September 2020 13:33 UTC](https://discourse.nodered.org/t/changing-state-of-input-number-in-function-node-is-it-possible-revisited/32686/7 "2020-09-10T13:33:12Z")

</div>

Well, slow is not in regard to operation speed, that's probably fine.

---

<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: [9 November 2020 13:33 UTC](https://discourse.nodered.org/t/changing-state-of-input-number-in-function-node-is-it-possible-revisited/32686/8 "2020-11-09T13:33:12Z")

</div>

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