# Status of a switch - related if a script is running or not

**URL:** <https://discourse.nodered.org/t/status-of-a-switch-related-if-a-script-is-running-or-not/95017>\
**Category:** Dashboard\
**Tags:** node-red-dashboard, iobroker\
**Created:** [31 January 2025 04:11 UTC](https://discourse.nodered.org/t/status-of-a-switch-related-if-a-script-is-running-or-not/95017 "2025-01-31T04:11:16Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![ChrisMD](https://avatars.discourse-cdn.com/v4/letter/c/e68b1a/32.png) [@ChrisMD](https://discourse.nodered.org/u/ChrisMD)\
**Post date:** [31 January 2025 04:11 UTC](https://discourse.nodered.org/t/status-of-a-switch-related-if-a-script-is-running-or-not/95017/1 "2025-01-31T04:11:16Z")

</div>

I have a solarsystem, that is doing some battery charging stuff with scripts in iobroker.

1. script: pi controlled solarcharging
2. script: manual charging

both scripts can be switched on/off by a switch in a node-red dashboard

 ![node_Red_1](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/e/0e239a33ea2c1b9f6ee6d7a0182172ce847c455a.png)

so my system is in "auto" mode, as long as the switch "pi on/off" is in on state.

sometime, i want a manual charging by a battery charger, that i can start manually with another script. in that case, the pi script will be stopped and the charger started.

but in my dashboard, my "pi on/off" switch, dont change its state - si it looks, that both are at the "on" state.

 ![node_Red_2](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/7/a7117ff91630eef96e6086df282e3e5db7ebb2f3.png)

how do i fix that, that the switches have the status of the scripts? if enabled script, the switch should state on and vice versa.

the scripts will change its status, but the switches doesnt.

lg  
Chris

---

<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:** [31 January 2025 10:16 UTC](https://discourse.nodered.org/t/status-of-a-switch-related-if-a-script-is-running-or-not/95017/2 "2025-01-31T10:16:52Z")

</div>

You can feed the required state into the front of the switch to change it from your flow when necessary.

---

<div class="post-metadata">

**Author:** ![ChrisMD](https://avatars.discourse-cdn.com/v4/letter/c/e68b1a/32.png) [@ChrisMD](https://discourse.nodered.org/u/ChrisMD)\
**Post date:** [31 January 2025 15:18 UTC](https://discourse.nodered.org/t/status-of-a-switch-related-if-a-script-is-running-or-not/95017/3 "2025-01-31T15:18:44Z")

</div>

how? im new to node-red ^^

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [31 January 2025 15:27 UTC](https://discourse.nodered.org/t/status-of-a-switch-related-if-a-script-is-running-or-not/95017/4 "2025-01-31T15:27:36Z")

</div>

As you are a new Node-red user, can you confirm that you have installed the new dashboard `@flowfuse/node-red-dashboard` and not the outdated one `node-red-dashboard`?

The way you achieve things are slightly different between the two.

You can check by going to the hamburger menu at the top right then Manage Palette.

---

<div class="post-metadata">

**Author:** ![ChrisMD](https://avatars.discourse-cdn.com/v4/letter/c/e68b1a/32.png) [@ChrisMD](https://discourse.nodered.org/u/ChrisMD)\
**Post date:** [31 January 2025 16:44 UTC](https://discourse.nodered.org/t/status-of-a-switch-related-if-a-script-is-running-or-not/95017/5 "2025-01-31T16:44:36Z")

</div>

i have this version:

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/e/0/e0bc00ecef02ba3d5d4e6111b34ace6a1729e25e.png)

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [31 January 2025 17:57 UTC](https://discourse.nodered.org/t/status-of-a-switch-related-if-a-script-is-running-or-not/95017/6 "2025-01-31T17:57:24Z")

</div>

The appearance of a switch node can reflect message payloads sent to it.  
If the payload is boolean false, the switch _appearance_ will change so it looks off, and the status shown in the dashboard will be "off".  
if it's true, the switch will _appear_ to be on.

1. This is not the same as clicking on the switch because no message is sent on from the switch (Unless you tick the pass through box on the switch config).
2. The same thing happens if you send a payload matching the switch output payload, in this case "ON" or "OFF"

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/b/9b1f82194387178702b764641c31cac97ecc1c86.png)

```auto
[{"id":"17fc961cb50dfe80","type":"ui-switch","z":"4f13805766521cb5","name":"","label":"Switch 1","group":"a78c26d96284e55f","order":1,"width":"2","height":"1","passthru":false,"decouple":false,"topic":"switch1","topicType":"str","style":"","className":"","onvalue":"ON","onvalueType":"str","onicon":"","oncolor":"","offvalue":"OFF","offvalueType":"str","officon":"","offcolor":"","x":360,"y":320,"wires":[["ef70457f42b7719a"]]},{"id":"ef70457f42b7719a","type":"ui-text","z":"4f13805766521cb5","group":"a78c26d96284e55f","order":2,"width":"2","height":"1","name":"","label":"Last msg from 1","format":"{{msg.payload}}","layout":"row-spread","style":false,"font":"","fontSize":16,"color":"#717171","className":"","x":560,"y":320,"wires":[]},{"id":"f32c3f04d030864a","type":"ui-button","z":"4f13805766521cb5","group":"20d91987fba15c6a","name":"","label":"ON","order":1,"width":"2","height":"1","emulateClick":false,"tooltip":"","color":"","bgcolor":"","className":"","icon":"","iconPosition":"left","payload":"ON","payloadType":"str","topic":"topic","topicType":"msg","buttonColor":"","textColor":"","iconColor":"","x":150,"y":300,"wires":[["17fc961cb50dfe80"]]},{"id":"2cd03e69b3f143b6","type":"ui-button","z":"4f13805766521cb5","group":"20d91987fba15c6a","name":"","label":"OFF","order":2,"width":"2","height":"1","emulateClick":false,"tooltip":"","color":"","bgcolor":"","className":"","icon":"","iconPosition":"left","payload":"OFF","payloadType":"str","topic":"topic","topicType":"msg","buttonColor":"","textColor":"","iconColor":"","x":150,"y":340,"wires":[["17fc961cb50dfe80"]]},{"id":"e577b8e8c2c56ae1","type":"ui-button","z":"4f13805766521cb5","group":"20d91987fba15c6a","name":"","label":"true","order":3,"width":"2","height":"1","emulateClick":false,"tooltip":"","color":"","bgcolor":"","className":"","icon":"","iconPosition":"left","payload":"true","payloadType":"bool","topic":"topic","topicType":"msg","buttonColor":"","textColor":"","iconColor":"","x":150,"y":380,"wires":[["17fc961cb50dfe80"]]},{"id":"bb1054a276b982b0","type":"ui-button","z":"4f13805766521cb5","group":"20d91987fba15c6a","name":"","label":"false","order":4,"width":"2","height":"1","emulateClick":false,"tooltip":"","color":"","bgcolor":"","className":"","icon":"","iconPosition":"left","payload":"false","payloadType":"bool","topic":"topic","topicType":"msg","buttonColor":"","textColor":"","iconColor":"","x":150,"y":420,"wires":[["17fc961cb50dfe80"]]},{"id":"a78c26d96284e55f","type":"ui-group","name":"Group2","page":"a522d4a2f7307c8b","width":"4","height":"1","order":2,"showTitle":true,"className":"","visible":"true","disabled":"false"},{"id":"20d91987fba15c6a","type":"ui-group","name":"Buttons","page":"a522d4a2f7307c8b","width":"2","height":"1","order":1,"showTitle":true,"className":"red","visible":"true","disabled":"false"},{"id":"a522d4a2f7307c8b","type":"ui-page","name":"Demo","ui":"ac5e535515ebb9c6","path":"/demo","icon":"home","layout":"grid","theme":"f36403a3012e6880","order":1,"className":"","visible":"true","disabled":"false"},{"id":"ac5e535515ebb9c6","type":"ui-base","name":"My Dashboard","path":"/dashboard","includeClientData":true,"acceptsClientConfig":["ui-notification","ui-control"],"showPathInSidebar":false,"navigationStyle":"default"},{"id":"f36403a3012e6880","type":"ui-theme","name":"Default Theme","colors":{"surface":"#ffffff","primary":"#0094CE","bgPage":"#eeeeee","groupBg":"#ffffff","groupOutline":"#cccccc"},"sizes":{"pagePadding":"12px","groupGap":"12px","groupBorderRadius":"4px","widgetGap":"12px"}}]

```

You can use this so that clicking one switch ON will turn another one OFF

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/a/da348c19abc9aead62d5765f7b2acc301b271e30.png)

1. Be careful with this; if you have the pass through ticked you can make an infinite loop!
2. If the switches trigger some additional processing, you may need extra code to interrupt it.
3. Also take a look at the Button Group node which has this sort of processing built-in

---

<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:** [2 March 2025 17:58 UTC](https://discourse.nodered.org/t/status-of-a-switch-related-if-a-script-is-running-or-not/95017/7 "2025-03-02T17:58:09Z")

</div>

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