Sonoff 4ch Pro, ESPeasy button/rule problem

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
emosbaek
New user
Posts: 6
Joined: 14 Mar 2018, 17:39
Location: Norway

Sonoff 4ch Pro, ESPeasy button/rule problem

#1 Post by emosbaek » 14 Mar 2018, 18:04

Hello,

I hope this is the correctly posted.

I'm trying to create a rule where button press activates one of the four relays in the opposite state. It always works for "on", but never for "off". And when its activated for "on" it takes a few seconds and it returns to "off".

My codes for "Rules"

Code: Select all

on System#Boot do
	GPIO,15,0
	GPIO,12,0
	GPIO,5,0
	GPIO,4,0
endon

on Button1#Button do
	if [GPIO12#State] = 1
		GPIO,12,0
		SendToHTTP 192.168.1.119,3480,/data_request?id=action&output_format=json&DeviceNum=16&serviceId=urn:upnp-org:serviceId:SwitchPower1&action=SetTarget&newTargetValue=1
	else
		GPIO,12,1
		SendToHTTP 192.168.1.119,3480,/data_request?id=action&output_format=json&DeviceNum=16&serviceId=urn:upnp-org:serviceId:SwitchPower1&action=SetTarget&newTargetValue=0
	endif
endon

log

Code: Select all

167070 : SW : Switch state 1 Output value 0
167073 : EVENT: Button1#Button=0.00
167088 : ACT : GPIO,12,1
167089 : SW : GPIO 12 Set to 1
167096 : ACT : SendToHTTP 192.168.1.119,3480,/data_request?id=action&output_format=json&DeviceNum=16&serviceId=urn:upnp-org:serviceId:S
168133 : Timeout while reading input data!
168138 : SW : GPIO 12 Set to 0

Buttons settings
ESPeasy Button settings.JPG
ESPeasy Button settings.JPG (75.03 KiB) Viewed 10254 times

Relay settings
ESPeasy Relay settings.JPG
ESPeasy Relay settings.JPG (75.49 KiB) Viewed 10254 times

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

Re: Sonoff 4ch Pro, ESPeasy button/rule problem

#2 Post by grovkillen » 14 Mar 2018, 18:38

[GPIO12#State] = 1 should be [Relay1#Switch] = 1 (please do not use spaces in task names). Calling for gpio state is not yet documented and implemented.
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:

emosbaek
New user
Posts: 6
Joined: 14 Mar 2018, 17:39
Location: Norway

Re: Sonoff 4ch Pro, ESPeasy button/rule problem

#3 Post by emosbaek » 14 Mar 2018, 19:59

grovkillen wrote: 14 Mar 2018, 18:38 [GPIO12#State] = 1 should be [Relay1#Switch] = 1 (please do not use spaces in task names). Calling for gpio state is not yet documented and implemented.
Thank you very much for your reply.

I totally agree. Spaces in task names in code is not good. But added it because i like spaces in overviews and tables. But it's corrected now.
Changed from "state" to "switch". (also changed button value from "Button" to "press". more code friendly)


The is the new error: (Just to be clear, i only pressed once)

Code: Select all

1493556 : SW : Switch state 1 Output value 0
1493559 : EVENT: Button1#Press=0.00
1493571 : ACT : GPIO,12,1
1493572 : SW : GPIO 12 Set to 1
1493656 : SW : Switch state 1 Output value 1
1493658 : EVENT: Relay1#Switch=1.00
1494586 : HTTP : connection failed
1497935 : SW : Switch state 1 Output value 1
1497937 : EVENT: Button1#Press=1.00
1497949 : ACT : GPIO,12,0
1497949 : SW : GPIO 12 Set to 0
1498035 : SW : Switch state 0 Output value 0
1498037 : EVENT: Relay1#Switch=0.00
1498964 : HTTP : connection failed

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

Re: Sonoff 4ch Pro, ESPeasy button/rule problem

#4 Post by grovkillen » 14 Mar 2018, 20:26

Since it's a momentary button it will go to 0 once you release it = making the button#press trigger again. Use this instead :

Code: Select all

on Button1#Press=1 do
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:

emosbaek
New user
Posts: 6
Joined: 14 Mar 2018, 17:39
Location: Norway

Re: Sonoff 4ch Pro, ESPeasy button/rule problem

#5 Post by emosbaek » 14 Mar 2018, 21:13

grovkillen wrote: 14 Mar 2018, 20:26 Since it's a momentary button it will go to 0 once you release it = making the button#press trigger again. Use this instead :

Code: Select all

on Button1#Press=1 do
Thank you.

I added the "=1", but it still keeps turning off.

After some investigation i noticed under "Devices" that the pressed button keeps its value high/1 forcing the relay to toggle due to the rule. So i added GPIO,0,0 (which is the button) to run after the GPIO output where changed. But nor in the rule or Tool Commands can i set GPIO 0 low :shock:

Code: Select all

34679 : SW : Switch state 1 Output value 0
34681 : EVENT: Button1#Press=0.00
34690 : WD : Uptime 1 ConnectFailures 0 FreeMem 19472
35378 : SW : Switch state 1 Output value 1
35378 : EVENT: Button1#Press=1.00
35384 : ACT : GPIO,12,1
35385 : SW : GPIO 12 Set to 1
35386 : ACT : GPIO,0,0
35386 : SW : GPIO 0 Set to 0
35690 : SW : Switch state 1 Output value 1
35691 : EVENT: Relay1#Switch=1.00
36701 : HTTP : connection failed
39755 : SW : Switch state 1 Output value 0
39762 : EVENT: Button1#Press=0.00
61101 : SW : Switch state 1 Output value 1
61102 : EVENT: Button1#Press=1.00
61109 : ACT : GPIO,12,0
61109 : SW : GPIO 12 Set to 0
61110 : ACT : GPIO,0,0
61111 : SW : GPIO 0 Set to 0
61201 : SW : Switch state 0 Output value 0
61203 : EVENT: Relay1#Switch=0.00

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

Re: Sonoff 4ch Pro, ESPeasy button/rule problem

#6 Post by grovkillen » 14 Mar 2018, 22:01

What version do you use?
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:

emosbaek
New user
Posts: 6
Joined: 14 Mar 2018, 17:39
Location: Norway

Re: Sonoff 4ch Pro, ESPeasy button/rule problem

#7 Post by emosbaek » 14 Mar 2018, 22:14

GIT version: v2.0-20180311

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

Re: Sonoff 4ch Pro, ESPeasy button/rule problem

#8 Post by grovkillen » 15 Mar 2018, 05:37

Try latest, some fixes to the rule engine has been made since that version.
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:

emosbaek
New user
Posts: 6
Joined: 14 Mar 2018, 17:39
Location: Norway

Re: Sonoff 4ch Pro, ESPeasy button/rule problem

#9 Post by emosbaek » 15 Mar 2018, 15:15

Loaded the newest firmware (GIT version: mega-20180315), set it up from scratch without uploading the old config, but still the same problem.

GPIO-0 (button1) stays high after its pressed and relay is latched and wont go low without a hard reset (only solution so far) :|

emosbaek
New user
Posts: 6
Joined: 14 Mar 2018, 17:39
Location: Norway

Re: Sonoff 4ch Pro, ESPeasy button/rule problem

#10 Post by emosbaek » 15 Mar 2018, 15:48

Well this is awkward.. :oops:

I changed all the dip-swtiches on "K5" & "K6" to 'ON'. Now its atleast locking. Next step is to see if i can press the button to release it :)

As far as i can see, this i hardware related and not software.
admin: feel free to move this to correct forum if needed.


Image
Last edited by emosbaek on 15 Mar 2018, 18:45, edited 3 times in total.

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

Re: Sonoff 4ch Pro, ESPeasy button/rule problem

#11 Post by grovkillen » 15 Mar 2018, 15:49

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
Methuselah
Normal user
Posts: 45
Joined: 04 Feb 2018, 01:39
Location: Boston, MA

Re: Sonoff 4ch Pro, ESPeasy button/rule problem

#12 Post by Methuselah » 15 Mar 2018, 23:38

I use a Sonoff 4CH Pro to control a remote antenna switch. Either by sending an event to the controller, or via the buttons. When I press a button, my state changes from 0 to 1 or 1 to 0 and stays that way until I change it again (or a reset).

My configuration:

Image

My rules:

Code: Select all


on Button1#Press do
   if [GPIO12#State] = 0
      GPIO,12,1
   else
      GPIO,12,0
   endif
endon

N00b to the world of ESPEasy, but I've been programming since the days of punch cards and paper tape :)

hacimsenigma
New user
Posts: 1
Joined: 22 Apr 2019, 13:50

Re: Sonoff 4ch Pro, ESPeasy button/rule problem

#13 Post by hacimsenigma » 22 Apr 2019, 13:52

Old post I know,

Change the Value from "State" to "Switch"

Post Reply

Who is online

Users browsing this forum: No registered users and 18 guests