andAND
option, I see no solution for me to solve this problem.IF
Moderators: grovkillen, Stuntteam, TD-er
andAND
option, I see no solution for me to solve this problem.IF
Code: Select all
on checkSwitches do
if [Switch1#State]=0 or [Switch3#State]=0 or [Switch3#State]=0 or [Switch4#State]=0
GPIO,4,0 // Turn on LED
else
GPIO,4,1 // Turn off LED
endif
endon
is one you gave. I used always the name of a switch likeon checkSwitches do
but that is not mandatory? I can use any name?on Switch1#State do
You can define event handlers (rules) as you like, there are some events generated by ESPEasy, like Switch#State when a value of a task changes, but you can also 'generate' an event yourself using the Event or AsyncEvent (preferred) command:
Code: Select all
On Switch1#State do
// regular commands for this switch
AsyncEvent,checkSwitches // Update LED state next
Endon
On Switch2#State do
// regular commands for this switch
AsyncEvent,checkSwitches // Update LED state next
Endon
// Add for other switches similarly
Code: Select all
on checkSwitches do
if [Stekkerdoos_houtST1#State]=1
GPIO,16,0 // Turn on LED
Else
GPIO,16,1
endif
Endon
Code: Select all
on checkSwitches do
LogEntry,"checkSwitches: current state: [Stekkerdoos_houtST1#State]"
if [Stekkerdoos_houtST1#State]=1
GPIO,16,0 // Turn on LED
Else
GPIO,16,1
endif
Endon
Code: Select all
on Stekkerdoos_houtSW1#State do
If [Stekkerdoos_houtSW1#State]=0 and [Stekkerdoos_houtRestart#State]=0
GPIO,33,0
else
GPIO,33,1
endif
endon
Code: Select all
On System#Boot do
GPIO,4,1 //prevent activating GPIO's during reboot
GPIO,13,1
GPIO,33,1
TimerSet,1,10
endon
On rules#Timer=1 do
GPIO,4,0
endon
You do...
Code: Select all
On checkSwitches Do
LogEntry,"checkSwitches: current state: [Stekkerdoos_houtST1#State]"
If [Stekkerdoos_houtST1#State]=1
GPIO,16,0 // Turn on LED
Else
GPIO,16,1
Endif
Endon
Code: Select all
AsyncEvent,checkSwitches
Ath wrote: ↑12 Apr 2023, 23:09You can define event handlers (rules) as you like, there are some events generated by ESPEasy, like Switch#State when a value of a task changes, but you can also 'generate' an event yourself using the Event or AsyncEvent (preferred) command:
AsyncEvent will add it to the the list of events to handle, while Event will execute it immediately, possibly delaying the response to the switch changing its state, and using more memory, that's why AsyncEvent is preferred.Code: Select all
On Switch1#State do // regular commands for this switch AsyncEvent,checkSwitches // Update LED state next Endon On Switch2#State do // regular commands for this switch AsyncEvent,checkSwitches // Update LED state next Endon // Add for other switches similarly
Code: Select all
on Stekkerdoos_houtSW1#State do
AsyncEvent,checkSwitches
If [Stekkerdoos_houtSW1#State]=0 and [Stekkerdoos_houtRestart#State]=0
GPIO,33,0
else
GPIO,33,1
endif
endon
on checkSwitches do
LogEntry,"checkSwitches: current state: [Stekkerdoos_houtST1#State]"
if [Stekkerdoos_houtST1#State]=1
GPIO,16,0 // Turn on LED
Else
GPIO,16,1
endif
Endon
Code: Select all
on Stekkerdoos_houtSW1#State do
AsyncEvent,checkSwitches
If [Stekkerdoos_houtSW1#State]=0
GPIO,33,0
else
GPIO,33,1
endif
endon
on Stekkerdoos_houtSW2#State do
AsyncEvent,checkSwitches
If [Stekkerdoos_houtSW2#State]=0
GPIO,22,0
else
GPIO,22,1
endif
endon
Code: Select all
on checkSwitches do
LogEntry,"checkSwitches: current state: [ST1 Or ST2]"
if [Stekkerdoos_houtST1#State]=1 or [Stekkerdoos_houtST2#State]=1
GPIO,16,1 // Turn on LED
Elseif [Stekkerdoos_houtST1#State]=0 and [Stekkerdoos_houtST2#State]=0
GPIO,16,0
endif
Endon
Code: Select all
If [Stekkerdoos_houtSW1#State]=0 and [Stekkerdoos_houtRestart#State]=0 // check 2 switches????
Code: Select all
if [Stekkerdoos_houtST1#State]=1 or [Stekkerdoos_houtST2#State]=1
GPIO,16,1 // Turn on LED
Elseif [Stekkerdoos_houtST1#State]=0 and [Stekkerdoos_houtST2#State]=0
Code: Select all
On checkSwitches Do
LogEntry,"checkSwitches: current state: ST1=[Stekkerdoos_houtST1#State], ST2=[Stekkerdoos_houtST2#State]" // etc.
If [Stekkerdoos_houtST1#State]=1 or [Stekkerdoos_houtST2#State]=1 // Add more on-state switches like this, using the 'or' condition, when needed
GPIO,16,0 // Turn on LED
Else
GPIO,16,1
Endif
Endon
Code: Select all
on Stekkerdoos_houtSW1#State do
AsyncEvent,checkSwitches
If [Stekkerdoos_houtSW1#State]=0
GPIO,33,0
else
GPIO,33,1
endif
endon
on Stekkerdoos_houtSW2#State do
AsyncEvent,checkSwitches
If [Stekkerdoos_houtSW2#State]=0
GPIO,22,0
else
GPIO,22,1
endif
endon
on checkSwitches do
LogEntry,"checkSwitches: current state: [ST1 Or ST2]"
if [Stekkerdoos_houtST1#State]=1 or [Stekkerdoos_houtST2#State]=1
GPIO,16,1 // Turn on LED
Else
//Elseif [Stekkerdoos_houtST1#State]=0 and [Stekkerdoos_houtST2#State]=0
GPIO,16,0
endif
Endon
What do you mean? Could you use the actual states when describing what you want?
As you can see he changed the states for the GPIO 16.Ath wrote: ↑13 Apr 2023, 20:38 All you had to do there is change the names of the switches, so it should en up something like this:
Code: Select all
On checkSwitches Do LogEntry,"checkSwitches: current state: ST1=[Stekkerdoos_houtST1#State], ST2=[Stekkerdoos_houtST2#State]" // etc. If [Stekkerdoos_houtST1#State]=1 or [Stekkerdoos_houtST2#State]=1 // Add more on-state switches like this, using the 'or' condition, when needed GPIO,16,0 // Turn on LED Else GPIO,16,1 Endif Endon
Code: Select all
If [Stekkerdoos_houtSW1#State]=0
GPIO,33,0
else
GPIO,33,1
endif
Well, as ESP's can't deliver much current on a high output (few mA only) but do allow to draw around 20 mA when in low state, I usually have the GPIO on 0 for an On state. So that's no accident
It seems you made some mistake in your rules, cause this shouldn´t happen and is probably the cause, that leads to unexpected behavior....
It is probably not necessary anymore once the Endon issue is corrected but originally i wanted to see what the switch states in the log say and your LogEntry is useless for that.
Code: Select all
LogEntry,"checkSwitches: current state: ST1=[Stekkerdoos_houtST1#State], ST2=[Stekkerdoos_houtST2#State]" // etc.
Code: Select all
if [Stekkerdoos_houtST1#State]=1 or [Stekkerdoos_houtST2#State]=1
Code: Select all
On Stekkerdoos_houtSW1#State Do
If [Stekkerdoos_houtSW1#State]=0
GPIO,33,0
Else
GPIO,33,1
Endif
AsyncEvent,checkSwitches
Endon
Code: Select all
On Stekkerdoos_houtST1#State Do
AsyncEvent,checkSwitches
Endon
Code: Select all
on Stekkerdoos_houtSW1#State do
If [Stekkerdoos_houtSW1#State]=0
GPIO,33,0
else
GPIO,33,1
endif
AsyncEvent,checkSwitches
endon
on Stekkerdoos_houtSW2#State do
If [Stekkerdoos_houtSW2#State]=0
GPIO,22,0
else
GPIO,22,1
endif
AsyncEvent,checkSwitches
endon
on checkSwitches do
LogEntry,"checkSwitches: current state: [ST1 Or ST2]"
if [Stekkerdoos_houtST1#State]=1 Or [Stekkerdoos_houtST2#State]=1
GPIO,16,1 // Turn on LED
Else
//Elseif [Stekkerdoos_houtST1#State]=1 and [Stekkerdoos_houtST2#State]=1
GPIO,16,0
endif
Endon
so "checkSwitches" is still to early... i recommend you this:
And did you find the mistake in your rules?Dick60 wrote: ↑14 Apr 2023, 09:42 Edit: To be really sure the "checkSwitches" event is fired at the right time you could use a new event block like this:
Code: Select all
On Stekkerdoos_houtST1#State Do AsyncEvent,checkSwitches Endon
chromo23 wrote: ↑14 Apr 2023, 08:49 Dick60 wrote: ↑14 Apr 2023, 08:11
ACT : Endon
Command unknown: Endon
It seems you made some mistake in your rules, cause this shouldn´t happen and is probably the cause, that leads to unexpected behavior....
Can you please post all of your rules? Otherwise it is impossible to analyze this.
Code: Select all
On Stekkerdoos_houtST* Do
LogEntry,"checkSwitches: current state: ST1=[Stekkerdoos_houtST1#State], ST2=[Stekkerdoos_houtST2#State]" // etc.
If [Stekkerdoos_houtST1#State]=1 or [Stekkerdoos_houtST2#State]=1 // Add more on-state switches like this, using the 'or' condition, when needed
GPIO,16,0 // Turn on LED
Else
GPIO,16,1
Endif
Endon
As i said earlier, this is probably caused by a mistake/typo in your rules.
Users browsing this forum: No registered users and 6 guests