# In the same button come on a lock/unlock

**URL:** <https://discourse.nodered.org/t/in-the-same-button-come-on-a-lock-unlock/74490>\
**Category:** Dashboard\
**Created:** [31 January 2023 15:02 UTC](https://discourse.nodered.org/t/in-the-same-button-come-on-a-lock-unlock/74490 "2023-01-31T15:02:36Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![amine1](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/amine1/32/80570_2.png) [@amine1](https://discourse.nodered.org/u/amine1)\
**Post date:** [31 January 2023 15:02 UTC](https://discourse.nodered.org/t/in-the-same-button-come-on-a-lock-unlock/74490/1 "2023-01-31T15:02:36Z")

</div>

hi every one , my question is how i can creat a push button that combine two differents states (when i push it ,the icon UNLOCK come on ,and the LOCK come on when i push the second time ) in the normal case the button is locked ,i tried to do that by making a function node which the input for it ,the payload coming from the output of the button when i click on it ,a msg sent to it ,and in this function i made some conditions ,i tried to make a static counter in this function however anything happen ,(the icon and the payload intented is working well )

note: outputBUtton is linked to the input function and vise-versa

---

<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 2023 15:38 UTC](https://discourse.nodered.org/t/in-the-same-button-come-on-a-lock-unlock/74490/2 "2023-01-31T15:38:26Z")

</div>

Hello @amine1.

Are you talking about a Node-red dashboard button?

 ![Untitled 1](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/f/0f0ac139515c393cb2fe020e28882b8902d0c9de.jpeg)

```auto
[{"id":"1feefcdebb5a9145","type":"ui_button","z":"728eca0c6ed52fad","name":"","group":"a6e358b.672ffa8","order":0,"width":"2","height":"1","passthru":false,"label":"button","tooltip":"","color":"","bgcolor":"","className":"","icon":"{{myicon}}","payload":"toggle","payloadType":"str","topic":"topic","topicType":"msg","x":490,"y":360,"wires":[["3f437fac800bf596","7aa5d8ce5322d823"]]},{"id":"6a54132a78a841b8","type":"change","z":"728eca0c6ed52fad","name":"","rules":[{"t":"set","p":"myicon","pt":"msg","to":"alarm_off","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":480,"y":460,"wires":[["6de3da3af6d617fa"]]},{"id":"4e69efe4e7b72cb5","type":"change","z":"728eca0c6ed52fad","name":"","rules":[{"t":"set","p":"myicon","pt":"msg","to":"alarm_on","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":480,"y":420,"wires":[["6de3da3af6d617fa"]]},{"id":"3f437fac800bf596","type":"switch","z":"728eca0c6ed52fad","name":"flow.icon?","property":"icon","propertyType":"flow","rules":[{"t":"eq","v":"alarm_off","vt":"str"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":300,"y":440,"wires":[["4e69efe4e7b72cb5"],["6a54132a78a841b8"]]},{"id":"6de3da3af6d617fa","type":"change","z":"728eca0c6ed52fad","name":"","rules":[{"t":"set","p":"icon","pt":"flow","to":"myicon","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":670,"y":440,"wires":[["1feefcdebb5a9145"]]},{"id":"7aa5d8ce5322d823","type":"link out","z":"728eca0c6ed52fad","name":"Use the button press","mode":"link","links":[],"x":700,"y":360,"wires":[],"l":true},{"id":"a6e358b.672ffa8","type":"ui_group","name":"Demo","tab":"4e528085.a1bfa","order":1,"disp":true,"width":"6","collapse":false,"className":""},{"id":"4e528085.a1bfa","type":"ui_tab","name":"Demo","icon":"dashboard","order":2,"disabled":false,"hidden":false}]

```

> [@amine1](#):
>
> i tried to do that by making a function node which the input for it ,the payload coming from the output of the button when i click on it ,a msg sent to it ,and in this function i made some conditions ,i tried to make a static counter in this function however anything happen ,(the icon and the payload intented is working well

Nope, you totally lost me there.

---

<div class="post-metadata">

**Author:** ![amine1](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/amine1/32/80570_2.png) [@amine1](https://discourse.nodered.org/u/amine1)\
**Post date:** [31 January 2023 17:28 UTC](https://discourse.nodered.org/t/in-the-same-button-come-on-a-lock-unlock/74490/3 "2023-01-31T17:28:06Z")

</div>

yeah exactly what i want thank you so much

---

<div class="post-metadata">

**Author:** ![dynamicdave](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dynamicdave/32/96_2.png) [@dynamicdave](https://discourse.nodered.org/u/dynamicdave)\
**Post date:** [31 January 2023 21:51 UTC](https://discourse.nodered.org/t/in-the-same-button-come-on-a-lock-unlock/74490/4 "2023-01-31T21:51:43Z")

</div>

Here's a link to a tutorial I wrote for my IoT students.  
It shows how to create buttons with different actions.  
e.g. On and Off, toggle, reset, etc..

Hope you find it useful.

[http://resources-area.co.uk/node-red-flows/having\_fun\_with\_buttons.pdf](http://resources-area.co.uk/node-red-flows/having_fun_with_buttons.pdf)

---

<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 2023 21:52 UTC](https://discourse.nodered.org/t/in-the-same-button-come-on-a-lock-unlock/74490/5 "2023-03-02T21:52:31Z")

</div>

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