Rules for an autonomous switch for a relay
Posted: 20 May 2017, 16:01
Hi,
I have a Wemos D1 mini running V1.20 with a relay board attached and also a push button (momentary) switch.
Everything is controlled via Node-Red and works as expected, but I wanted to add a rule so that the local button flips the state of the relay and publishes a relevant message so the unit can work 'offline' too if Node-red is not responding for whatever reason.
The push button flips from 1 to 0 and back when pushed and the devices setup is as follows:
Both definitions have a value of 'state'.
I have read the wiki and tried a few permutations to create a rule without success - this is where I gave up:
This code seems to always run the 'else' condition as I can see Mosquitto receiving '/RELAY172/relay/state 1' every time the button is pressed and released. I suspect I have done something obviously wrong, but have spent so much time on this that I am not seeing it.
Supplemental questions:
==========
As well as I have tried - is that allowed?
==========
Can you use to set the state of the relay as well as/instead of
==========
Which syntax can be used (or both?): and
Any coding advice appreciated.
Thanks
I have a Wemos D1 mini running V1.20 with a relay board attached and also a push button (momentary) switch.
Everything is controlled via Node-Red and works as expected, but I wanted to add a rule so that the local button flips the state of the relay and publishes a relevant message so the unit can work 'offline' too if Node-red is not responding for whatever reason.
The push button flips from 1 to 0 and back when pushed and the devices setup is as follows:
Code: Select all
1 Switch input button 172 GPIO-13
2 Output - (Domoticz MQTT helper) relay 1 GPIO-5
I have read the wiki and tried a few permutations to create a rule without success - this is where I gave up:
Code: Select all
on System#Boot do
gpio,5,0 // Prevent relay turning on during boot
endon
on button#state=0 do
if [gpio,5]=1
gpio,5,0
gpio,0,0
Publish /RELAY172/relay/state,0
else
gpio,5,1
gpio,0,1
Publish /RELAY172/relay/state,1
endif
endon
Supplemental questions:
==========
As well as
Code: Select all
if [gpio,5]=1
Code: Select all
if [relay#state]=1
==========
Can you use
Code: Select all
relay#state=1
Code: Select all
gpio,5,1
Which syntax can be used (or both?):
Code: Select all
on button#state=0 do
Code: Select all
on [button#state]=0 do
Thanks