rules - example not working - error

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
pw444
Normal user
Posts: 38
Joined: 23 Apr 2019, 15:34

rules - example not working - error

#1 Post by pw444 » 28 Apr 2019, 16:12

Hi All,

trying to learn from example. used the example at: https://www.letscontrolit.com/wiki/inde ... rial_Rules



Rule:

Code: Select all


On System#Boot do
 gpio,12,0
 timerSet,1,5
endon

On Rules#Timer=1 do
 if [E1SW1#Switch]=1
   gpio,12,0
  else 
   gpio,12,1
 endif
 timerSet,1,5
endon

Yes, the virtual switch was created as:
virtual switch needs to be created in the "Devices" section to allow the reading the state of the LED (on or off). The Device needs to be "Switch Input" with the following settings:

Device Name - E1SW1
Enabled - Ticked
Internal PullUp - Ticked
1st GPIO - GPIO-12(D6)
Switch Type - Switch
Switch Button Type - Normal Switch
After rebooting the ESP, the LED will start blinking 10 seconds on then 10 seconds off.

But led stays on and log shows:

Code: Select all


2251651: EVENT: Rules#Timer=1
2251713: ACT : gpio,12,1
2251716: SW : GPIO 12 Set to 1
2251721: ACT : timerSet,1,5
2251730: Command: timerset
2253193: WD : Uptime 38 ConnectFailures 0 FreeMem 17776 WiFiStatus 3
12685: NTP : NTP replied: delay 30 mSec Accuracy increased by 0.981 seconds
12686: Time adjusted by -1556460418356.05 msec. Wander: -432350116.21 msec/second
12687: Current Time Zone: STD time start: 2019-10-27 03:00:00 offset: -180 min
12689: EVENT: Time#Initialized
12706: EVENT: Clock#Time=Sun,11:07
13627: EVENT: Rules#Timer=1
13687: ACT : gpio,12,1
13690: SW : GPIO 12 Set to 1
13695: ACT : timerSet,1,5
13703: Command: timerset
19627: EVENT: Rules#Timer=1
19687: ACT : gpio,12,1
19690: SW : GPIO 12 Set to 1
19694: ACT : timerSet,1,5
19702: Command: timerset
25627: EVENT: Rules#Timer=1
25688: ACT : gpio,12,1
25691: SW : GPIO 12 Set to 1
25695: ACT : timerSet,1,5
25703: Command: timerset
31627: EVENT: Rules#Timer=1
31686: ACT : gpio,12,1
31689: SW : GPIO 12 Set to 1
31695: ACT : timerSet,1,5
31703: Command: timerset
33181: WD : Uptime 1 ConnectFailures 0 FreeMem 17936 WiFiStatus 3
37628: EVENT: Rules#Timer=1
37688: ACT : gpio,12,1
37691: SW : GPIO 12 Set to 1
37695: ACT : timerSet,1,5
37703: Command: timerset
43627: EVENT: Rules#Timer=1
43687: ACT : gpio,12,1
43690: SW : GPIO 12 Set to 1
43694: ACT : timerSet,1,5
43702: Command: timerset
49627: EVENT: Rules#Timer=1
49686: ACT : gpio,12,1
49689: SW : GPIO 12 Set to 1
49694: ACT : timerSet,1,5
49702: Command: timerset
55627: EVENT: Rules#Timer=1
55688: ACT : gpio,12,1
55691: SW : GPIO 12 Set to 1
55695: ACT : timerSet,1,5
55703: Command: timerset
61627: EVENT: Rules#Timer=1
61686: ACT : gpio,12,1
61689: SW : GPIO 12 Set to 1
61694: ACT : timerSet,1,5
61703: Command: timerset
62628: EVENT: Clock#Time=Sun,11:08
63181: WD : Uptime 1 ConnectFailures 0 FreeMem 17936 WiFiStatus 3
67627: EVENT: Rules#Timer=1
67712: ACT : gpio,12,1
67715: SW : GPIO 12 Set to 1
67720: ACT : timerSet,1,5
67727: Command: timerset
73627: EVENT: Rules#Timer=1
73688: ACT : gpio,12,1
73691: SW : GPIO 12 Set to 1
73696: ACT : timerSet,1,5
73703: Command: timerset
79627: EVENT: Rules#Timer=1
79686: ACT : gpio,12,1
79689: SW : GPIO 12 Set to 1
79694: ACT : timerSet,1,5
79701: Command: timerset
85627: EVENT: Rules#Timer=1
85687: ACT : gpio,12,1
85690: SW : GPIO 12 Set to 1
85695: ACT : timerSet,1,5
85703: Command: timerset
91627: EVENT: Rules#Timer=1
91686: ACT : gpio,12,1
91689: SW : GPIO 12 Set to 1
91694: ACT : timerSet,1,5
Any hint?

Thx in advance!
Last edited by pw444 on 30 Apr 2019, 01:26, edited 2 times in total.

kimot
Normal user
Posts: 161
Joined: 12 Oct 2017, 20:46

Re: rules - example not working -

#2 Post by kimot » 28 Apr 2019, 21:55

Try different version of ESPeasy.
It seems, you are using some "mega" version.
I recommend last v2.0 versions.

My simple if statements, which works with v2.0 do not works with mega version.

pw444
Normal user
Posts: 38
Joined: 23 Apr 2019, 15:34

Re: rules - example not working -

#3 Post by pw444 » 28 Apr 2019, 22:51

Hi, thank you for the answer.

Where do i get the 2.0?

I've found R120 or mega.

Thx!

User avatar
ThomasB
Normal user
Posts: 400
Joined: 17 Jun 2018, 20:41
Location: USA

Re: rules - example not working -

#4 Post by ThomasB » 29 Apr 2019, 03:13

There were some changes to the Switch input - Switch plugin sometime between Dec 2018 and Jan 2019 that had adversely affected reading an output pin that is also an Switch input. I understood these changes were reverted, but your observation suggests otherwise. So use a Mega release from before Dec-2018 if you want to use those rules as-is.

Or, continue to use the latest Mega release and use the revised rule example shown below. It will toggle gpio 12, which is the power relay in a Sonoff module. So change gpio-12 to the I/O pin that has the LED you want to blink.

Code: Select all

On System#Boot do
 gpio,12,0
 let,1,0
 timerSet,1,5
endon

On Rules#Timer=1 do
 timerSet,1,5
 if [VAR#1]=1
   let,1,0
   gpio,12,0
  else 
   let,1,1
   gpio,12,1
 endif
endon

- Thomas

pw444
Normal user
Posts: 38
Joined: 23 Apr 2019, 15:34

Re: rules - example not working -

#5 Post by pw444 » 29 Apr 2019, 12:38

Thank you ThomasB,

regarding the following code:

Code: Select all

On System#Boot do
 gpio,12,0
 let,1,0
 timerSet,1,5
endon

On Rules#Timer=1 do
 timerSet,1,5
 if [VAR#1]=1
   let,1,0
   gpio,12,0
  else   
   let,1,1
   gpio,12,1
 endif
endon
where do i find the description for "let,1,0"? Where do the VAR#1 came from?

It there a revised tutorial for rules? the one i used, which seams to be outdated is https://www.letscontrolit.com/wiki/inde ... rial_Rules.

Thanks!

User avatar
grovkillen
Core team member
Posts: 3225
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

Re: rules - example not working -

#6 Post by grovkillen » 29 Apr 2019, 12:40

I'm the one responsible for the wiki, which we're moving to "read the docs", but I'm working full time now and have little time to keep up with the documentation.

Please consider sponsoring us.
ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you :idea: :idea: :idea:

pw444
Normal user
Posts: 38
Joined: 23 Apr 2019, 15:34

Re: rules - example not working -

#7 Post by pw444 » 29 Apr 2019, 12:52

Hi Grovkillen,

i've found espeasy lesss than 10 days ago... i'm trying to find out how rules works and things can be done, having no success yet, due not performing as shown by docs / wikis.

Sure i consider sponsoring, as i do with two other open source initiatives, and for that, having some results is needed.

So, knowing where i can get reliable information (documentation and examples) is a good start ;) The forum, for doubts which i either don't understand from reading or don't work as expected..

Thx!

User avatar
ThomasB
Normal user
Posts: 400
Joined: 17 Jun 2018, 20:41
Location: USA

Re: rules - example not working -

#8 Post by ThomasB » 29 Apr 2019, 17:03

where do i find the description for "let,1,0"? Where do the VAR#1 came from?
https://espeasy.readthedocs.io/en/lates ... mmand.html
and
viewtopic.php?t=6288

Code: Select all

i'm trying to find out how rules works and things can be done, having no success yet, due not performing as shown by docs / wikis.
The wiki has many outdated examples and/or missing info. The community keeps adding features and changing existing features, without updating the wiki.

Code: Select all

I'm the one responsible for the wiki, which we're moving to "read the docs", but I'm working full time now and have little time to keep up with the documentation.
I'd say that the authors of the functional changes to ESPEasy are directly responsible for ensuring the wiki is updated. But for many months there have been important changes without any enforcement of updating the wiki. Besides helping the user base, keeping the wiki up to date will help with the proposed "read the docs" project.

- Thomas

pw444
Normal user
Posts: 38
Joined: 23 Apr 2019, 15:34

Re: rules - example not working -

#9 Post by pw444 » 29 Apr 2019, 20:14

Hi ThomasB,

thank you for pointing the new docs.

BR,

PauloW

pw444
Normal user
Posts: 38
Joined: 23 Apr 2019, 15:34

Re: rules - example not working - solved

#10 Post by pw444 » 30 Apr 2019, 01:22

Hi All,

trying to find out how it works, i did the following:

Code: Select all

On System#Boot do
 gpio,12,0
 gpio,13,0
 gpio,14,0
 let,1,0
 let,2,0
 timerSet,1,5
 timerSet,2,1
endon

On Rules#Timer=1 do
 timerSet,1,5
 if [VAR#1]=1
   let,1,0
   gpio,12,0
   gpio,14,1
  else   
   let,1,1
   gpio,12,1
   gpio,14,0
 endif
endon

On Rules#Timer=2 do
 timerSet,2,1
 if [VAR#2]=1
   let,2,0
   gpio,13,1
  else
   let,2,1
   gpio,13,0
  endif
endon
The second one, On Rules#Timer=2 do is not executed.

What am i doing wrong?

Thx in advance.

User avatar
ThomasB
Normal user
Posts: 400
Joined: 17 Jun 2018, 20:41
Location: USA

Re: rules - example not working - error

#11 Post by ThomasB » 30 Apr 2019, 01:50

Your timer 2 rules seem legit. Don't forget that you must reboot the ESP after changing those rules since the new timer needs initialization.

If reboot does not help then change timer 2 duration to something bigger than one second.

If still no luck then we need to know more. For example, what is connected to GPIO 13? Post schematic if it is a published project.

- Thomas

pw444
Normal user
Posts: 38
Joined: 23 Apr 2019, 15:34

Re: rules - example not working - error

#12 Post by pw444 » 30 Apr 2019, 17:30

After rebooting, it worked :D

What i'm trying to do (concept and learning - later, more sofisticated jobs ;) )

1) have 3 virtual push buttons ("pushed" either by http command or by openhab / home assistant), which will trigger 3 gpio to high (as output), physically conencted to a circuit in parallel with it's 3 physical push buttons, having message sent to openhab / home assitant)

2) reading one gpio state, physically connected to a LED from this circuit, which light (state HIGH) when one of the 3 push buttons iis triggered, and when it gets off, state LOW again), having message sent to openhab / home assistant.

Thank you for the fine support.

For sponsoring, please inform how to do it.

BR

User avatar
grovkillen
Core team member
Posts: 3225
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

Re: rules - example not working - error

#13 Post by grovkillen » 30 Apr 2019, 19:20

ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you :idea: :idea: :idea:

User avatar
ThomasB
Normal user
Posts: 400
Joined: 17 Jun 2018, 20:41
Location: USA

Re: rules - example not working - error

#14 Post by ThomasB » 30 Apr 2019, 20:48

Code: Select all

After rebooting, it worked
Glad to hear it is working.

- Thomas

pw444
Normal user
Posts: 38
Joined: 23 Apr 2019, 15:34

Re: rules - example not working - error

#15 Post by pw444 » 30 Apr 2019, 21:19

done. markus kuntz is patroning you with $ 10.00 / month. keep the good job.

User avatar
grovkillen
Core team member
Posts: 3225
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

Re: rules - example not working - error

#16 Post by grovkillen » 30 Apr 2019, 21:28

pw444 wrote:
30 Apr 2019, 21:19
done. markus kuntz is patroning you with $ 10.00 / month. keep the good job.
Thank you very much!
ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you :idea: :idea: :idea:

pw444
Normal user
Posts: 38
Joined: 23 Apr 2019, 15:34

Re: rules - example not working - error

#17 Post by pw444 » 01 May 2019, 15:58

Hi All,

the rules:

Code: Select all

On System#Boot do
 gpio,12,0
 gpio,13,0
 gpio,14,0
 gpio,15,0
 let,1,0
 let,2,0
 timerSet,1,5
endon

// loop
On On24_On do
  gpio,12,1
endon

On On58_On do
  gpio,13,1
endon

On OffAll_Off do
  gpio,14,0
  gpio,13,0
  gpio,12,0
endon

//On LedFinish_On
as i understand, all the pins should have state low (0), when starting, but under devices, i find as:

1 ✔ Display - LCD2004 lcd1602 GPIO-4
GPIO-5
Edit 2 ✔ Switch input - Switch On24 GPIO-12 State:1
Edit 3 ✔ Switch input - Switch On58 GPIO-13 State:1
Edit 4 ✔ Switch input - Switch OffAll GPIO-14 State:1
Edit 5 ✔ Switch input - Switch LedFinish_On GPIO-15 State:0
Edit 6

By pin state buffer:

Plugin ❔ GPIO Mode Value/State Task Monitor Command Init
P001 12 output 0 1 0 1 0
P001 13 output 0 1 0 1 0
P001 14 output 0 1 0 1 0
P001 15 output 0 1 0 1 0

Why do devices states 1, when it should be 0?

Another question: by push button, how to make the output become high for 60ms, or 1 second (ok, the is the debounce), but the buttons are defined as push button high active.

For testing purpused, i have a 220 Ohm resistr from gpio's to led, and when button is "pushed", led lights, but remains on.

The virtual push button shall simulate the physical push button by output, or am i wrong?

Thank you all!

User avatar
grovkillen
Core team member
Posts: 3225
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

Re: rules - example not working - error

#18 Post by grovkillen » 01 May 2019, 16:23

You may have one of the DEVICES set to inverted? The rest of your questions I'm not entirely sure what you mean by virtual switches?
ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you :idea: :idea: :idea:

pw444
Normal user
Posts: 38
Joined: 23 Apr 2019, 15:34

Re: rules - example not working - error

#19 Post by pw444 » 01 May 2019, 16:54

By inverted you mean Inversed Logic? if yes, not ticked.

by virtual buttons, i mean the following:

the esp8266 device have no physical button, and it's gpios (input or output) will be connectd to other devices in paralell to those devices physical buttons, either direct, in case of an arduino (voltage divider, in case 3.3 to 5) or optcoupler (with triac, transistor, or whatever is needed), in case of other devices, so while testing, i'm using http://192.168.1.7/control?cmd=event,On24_On for example. Later will have it by OH2 or HA.

When other devices have a toggle button (on and off), relay will be used, but when devices used push button, i want to simulate the output high state for the time of a conventional push button pressing, like 60 mS or 1 S.

And for reading states from other devices, which don't have any inteligence other than an internal timer or sensor, getting the led state, for example, will make figure out if the other device is still on or off, so led on -> input high on gpio = togle position ON switch for the esp8266, led off -> input low on gpio.

That's the way i will make semi-stupid devices able to be controlled, turning on, off, having the state and triggering messages to openhab, etc

Under arduino, i'm already doing it for some cases, where the virtual button is triggered as digitalWrite() .... and now i will make use of the facilities of the espeasy, but need to understand more how rules works and bindings works... and the best way for me to understand is getting examples and testing.

TIA

User avatar
ThomasB
Normal user
Posts: 400
Joined: 17 Jun 2018, 20:41
Location: USA

Re: rules - example not working - error

#20 Post by ThomasB » 01 May 2019, 20:19

Code: Select all

Why do devices states 1, when it should be 0?
Perhaps your directly connected LEDs are acting as strong pullups. To check for that, simply disconnect the LEDs (nothing connected to the pin), reboot, and check the device page again. If that solves the problem then buffering the LED's with a driver (transistor or logic gate, choose your poison) will be needed.

BTW, using the Switch Input device plugin to read output pins is a common thing to do. But it's a popular functionality that is threaten with extinction. To avoid surprises, I suggest you use variables to store the output pin states instead of reading the output pins with the Switch Input Plugin. I know, a messy way to do it, but safer than sorry.

- Thomas

pw444
Normal user
Posts: 38
Joined: 23 Apr 2019, 15:34

Re: rules - example not working - error

#21 Post by pw444 » 01 May 2019, 21:55

Thanks for answering.

all 4 gpios (12,13, 14 and 15) are connected as:

gpio pin -> 220 ohm resistor -> led -> gnd

for the testing, i'm using the Wemos D1, on 5V, which is ok for it.

All have the same configuration, under devices, but 3 starts with state 1 (on device list page) and have state 0 (all 4) under pin state buffer. So, que question why the difference.

Regarding the suggestion " I suggest you use variables to store the output pin states instead of reading the output pins with the Switch Input Plugin", any example? I buy it, being safe than sorry.

And by push button behavior, so defines as push button active high on devices, only sets the gpio HIGH for some mS, then LOW again, any suggestion? push button, as said, only sets HIGH while pushed.

TIA,

User avatar
ThomasB
Normal user
Posts: 400
Joined: 17 Jun 2018, 20:41
Location: USA

Re: rules - example not working - error

#22 Post by ThomasB » 01 May 2019, 23:22

all 4 gpios (12,13, 14 and 15) are connected as:
gpio pin -> 220 ohm resistor -> led -> gnd
for the testing, i'm using the Wemos D1, on 5V, which is ok for it.
All have the same configuration, under devices, but 3 starts with state 1 (on device list page) and have state 0 (all 4) under pin state buffer. So, que question why the difference.
Your observation is unexpected, sounds like the Switch Plugin is messed up. What EPSEasy release/version are you using?
Regarding the suggestion " I suggest you use variables to store the output pin states instead of reading the output pins with the Switch Input Plugin", any example? I buy it, being safe than sorry.
The general idea is that every place you set/clear a GPIO pin you also save its logic state in a system variable (general VAR usage was discussed in the previous posts). Then write the rule logic so it uses the system variable instead of reading the GPIO pin's output state. There will be no need to create a Switch Input device for each GPIO output that you want to monitor, the VAR will be used instead.
And by push button behavior, so defines as push button active high on devices, only sets the gpio HIGH for some mS, then LOW again, any suggestion? push button, as said, only sets HIGH while pushed.
You have to write a timer rule to do that. Timers have one second resolution, so the shortest On Time would be 1S.

- Thomas

pw444
Normal user
Posts: 38
Joined: 23 Apr 2019, 15:34

Re: rules - example not working - error

#23 Post by pw444 » 02 May 2019, 21:55

THx for the answer.

Firmware
Build:⋄ 20103 - Mega
System Libraries:⋄ ESP82xx Core 2_4_2, NONOS SDK 2.2.1(cfd48f3), LWIP: 2.0.3 PUYA support
Git Build:⋄ mega-20190425
Plugins:⋄ 47 [Normal]
Build Md5: 8364f546fd8f5fcd0843c49262b0e8
Md5 check: passed.
Build Time:⋄ Apr 25 2019 02:14:50
Binary Filename:⋄ ESP_Easy_mega-20190425_normal_ESP8266_4M.bin

Regarding "You have to write a timer rule to do that. Timers have one second resolution, so the shortest On Time would be 1S." i found pulse (ok, blocking, but for this job, is perfect).


by devices, behavior changes by boot.

defined switch - normal switch (togle) to gpio 15.

well, the following code:

Code: Select all

// http://192.168.1.7/control?cmd=event,OffAll_Off
// http://192.168.1.7/control?cmd=event,On24_On
// LedFinish button to gpio15

// setup
On System#Boot do
 gpio,12,0
 gpio,13,0
 gpio,14,0
 gpio,15,0 
endon

// loop
On On24_On do
  pulse,12,1,200
  let,1,1
  gpio,12,0
// message running 2-4
endon

On On58_On do
  pulse,13,1,200
  let,1,2
  gpio,13,0
// message running 5-8
endon

On OffAll_Off do
  pulse,14,1,200
  let,1,3
  gpio,14,0
// message interrupted
endon

On LedFinish#State=1 do
   gpio,12,1
   if [VAR#1]=1
     // message 2-4
     let,1,4
   endif
   if [VAR#1]=2
     // message 5-8
     let,1,4
   endif   
endon
  
On LedFinish#State=0 do
   gpio,12,0
   if [VAR#1]=3
     // message interrupted
     let,1,0
   endif
   if [VAR#1]=4
     // message finished
     let 1,0
   endif    
endon
does not perform, so, i go to devices, and by LedFinish switch, i enable internal pullup, and voila, it works like i charm.

So, i reboot it, and it does not work. So i go to devices and disable internal pullup, and it works.

And every reboot, internal pullupp. I simply don't understand it, as the hardware and connections did not change.

Translating simple, no buttons... pulse get the push button job done, so gpio 12,13 and 14 are outputs for optcpoupler. the 4th button, a "rocker switch" as input on gpio15

but the inversion of pullup every reboot... any hint in how to get it done right?

TIA

User avatar
ThomasB
Normal user
Posts: 400
Joined: 17 Jun 2018, 20:41
Location: USA

Re: rules - example not working - error

#24 Post by ThomasB » 02 May 2019, 23:33

It seems to me that Switch Input device isn't reliably reading the GPIO output pins. I suggest you post a about your observed behavior (Switch device values don't match Tools=>PinStateBuffer values) in the ongoing topic related to the Switch Input plugin: viewtopic.php?f=6&t=6661

I don't have time to deeply analyzer your new rule example, but I see that it is reading Switch Input GPIO that is also used as GPIO outputs. Since I suspect the Switch Device plugin is broken when this technique is used, you can either: (1) Replace your rule code that reads output GPIO (via the Switch Input) and instead use local variables, per my earlier suggestion. Or, (2) Install a Mega firmware release from before mid-Nov 2018 and see if it solves the problem. Hopefully one of these choices gets you going.

Lastly, I suggest you avoid using GPIO-15 in your code experiments. That is a boot pin (and also hardware Rx) and misuse can hang the board at a reset.

- Thomas

pw444
Normal user
Posts: 38
Joined: 23 Apr 2019, 15:34

Re: rules - example not working - error

#25 Post by pw444 » 03 May 2019, 01:38

Thx for the answer.

regarding "1) Replace your rule code that reads output GPIO (via the Switch Input) and instead use local variables, per my earlier suggestion." any example in how using local variables, as i need to get the gpio state, and have it updated when gpio state changes from high to low or low to high? It's a little bit confusing me.. :cry: ?

User avatar
ThomasB
Normal user
Posts: 400
Joined: 17 Jun 2018, 20:41
Location: USA

Re: rules - example not working - error

#26 Post by ThomasB » 03 May 2019, 03:31

Regarding the use of VARs, I mean that every time a rule changes the on/off state of a GPIO output, have it also copy the state to a system VAR (or Generic-Dummy device). Now anytime your rules need to know if the GPIO output is on or off, you query the VAR instead of reading the Switch-Input that was assigned the GPIO output.

In other words, the only time you use the Switch Input is when you are reading a mechanical switch or external logic signal. The VARs are used to shadow the GPIO output state and your rules can act on them. A unique VAR is assigned to each GPIO output. The Switch Input devices, that are not connected to a mechanical switch or external signal, would be deleted since the VARs replace them.

But put aside the VAR trick for now. Instead, use an older Mega release. I tested mega-20181207 on a spare Sonoff Basic module (specifically ESP_Easy_mega-20181207_normal_core_241_ESP8266_1024.bin) and its Switch Plugin is working as intended. It will allow the Switch Input plugin to read GPIO output, which is better suited to your rule methods.

- Thomas

pw444
Normal user
Posts: 38
Joined: 23 Apr 2019, 15:34

Re: rules - example not working - error

#27 Post by pw444 » 03 May 2019, 12:36

Thank you.

i will try with 20181207 and let you know the results.

TIA

pw444
Normal user
Posts: 38
Joined: 23 Apr 2019, 15:34

Re: rules - example not working - error

#28 Post by pw444 » 03 May 2019, 16:28

Hi,
With 20181207 it did not work. i only got it working with:
Build:⋄ 20103 - Mega
Libraries:⋄ ESP82xx Core 2_4_2, NONOS SDK 2.2.1(cfd48f3), LWIP: 2.0.3 PUYA support
GIT version:⋄ mega-20181204
Plugins:⋄ 46 [Normal]
Build Md5: 8fcbabb62a7e828e37824fd0e484298a
Md5 check: passed.
Build time:⋄ Dec 4 2018 03:08:51
Binary filename:⋄ ESP_Easy_mega-20181204_normal_ESP8266_4096.bin

The following code:

Code: Select all

// http://192.168.1.7/control?cmd=event,OffAll_Off
// http://192.168.1.7/control?cmd=event,On24_On

// setup
On System#Boot do
 gpio,12,0
 gpio,13,0
 gpio,14,0
 gpio,15,0
endon

// loop
On On24_On do
  pulse,12,1,200
  let,1,1
  gpio,12,0
// message running 2-4
endon

On On58_On do
  pulse,13,1,200
  let,1,2
  gpio,13,0
// message running 5-8
endon

On OffAll_Off do
  pulse,15,1,200
  let,1,3
  gpio,14,0
// message interrupted
endon

On LedFinish#Switch=1 do
   gpio,12,1
   if [VAR#1]=1
     // message 2-4
     let,1,4
   endif
   if [VAR#1]=2
     // message 5-8
     let,1,4
   endif
   
endon
  
On LedFinish#Switch=0 do
   gpio,12,0
   if [VAR#1]=3
   // message interrupted
   let,1,0
   endif
   if [VAR#1]=4
   // message finished
   let 1,0
   endif    
endon
And this is weird, because it's only a simple toggle switch.

Anyway, for now, it's working.

Thx!

User avatar
ThomasB
Normal user
Posts: 400
Joined: 17 Jun 2018, 20:41
Location: USA

Re: rules - example not working - error

#29 Post by ThomasB » 03 May 2019, 18:20

From that info I have to draw the conclusion that the Switch Input plugin is broken. I don't expect a fix in the existing Switch-Input device because of a matter of opinion on what this plugin should be allowed to do.

I read that two new plugins will be created to replace it, but I don't know any useful details; I'm just a user fan-boy, not a principal developer. So your workaround using the old 20181204 release seems to be the most practical solution.

- Thomas

pw444
Normal user
Posts: 38
Joined: 23 Apr 2019, 15:34

Re: rules - example not working - error

#30 Post by pw444 » 03 May 2019, 19:31

Yes, it seams it's broken.

I also will give a try on Monitor GPIO, which , if it works, will retrun the state of the gpio.

Regarding opinion i share yours. A switch shall close two leads and have it's state possible to be read. Anyway, let's see what the solution will be.

Thank you very much for the help.

BR

Post Reply

Who is online

Users browsing this forum: RayEbb and 5 guests