Page 1 of 1

Rules Help

Posted: 18 Jan 2019, 13:59
by angelo-filippi
hi to all, I'm new in the forum.
I recently met this wonderful software, it's really well done. I ask you for a suggestion for the application of a simple rule.
I'm using a wemosd1r1
in the GPIO 13 a pullup switch is connected. The GPIO at BOOT is in default configuration
I would like that: when the pullup switch goes to 1 (gpio13,1)
the gpio 14 goes to 1 (gpio14,1)

I use the gpio14 for other services in mqtt to nodered without any problem

I applied the rule I found at the address
https://espeasy.readthedocs.io/en/lates ... Rules.html

Without any success.

I did a more in-depth search in the forum and in google and applied many variations, without success.
I ask you if you can tell me which is the best solution, and how to apply it.

I enclose the photos of my configuration.

I thank those who want to help me.

Angelo Filippi

Re: Rules Help

Posted: 18 Jan 2019, 14:41
by dynamicdave
In your screenshots, your device name is Switch1 and the value is called State.

In the rules you have used... on Button#State=1 do

I think it should be... on Switch1#State=1 do

Regards, David

Re: Rules Help

Posted: 18 Jan 2019, 16:09
by angelo-filippi
Hi thank you for the reply
i have applied you suggestion but nothing...

now the rules are:

