# Work with message

**URL:** <https://discourse.nodered.org/t/work-with-message/23768>\
**Category:** Dashboard\
**Created:** [28 March 2020 05:02 UTC](https://discourse.nodered.org/t/work-with-message/23768 "2020-03-28T05:02:57Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![smaeelnakhaee](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/smaeelnakhaee/32/18938_2.png) [@smaeelnakhaee](https://discourse.nodered.org/u/smaeelnakhaee)\
**Post date:** [28 March 2020 05:02 UTC](https://discourse.nodered.org/t/work-with-message/23768/1 "2020-03-28T05:02:57Z")

</div>

Hello friends  
How do I use a received fixed message that is always one to turn a switch on and off? That is, when the number is received, if the switch is off,turn it on, and if it is on turn it to off, please advise me.

 ![HomeKit-Button-Programming-Flow-Chart-1024x434](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/b/fbc8f8091f3c3095a98886364bea46a9574f2dde.png)

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [28 March 2020 10:40 UTC](https://discourse.nodered.org/t/work-with-message/23768/2 "2020-03-28T10:40:14Z")

</div>

You'll probably get more help if You're more specific.

Context is king 🙂

What do you use to get status of light - MQTT? Rest? Other?

how do you turn the light on/off?

Is it a physical button or dashboard button you refer to?

If it's a physical button, how do you read it's state/how does it's push state reach node red?

What have you tried so far? (Post your flow & screenshots of it would help)

---

<div class="post-metadata">

**Author:** ![smaeelnakhaee](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/smaeelnakhaee/32/18938_2.png) [@smaeelnakhaee](https://discourse.nodered.org/u/smaeelnakhaee)\
**Post date:** [28 March 2020 15:35 UTC](https://discourse.nodered.org/t/work-with-message/23768/3 "2020-03-28T15:35:30Z")

</div>

i have a touch sensor tp223 connected to wemos d1 mini and it work with mqtt  
when i touch the sensor it will be send number 1 as payload to node-red  
So I want to change the status of the switch when the message is received, turn it on if the switch is off, and turn off if the switch is on

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [28 March 2020 19:24 UTC](https://discourse.nodered.org/t/work-with-message/23768/4 "2020-03-28T19:24:15Z")

</div>

Hi, when you reply to a topic, its wise to reply to the person otherwise they dont get a notification.

Ok, so you replied privately to me and i asked you...

* * *
When you reply on the thread, Please also, include information on...
- Does node-red get the lamps status? And what is its value for on and it's value for off?
- what protocol is used to turn on lamp?
- What value (number 0/1? Boolean true/false? String 'on'/'off'?) Is used to turn the lamp off and on.

* * *

### and you replied...

* * *
hi my friend , thanks for helping i have a wemos d1 mini connected to a touch sensor tp223 when i touch sensor i recive a message from mqtt Touch every time it send a Fixed message i want to use this message for change state of my switch

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

* * *

So you still really haven't sent nearly enough info to fully help you but I can provide an untested example that should be close to what you need....

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

the flow

```auto
[{"id":"b41ffda2.6a3fa","type":"inject","z":"13bb21a6.7cbe0e","name":"fake button","topic":"esp/tp223","payload":"1","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":120,"y":340,"wires":[["11c81e23.591582"]]},{"id":"661d679b.735508","type":"switch","z":"13bb21a6.7cbe0e","name":"lamp_status == 1 or 0?","property":"house_livingroom_lamp","propertyType":"flow","rules":[{"t":"eq","v":"1","vt":"num"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":480,"y":280,"wires":[["3937e44c.41d30c"],["702e5c9b.a26f64"]]},{"id":"45862aed.8e5724","type":"change","z":"13bb21a6.7cbe0e","name":"store lamp status in flow.lamp_status","rules":[{"t":"set","p":"lamp_status","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":530,"y":200,"wires":[[]]},{"id":"dbc3ad38.dab57","type":"mqtt in","z":"13bb21a6.7cbe0e","name":"","topic":"house/livingroom/lamp/status","qos":"2","datatype":"auto","broker":"4af1f016.58aaa","x":180,"y":200,"wires":[["45862aed.8e5724"]]},{"id":"11c81e23.591582","type":"switch","z":"13bb21a6.7cbe0e","name":"payload == 1 ?","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"1","vt":"num"}],"checkall":"true","repair":false,"outputs":1,"x":280,"y":280,"wires":[["661d679b.735508"]]},{"id":"7c87522.d38dcac","type":"mqtt out","z":"13bb21a6.7cbe0e","name":"","topic":"house/livingroom/lamp/control","qos":"","retain":"","broker":"4af1f016.58aaa","x":970,"y":280,"wires":[]},{"id":"3937e44c.41d30c","type":"change","z":"13bb21a6.7cbe0e","name":"set payload=0","rules":[{"t":"set","p":"payload","pt":"msg","to":"0","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":700,"y":260,"wires":[["7c87522.d38dcac"]]},{"id":"702e5c9b.a26f64","type":"change","z":"13bb21a6.7cbe0e","name":"set payload=1","rules":[{"t":"set","p":"payload","pt":"msg","to":"1","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":700,"y":300,"wires":[["7c87522.d38dcac"]]},{"id":"206abcbb.db0f34","type":"mqtt in","z":"13bb21a6.7cbe0e","name":"","topic":"esp/tp223","qos":"2","datatype":"auto","broker":"4af1f016.58aaa","x":120,"y":280,"wires":[["11c81e23.591582"]]},{"id":"4af1f016.58aaa","type":"mqtt-broker","z":"","name":"aedes local","broker":"localhost","port":"1883","clientid":"","usetls":false,"compatmode":false,"keepalive":"40","cleansession":true,"birthTopic":"aedes/state","birthQos":"0","birthPayload":"ready","closeTopic":"aedes/state","closeQos":"0","closePayload":"alert","willTopic":"aedes/state","willQos":"0","willPayload":"alert"}]

```

---

<div class="post-metadata">

**Author:** ![smaeelnakhaee](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/smaeelnakhaee/32/18938_2.png) [@smaeelnakhaee](https://discourse.nodered.org/u/smaeelnakhaee)\
**Post date:** [28 March 2020 19:38 UTC](https://discourse.nodered.org/t/work-with-message/23768/5 "2020-03-28T19:38:03Z")

</div>

Thank you very much for your excellent guidance.

---

<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:** [27 April 2020 19:38 UTC](https://discourse.nodered.org/t/work-with-message/23768/6 "2020-04-27T19:38:03Z")

</div>

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