Create rules for 8 buttons/relays + LCD display
Posted: 20 Jul 2019, 16:45
Hello all,
Still working on my sprinkler system. The esp8266 is connected to 2 PCF8574 (relays and buttons), 1 LCD display and thermometer (GPIO).
I tried to link the button pressing acting on the relay:
- one pression turns the selected relay on
- one other pression turns off the relay
- A pression on a different zone turns on the selected relay and turns off the previous relay
- I must update the display
- I'm using 2 dummy variable (quad) to publish the relay status to the home automation system
- I will use timer to turn off the relays automatically
My problem is I can't get the rules to run properly, most button press (if tight with a rule) results in a crash. Calling the event via http works OK.
Can someone review my code and guide to some improvments/solutions:
- Is the syntax OK ?
- What can be wrong on the hardware side, am i asking too much to the esp ?
- Catch more errors in the log ?
- How deep can I nest the events (I'm coming from python...)
- I noticed sometime that IF/THEN/ELSE with %eventvalues% behaves not as expected
- Anything else...
Any guidance will be appreciated
Still working on my sprinkler system. The esp8266 is connected to 2 PCF8574 (relays and buttons), 1 LCD display and thermometer (GPIO).
I tried to link the button pressing acting on the relay:
- one pression turns the selected relay on
- one other pression turns off the relay
- A pression on a different zone turns on the selected relay and turns off the previous relay
- I must update the display
- I'm using 2 dummy variable (quad) to publish the relay status to the home automation system
- I will use timer to turn off the relays automatically
My problem is I can't get the rules to run properly, most button press (if tight with a rule) results in a crash. Calling the event via http works OK.
Can someone review my code and guide to some improvments/solutions:
- Is the syntax OK ?
- What can be wrong on the hardware side, am i asking too much to the esp ?
- Catch more errors in the log ?
- How deep can I nest the events (I'm coming from python...)
- I noticed sometime that IF/THEN/ELSE with %eventvalues% behaves not as expected
- Anything else...
Code: Select all
On System#Boot Do
event,alloff
endOn
//Button actions
on button8#State Do
if [button8#State]=1
Event,button=8,5
endif
EndOn
on button7#State Do
if [button7#State]=1
Event,button=7,10
endif
EndOn
//General feature called
on button Do
if [VAR#%eventvalue1%]=0
event,relayon=%eventvalue1%,%eventvalue2%
else
event,relayoff=%eventvalue1%
endif
endon
//Turns everything down
On alloff Do
Let,16,0
event,relayoff=1
event,relayoff=2
event,relayoff=3
event,relayoff=4
event,relayoff=5
event,relayoff=6
event,relayoff=7
event,relayoff=8
EndOn
On relayoff Do //turns off the relay number
let,%eventvalue%,0 // Sets the variable
pcfgpio,%eventvalue%,1
timerSet,%eventvalue%,0
endif
endon
On relayon Do //Turns on the relay number for defined number of secondes
let,%eventvalue%,1
let,16,1
pcfgpio,%eventvalue1%,0
timerSet,%eventvalue1%,%eventvalue2%
endif
endon
On WiFi#Connected Do
LCD,1,1,%ip%
EndOn