Page 1 of 1

Wi-Fi HTTP Switch

Posted: Friday 17 June 2016 22:08
by lollo93
Hi,
I'm building with an ESP8266 (board arduino like but with onboard WiFi) a controller for a relay to swtich some lights.
The project also allows to switch the light from a phisical switch on the wall.
Domotics is configure to open an HTTP link when the light is on and anotherone when the light goes off.
For fallback reason (ex WiFi or Domoticz not working) the ESP8266 is configured this way:
1) if the phisical switch is triggered I want the ESP8266 to change autonomously the relay state and after that send the HTTP request to JSON API to inform of the changed state
2) if a HTTP request is recived from domoticz instantly change the relay state

Now my problem: if I trigger the phisical switch this is appening:
1) the light goes on
2) ESP8266 then sends the HTTP JSON request to domoticz
3) Domoticz receive the switch toggle
4) Domoticz sends a HTTP Request to ESP8266 because the light status has changed
5) ESP8266 switch off the light

So I'm in a cycle with no end. If I toggle the swtich directly from domoticz works like a charm. Everything works good also if I disable the request from ESP8266 to Domoticz to inform the changed state.

Is there a way to get out from this?

This is my domoticz configuration
Image

Re: Wi-Fi HTTP Switch

Posted: Friday 17 June 2016 22:36
by toreandre
Are you sure you are sending the correct status from the ESP to domoticz when the GPIO status is sent?

Re: Wi-Fi HTTP Switch

Posted: Friday 17 June 2016 22:53
by lollo93
Yes, but the problem is the loop that is created.
I manual trigger the switch, so the light goes on, so domotics receive the udpate status, so domoticz sends the status back to ESP8266, so the light is off again.
Both domoticz and ESP8266 are sending the status each other on a device change, to keep everyting syncronized, each status is a toggle so the light starts blinking

Re: Wi-Fi HTTP Switch

Posted: Saturday 18 June 2016 9:18
by MatthijsPH
I have something similar going on with a physical wall switch.
When I use the wall switch a lua script checks the status of the (Hue) lights. If the lights are on, the script turns them off (and vice versa).

Code: Select all

if devicechanged['schakelKeuken'] then
   local status= hueStatus(3)
   if hue_state == true then
      commandArray[switch[3]]='Off'
      commandArray['lichtKeukenSpot']='Off'
      commandArray['dummyIemandInKeuken']='Off'
   elseif hue_state == false then
      commandArray[switch[3]]='On' 
   end
end

Re: Wi-Fi HTTP Switch

Posted: Saturday 18 June 2016 12:24
by Derik
Why not EspEasy?

Re: Wi-Fi HTTP Switch

Posted: Wednesday 13 July 2016 20:57
by niwreg
I did something like this too. I fixed it by adding on de esp8266 an variable, then when the physical switch is turned on:

if switch = on and lighton = off then
lighton = 1
set output high
call domoticz json
else if switch = of and lighton = on
lighton = off
set output low
call domoticz json
endif

and with http:

if httpon = on and lighton = off then
lighton = 1
set output high
elseif httpon = off and lighton = on then
lighton = 0
set output low
endif

the trick is the lighton variable wich is set and readable by physical and http. Also i don;t use toggles for this reason :)