Work with message

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.

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

Context is king :slight_smile:

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)

1 Like

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

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


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....

the flow

[{"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"}]

Thank you very much for your excellent guidance.

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