on Switch1#State=1 do
timerSet,1,1
endon
on rules#timer=1 do
if [Switch1#State]=0
gpio,14,1
endif
endon

the GPIO14 is always turned off.

how to have the same result using in the rules mqtt?

Re: Rules Help

Posted: 18 Jan 2019, 16:23
by grovkillen
angelo-filippi wrote: 18 Jan 2019, 16:09 Hi thank you for the reply
i have applied you suggestion but nothing...

now the rules are:

on Switch1#State=1 do
timerSet,1,1
endon
on rules#timer=1 do
if [Switch1#State]=0
gpio,14,1
endif
endon

the GPIO14 is always turned off.

how to have the same result using in the rules mqtt?

Code: Select all

on Switch1#State=1 do
timerSet,1,1
endon
on rules#timer=1 do
if [Switch1#State]=0
gpio,14,1
else
gpio,14,0
endif
endon


Re: Rules Help

Posted: 18 Jan 2019, 16:41
by angelo-filippi
Thank you for the reply,

no, the GPIO14 is always turned off

2704105: SW : GPIO=13 State=0 Output value=1
2704112: EVENT: Switch1#State=1.00
2705205: SW : GPIO=13 State=0 Output value=0
2705212: EVENT: Switch1#State=0.00

Re: Rules Help

Posted: 18 Jan 2019, 19:24
by grovkillen
You're using the newer version which got double click and long press already. Use those events instead.

Re: Rules Help

Posted: 18 Jan 2019, 19:25
by grovkillen

Re: Rules Help

Posted: 19 Jan 2019, 00:19
by angelo-filippi
Mmm.
I read the wiki. I thought about using a single event.

Thank you very much for helping.
I try your suggestion as soon as possible.
Espeasy is fantastic.
Congratulations to the whole development team

Re: Rules Help

Posted: 21 Jan 2019, 15:56
by fraeggle
How long should gpio 14 be 1? As long as gpio 13 is 1 or should gpio 13 toggle 14?

as long as gpio13 is 1:

on Switch1#State do
if [Switch1#State]=1
gpio,14,1
else
gpio,14,0
endif
endon

Don*t know why you use the timer

in this Case (toggle everytime gpio 13 gets 1) i use Dummy Device (task12, Name = status, first value name = io14) to show the state of the io14
maybe the very first "toggle" goes wrong, because io14 and dummy is not equal. And if you change io14 in another way (second switch or mqtt) you should update the TaskValueSet too.

on Switch1#State=1 do
If [status#io14]=1 -----> Dummy Device
TaskValueSet,12,1,0 -----> set Dummy Device like gpio
GPIO,14,0
Else
TaskValueSet,12,1,1
GPIO,14,1
EndIf
EndOn

Re: Rules Help

Posted: 21 Jan 2019, 23:11
by angelo-filippi
Dear friends, thank you again for your precious help.
I followed your generous instructions, unfortunately without luck.
I applied the rules you suggested to me, I really did the most disparate tests
yet it is simple.
at boot the gpio14 is at 0
1 press on the button (gpio13)
the gpio14 (led) must light up.
1 press on the button (gpio13)
the gpio14 (led) must go off.

If possible without mqtt.

@fraeggle I used the timer because it is written in the wiki.
thanks for the suggestion on using the dummy device,
using the rules you suggested, but no success, I attach my configuration.

THANK YOU FOR ALL





{"System":{
"Build":20103,
"Git Build":"mega-20190108",
"System libraries":"ESP82xx Core 2_4_2, NONOS SDK 2.2.1(cfd48f3), LWIP: 2.0.3 PUYA support",
"Plugins":46,
"Plugin description":" [Normal]",
"Local time":"2019-01-21 23:03:02",
"Unit":1,
"Name":"ESP_Easy",
"Uptime":69,
"Last boot cause":"Cold boot",
"Reset Reason":"External System",
"Load":25.00,
"Load LC":6776,
"Free RAM":17744
},
"WiFi":{
"Hostname":"ESP-Easy-1",
"IP config":"DHCP",
"IP":"192.168.20.243",
"Subnet Mask":"255.255.255.0",
"Gateway IP":"192.168.20.1",
"MAC address":"60:01:94:70:09:0F",
"DNS 1":"8.8.8.8",
"DNS 2":"0.0.0.0",
"SSID":"WIFI-01",
"BSSID":"E4:8D:8C:D4:55:29",
"Channel":1,
"Connected msec":4149297,
"Last Disconnect Reason":1,
"Last Disconnect Reason str":"(1) Unspecified",
"Number reconnects":0,
"RSSI":-42
},
"Sensors":[
{
"DataAcquisition": [
{"Controller":1,
"IDX":0,
"Enabled":"false"
},
{"Controller":2,
"IDX":0,
"Enabled":"false"
},
{"Controller":3,
"IDX":0,
"Enabled":"false"
}],
"TaskInterval":1,
"Type":"Display - LCD2004",
"TaskName":"LCD",
"TaskEnabled":"true",
"TaskNumber":1
},
{
"TaskValues": [
{"ValueNumber":1,
"Name":"Temp",
"NrDecimals":1,
"Value":19.3
},
{"ValueNumber":2,
"Name":"Hum",
"NrDecimals":1,
"Value":48.7
}],
"DataAcquisition": [
{"Controller":1,
"IDX":1,
"Enabled":"true"
},
{"Controller":2,
"IDX":0,
"Enabled":"false"
},
{"Controller":3,
"IDX":0,
"Enabled":"false"
}],
"TaskInterval":60,
"Type":"Environment - DHT11/12/22 SONOFF2301/7021",
"TaskName":"DHT22",
"TaskEnabled":"true",
"TaskNumber":2
},
{
"TaskValues": [
{"ValueNumber":1,
"Name":"State",
"NrDecimals":0,
"Value":1
}],
"DataAcquisition": [
{"Controller":1,
"IDX":0,
"Enabled":"true"
},
{"Controller":2,
"IDX":3,
"Enabled":"true"
},
{"Controller":3,
"IDX":0,
"Enabled":"false"
}],
"TaskInterval":0,
"Type":"Switch input - Switch",
"TaskName":"Switch1",
"TaskEnabled":"true",
"TaskNumber":3
},
{
"TaskValues": [
{"ValueNumber":1,
"Name":"io14",
"NrDecimals":2,
"Value":0.00
},
{"ValueNumber":2,
"Name":"",
"NrDecimals":2,
"Value":0.00
},
{"ValueNumber":3,
"Name":"",
"NrDecimals":2,
"Value":0.00
},
{"ValueNumber":4,
"Name":"",
"NrDecimals":2,
"Value":0.00
}],
"DataAcquisition": [
{"Controller":1,
"IDX":0,
"Enabled":"true"
},
{"Controller":2,
"IDX":4,
"Enabled":"true"
},
{"Controller":3,
"IDX":0,
"Enabled":"false"
}],
"TaskInterval":60,
"Type":"Generic - Dummy Device",
"TaskName":"status",
"TaskEnabled":"true",
"TaskNumber":4
}
],
"TTL":60000
}

Re: Rules Help

Posted: 22 Jan 2019, 08:42
by kimot
At first you wrote you switch gpio13 by pulling it up.
But in your first configuration screenshot I can see internal pullup enabled.
So your gpio13 is on log. 1 in standby and you must switch to ground and check log. low state when switch is pressed.

If I understand well, you want to change the status of the led output every time you press the button.
I had a similar project for switching on and switching off light using a button and using commands sent from other ESPs and Domoticz along with sending the current status back to Domoticz.

My rules ( gpio12 - relay, gpio13 - LED

Code: Select all

on lamp_on do
    gpio,12,1
    gpio,13,0
endon

on lamp_off do
    gpio,12,0
    gpio,13,1
endon

on lamp_change do
  if [rele#Switch]=1
    event,lamp_off
    SendToHTTP 192.168.1.253,8080,/json.htm?type=command&param=switchlight&idx=19&switchcmd=Off
  else
    event,lamp_on
    SendToHTTP 192.168.1.253,8080,/json.htm?type=command&param=switchlight&idx=19&switchcmd=On
  endif
endon

on SW01#Switch do
  event,lamp_change
endon
I am using old "stable" versions _dev13 and V2.0 and defined auxiliary input switch on the same gpio like relay is, so I can check actual relay status by reading [rele#Switch]

An example of a similar device configuration but from another project, so relay is on gpio-5:
2018-11-03-210641_1920x1080_scrot.png
2018-11-03-210641_1920x1080_scrot.png (121.37 KiB) Viewed 7004 times
But in actual mega versions of firmware this is maybe not possible.
I read something like this in a forum.

Re: Rules Help

Posted: 22 Jan 2019, 10:45
by fraeggle
kimot wrote: 22 Jan 2019, 08:42 At first you wrote you switch gpio13 by pulling it up.
But in your first configuration screenshot I can see internal pullup enabled.
So your gpio13 is on log. 1 in standby and you must switch to ground and check log. low state when switch is pressed.


You are right... haven't seen this.
@angelo-filippi:
How is your switch and GPIO13 connected.
can you try following:
GPIO 13 connectect via 10k to Ground and via 1k and switch to 5V.
Change GPIO Device to Pullup Enabled normal switch...


Gnd ------| 10k |----O------| 1K |----/ --------> 5V
|
|-----> Gpio13

Re: Rules Help

Posted: 22 Jan 2019, 11:06
by kimot
Simply enable pullup and through switch connect gpio to ground.

Re: Rules Help

Posted: 22 Jan 2019, 15:22
by fraeggle
fraeggle wrote: 22 Jan 2019, 10:45
kimot wrote: 22 Jan 2019, 08:42 At first you wrote you switch gpio13 by pulling it up.
But in your first configuration screenshot I can see internal pullup enabled.
So your gpio13 is on log. 1 in standby and you must switch to ground and check log. low state when switch is pressed.


You are right... haven't seen this.
@angelo-filippi:
How is your switch and GPIO13 connected.
can you try following:
GPIO 13 connectect via 10k to Ground and via 1k and switch to 5V.
Change GPIO Device to Pullup Enabled normal switch...


Gnd ------| 10k |----O------| 1K |----/ --------> 5V
|
|-----> Gpio13
ups gpio 13 should be between 10k and 1k,



He wrote "I would like that: when the pullup switch goes to 1 (gpio13,1), the gpio 14 goes to 1 (gpio14,1)"

by kimot » 22 Jan 2019, 11:06
Simply enable pullup and through switch connect gpio to ground. ---> in this case GPIO13 is 1 and 0 wenn pressed (if he usese a normal button. Ok in the end it will be the same effect, but then it would be better to change if GPIO 13 goes 0).