stateless button to change relay state in node-red

Hello! I just started learning node-red. please tell me a simple way to solve my problem.
I have an input, a dry contact, a button is connected to it.
by pressing the button I get state 1, I need to work on the relay channel, change its state to the opposite.

Hmmm..not quite sure what it is, that you want to achieve.

Do you want,

a) for every press of the button to toggle the relay or
b) just change the payload of the button from "1" to "0"
c) or else...?

1 Like

Hello!
all right. Option 2. Each time the button is pressed, the relay state is reversed.
each press of the button sends mqtt to the topic - state 1
when released - state 0
as soon as the state of the topic - button becomes 0-1-0, you need to change the current state of the relay to the opposite (0 to 1 or 1 to 0).

OK, I'd still gather that you want to toggle the relay everytime the button is pressed.
The dry contact is generating messages, everytime it opens (state 0) and closes (state 1).

In either case, you want the state 1 to drive/toggle the relay and ignore the "state 0" messages (kind of de-bouncing the contact).

Look at this flow:

[{"id":"15a2d35e.cb02ed","type":"inject","z":"8228e26c.f17ef","name":"OFF","topic":"OFF","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":210,"y":433,"wires":[["3f2385e9.d1c20a"]]}]

It uses a dsm node to set the relay-state...each "click" will toggle the output.
You can use the inject nodes to test the dsm node...observe the output of the debug messages.
For the button (dry contact) the switch node will ignore/filter the "state 0" messages and create a "click" for each "state 1" message.

1 Like

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