# How can i have a physical button that toggles a switch on the dashboard?

**URL:** https://discourse.nodered.org/t/how-can-i-have-a-physical-button-that-toggles-a-switch-on-the-dashboard/5951
**Category:** General
**Created:** [19 December 2018 07:41 UTC](https://discourse.nodered.org/t/how-can-i-have-a-physical-button-that-toggles-a-switch-on-the-dashboard/5951 "2018-12-19T07:41:11Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![IvarMvl](https://avatars.discourse-cdn.com/v4/letter/i/3e96dc/32.png) [@IvarMvl](https://discourse.nodered.org/u/IvarMvl)
#### Post date: [19 December 2018 07:41 UTC](https://discourse.nodered.org/t/how-can-i-have-a-physical-button-that-toggles-a-switch-on-the-dashboard/5951/1 "2018-12-19T07:41:11Z")

</div>

hi, i'm using NodeRed on my raspberry pi, and I have a physical button wired up to the GPIO pin and it works.

what's the easiest way to make a switch on the dashboard turn on if it's off, and vica versa, when i press the button?

---

<div class="post-metadata">

### Author: ![ukmoose](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ukmoose/32/13_2.png) [@ukmoose](https://discourse.nodered.org/u/ukmoose)
#### Post date: [19 December 2018 08:03 UTC](https://discourse.nodered.org/t/how-can-i-have-a-physical-button-that-toggles-a-switch-on-the-dashboard/5951/2 "2018-12-19T08:03:29Z")

</div>

You can change the state of a switch in the dashboard by sending it a message with either  
msg.payload = true or msg.payload = false ( note they are boolean not strings)

The easiest way is therefore probably to use a change node to change the value you are getting from your physical switch into boolean true or false, before sending that to your dashboard switch

---

<div class="post-metadata">

### Author: ![IvarMvl](https://avatars.discourse-cdn.com/v4/letter/i/3e96dc/32.png) [@IvarMvl](https://discourse.nodered.org/u/IvarMvl)
#### Post date: [19 December 2018 08:19 UTC](https://discourse.nodered.org/t/how-can-i-have-a-physical-button-that-toggles-a-switch-on-the-dashboard/5951/3 "2018-12-19T08:19:44Z")

</div>

Thank you that worked and I also had to check te pass through when msg arrives

---

<div class="post-metadata">

### Author: ![afiqkimii](https://avatars.discourse-cdn.com/v4/letter/a/e9bcb4/32.png) [@afiqkimii](https://discourse.nodered.org/u/afiqkimii)
#### Post date: [26 May 2019 14:22 UTC](https://discourse.nodered.org/t/how-can-i-have-a-physical-button-that-toggles-a-switch-on-the-dashboard/5951/4 "2019-05-26T14:22:09Z")

</div>

hi can i know the details about your project? im in the same situation also

---

<div class="post-metadata">

### Author: ![IvarMvl](https://avatars.discourse-cdn.com/v4/letter/i/3e96dc/32.png) [@IvarMvl](https://discourse.nodered.org/u/IvarMvl)
#### Post date: [29 May 2019 10:14 UTC](https://discourse.nodered.org/t/how-can-i-have-a-physical-button-that-toggles-a-switch-on-the-dashboard/5951/5 "2019-05-29T10:14:44Z")

</div>

what you want to do is connect one wire to the ground of your raspberry to the button.  
Than from the button to whatever Pin your using

 ![afbeelding](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/5/55a127664b7ea5c413ca3088e2b3b55ff641988b.png)

in Node red u want to select the Pullup resistor as seen on the foto  
The raspberry pi GPio node is needed for linking to a button or switch in node-red

that will do the trick
