# State of Node-RED dashboard nodes

**URL:** <https://discourse.nodered.org/t/state-of-node-red-dashboard-nodes/51942>\
**Category:** Dashboard\
**Created:** [6 October 2021 20:17 UTC](https://discourse.nodered.org/t/state-of-node-red-dashboard-nodes/51942 "2021-10-06T20:17:50Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![tmichaeltx](https://avatars.discourse-cdn.com/v4/letter/t/73ab20/32.png) [@tmichaeltx](https://discourse.nodered.org/u/tmichaeltx)\
**Post date:** [6 October 2021 20:17 UTC](https://discourse.nodered.org/t/state-of-node-red-dashboard-nodes/51942/1 "2021-10-06T20:17:50Z")

</div>

I have already often built my own mechanism to store the output from a dashboard node into a context variable and then read the current state elsewhere when I need it, but I wanted to verify this:

- **There is no way to have a change node or function node to retrieve the current state of a dashboard node (i.e. switch is on/off) unless that state was saved to a context variable upon an output from the dashboard node.**

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [6 October 2021 20:25 UTC](https://discourse.nodered.org/t/state-of-node-red-dashboard-nodes/51942/2 "2021-10-06T20:25:41Z")

</div>

Remember that the Dashboard and Node-RED run in two completely different environments, often on different devices. The only link between them is a [Socket.IO](http://Socket.IO) based websocket connection.

Also remember that a Dasboard might be open in multiple tabs/windows, possibly on multiple devices.

The way that Dashboard works is that any updates that a user makes in any instance of the Dashboard are sent to Node-RED. It is up to you to sort out where they have come from and what to do with them.

It wouldn't make sense to have Node-RED to reach out to try and get a value - which instance of the Dashboard would it get the value from? What if there were a hundred different values in different instances?

---

<div class="post-metadata">

**Author:** ![tmichaeltx](https://avatars.discourse-cdn.com/v4/letter/t/73ab20/32.png) [@tmichaeltx](https://discourse.nodered.org/u/tmichaeltx)\
**Post date:** [6 October 2021 20:29 UTC](https://discourse.nodered.org/t/state-of-node-red-dashboard-nodes/51942/3 "2021-10-06T20:29:15Z")

</div>

I always assumed that Node-Red itself knew the nodes current status. For instance imagine 1 switch node:

1. User 1 connects to dashboard and sees switch in default position (say off)
2. User 1 switches to on
3. User 2 connects to dashboard and sees the switch in its current position (now on due to change made by user 1).

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [6 October 2021 20:29 UTC](https://discourse.nodered.org/t/state-of-node-red-dashboard-nodes/51942/4 "2021-10-06T20:29:27Z")

</div>

It does not need to be saved to context, but it needs to be stored somewhere. I use MQTT retained topics to save the state of switches etc and to restore them on node-red restart. Also it could be stored in nodes such as Join nodes.

---

<div class="post-metadata">

**Author:** ![tmichaeltx](https://avatars.discourse-cdn.com/v4/letter/t/73ab20/32.png) [@tmichaeltx](https://discourse.nodered.org/u/tmichaeltx)\
**Post date:** [6 October 2021 20:36 UTC](https://discourse.nodered.org/t/state-of-node-red-dashboard-nodes/51942/5 "2021-10-06T20:36:46Z")

</div>

Here is the situation, I am looking to address. I have 3 lights (Kathy, Mike, Overhead). I am using the multiswitch to control them with Overhead also having a separate switch. Ignore the charger switch.  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/7/f7a62540280944fe7d93e8d4b8149e90b0071033.png)

When I get an update of Mike to on, then I want the multiswitch to go from off to Mike. This is easy. If however, Kathy is already on and an external input of Mike just turned on, then I need to move the switch from Kathy to both.  
So without storing the state of the multiswitch in a context variable and then using the incoming new Mike on input plus the context variable, I can't distinguish between the 2 states.

I have done this before, but wanted to make sure that there wasn't a direct line to the current state without having to manage it myself.

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [6 October 2021 20:47 UTC](https://discourse.nodered.org/t/state-of-node-red-dashboard-nodes/51942/6 "2021-10-06T20:47:13Z")

</div>

> [@tmichaeltx](#):
>
> I always assumed that Node-Red itself knew the nodes current status

Dashboard nodes _may_ store the last value I think and _may_ offer that as a cached value to new connections and _will_ send updates to all connected clients.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [6 October 2021 20:48 UTC](https://discourse.nodered.org/t/state-of-node-red-dashboard-nodes/51942/7 "2021-10-06T20:48:00Z")

</div>

Feed all the states into a Join node in key/value mode and then when any one of them changes the join node will output a message with all the current states in it so you can do what you want with the switch.

---

<div class="post-metadata">

**Author:** ![tmichaeltx](https://avatars.discourse-cdn.com/v4/letter/t/73ab20/32.png) [@tmichaeltx](https://discourse.nodered.org/u/tmichaeltx)\
**Post date:** [6 October 2021 20:49 UTC](https://discourse.nodered.org/t/state-of-node-red-dashboard-nodes/51942/8 "2021-10-06T20:49:41Z")

</div>

> [@Colin](#):
>
> Feed all the states into a Join node in key/value mode and then when any one of them changes the join node will output a message with all the current states in it so you can do what you want with the switch.

Very elegant solution to the specific case I am working on.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [6 October 2021 20:51 UTC](https://discourse.nodered.org/t/state-of-node-red-dashboard-nodes/51942/9 "2021-10-06T20:51:30Z")

</div>

The concept will work in very many situations. I virtually never use context for such issues.

---

<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:** [5 November 2021 20:52 UTC](https://discourse.nodered.org/t/state-of-node-red-dashboard-nodes/51942/10 "2021-11-05T20:52:16Z")

</div>

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