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