Esp8266 + relay + normal switch rules coding

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
javier77
New user
Posts: 8
Joined: 04 Nov 2016, 15:13

Esp8266 + relay + normal switch rules coding

#1 Post by javier77 » 18 Oct 2017, 04:33

Hi i am finishing my project but I am missing the last part, let me tell you what I have so far:

1. ESP8266 d1 mini
2. Relay module
3. Normal wall light switch (with should turn the relay and send via mqtt the state of the relay to my hub)

I use mqtt to turn the relay on and off with is working fine, I use it with Home Assistant as hub on a Raspberry pi 3. I want to add a normal wall light switch with function is just turn one of the ESP8266 pins low/high and turn on and off (and change the state of the relay using mqtt) the relay so that I can use my phone as switch and also use the light switch to toggle the relay on and off.

So far the esp8266 can turn the relay on and off (gpio 12, name: relay value: state 1 or state 2) using my phone. This works like a charm but I can't seem to wrote the rules to use the normal light switch to work too.

Code: Select all

On button#state do
   if [relay#state]=0
      gpio,16,1
      publish,%sysname%/relay/gpio 
   else
      gpio,16,0
      publish,%sysname%/relay/gpio
   endif
endon
I tried other variations of this code too but they didn't work neither.


Any hints??

Thanks in advance

Javier

User avatar
vader
Normal user
Posts: 241
Joined: 21 Mar 2017, 17:35

Re: Esp8266 + relay + normal switch rules coding

#2 Post by vader » 18 Oct 2017, 10:43

You wrote " relay value: state 1 or state 2" and in the rules "if [relay#state]=0"? When is it 0 to do something? I think it should be 1 or 2. It's also better to use the logical values 0 and 1 for a switch/relay. It's a bit more international... ;)

And: publish %sysname%/relay/gpio,1 (or 2 in your case)

User avatar
toffel969
Normal user
Posts: 469
Joined: 03 Jan 2017, 10:58
Location: Germany

Re: Esp8266 + relay + normal switch rules coding

#3 Post by toffel969 » 18 Oct 2017, 12:25

If relay is connected to gpio12, shouldn't that also be 12 in rules?
Domoticz on Raspi 2 -- 14 ESP units (hacked Sonoff,NodeMCUs, Wemos, self-built units) running with RC140- Mega 2.0.0 dev8

Post Reply

Who is online

Users browsing this forum: No registered users and 68 guests