Help With Rules

Moderators: Voyager, BertB, rtenklooster, Stuntteam, Martinus, grovkillen, TD-er

Message
Author
potzkiin
Normal user
Posts: 28
Joined: 04 Sep 2018, 09:15

Help With Rules

#1 Post by potzkiin » 04 Sep 2018, 09:21

hello,
im trying to setup a physical SW with Relay and Mqtt.

so far i managed to control relay via the switch
the problem is when i controlling via mqtt the sw status remain as it was before and it need 2 pulses to sync to the current status and toggle the relay..

this is the rule im using:
on System#Boot do
gpio,0,1 // Prevent relay turning on during boot
endon

on sw1#sw1 do
if [sw1#sw1]=0
gpio,0,1
gpio,16,1
else
gpio,0,0
gpio,16,0
endif
endon


if anyone can helo make the rule better so the mqtt command will sync the button to correct status as well?

User avatar
grovkillen
Normal user
Posts: 1900
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

Re: Help With Rules

#2 Post by grovkillen » 04 Sep 2018, 10:08

Code: Select all

on System#Boot do
gpio,0,1 // Prevent relay turning on during boot
endon

on sw1#sw1 do
 Event,toggleSwitch
endon

On toggleSwitch Do
 if [sw1#sw1]=0
  gpio,0,1
  gpio,16,1
 else
  gpio,0,0
  gpio,16,0
 endif
EndOn
Trigger using MQTT by sending "Event, toggleSwitch" on the topic ending with "cmd". See more about the in the rules tutorials.
ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Sponsor ESP Easy, we need you :idea: :idea: :idea:

potzkiin
Normal user
Posts: 28
Joined: 04 Sep 2018, 09:15

Re: Help With Rules

#3 Post by potzkiin » 04 Sep 2018, 10:25

im using
"payload": "GPIO,0,1 or 0",
"topic": "/test/cmd"

that's controlling the relay...but button get out of sync....

User avatar
grovkillen
Normal user
Posts: 1900
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

Re: Help With Rules

#4 Post by grovkillen » 04 Sep 2018, 10:35

So use my example? That is what making it stay in sync, by letting the unit itself handle the state. Thus the event name "toggle" switch.
ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Sponsor ESP Easy, we need you :idea: :idea: :idea:

potzkiin
Normal user
Posts: 28
Joined: 04 Sep 2018, 09:15

Re: Help With Rules

#5 Post by potzkiin » 04 Sep 2018, 11:12

yes i try it and i got the same results..

potzkiin
Normal user
Posts: 28
Joined: 04 Sep 2018, 09:15

Re: Help With Rules

#6 Post by potzkiin » 04 Sep 2018, 11:26

as i understand i need some rule to listen to my mqtt command an execute the switch mode according to the mqtt topic...

User avatar
grovkillen
Normal user
Posts: 1900
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

Re: Help With Rules

#7 Post by grovkillen » 04 Sep 2018, 11:51

Please be more informative. The rule I posted should work but you may please post your entire setup since I don't know what gpio 0 is doing for example. And what is the exact topic and payload you're sending? What is the unit name etc etc.
ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Sponsor ESP Easy, we need you :idea: :idea: :idea:

potzkiin
Normal user
Posts: 28
Joined: 04 Sep 2018, 09:15

Re: Help With Rules

#8 Post by potzkiin » 04 Sep 2018, 12:21

rule:
on System#Boot do
gpio,0,1 // Prevent relay turning on during boot
endon

on sw1#sw1 do
Event,toggleSwitch
endon

On toggleSwitch Do
if [sw1#sw1]=0
gpio,0,1
gpio,16,1
else
gpio,0,0
gpio,16,0
endif
EndOn
Image
Image
Image


i don't want to use switch toggle in mqtt.. as i want to be able to use mqtt set 1 or 0 or on or off.
Attachments
Hardware.jpg
Hardware.jpg (53.4 KiB) Viewed 373 times
Devices.jpg
Devices.jpg (38.91 KiB) Viewed 373 times
Config.jpg
Config.jpg (80.24 KiB) Viewed 385 times
Last edited by potzkiin on 04 Sep 2018, 13:46, edited 1 time in total.

User avatar
grovkillen
Normal user
Posts: 1900
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

Re: Help With Rules

#9 Post by grovkillen » 04 Sep 2018, 12:27

If you want to be able to set given 1 or 0 I suggest you use event values for that and tweak my rules to work with them. See wiki please.
ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Sponsor ESP Easy, we need you :idea: :idea: :idea:

User avatar
grovkillen
Normal user
Posts: 1900
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

Re: Help With Rules

#10 Post by grovkillen » 04 Sep 2018, 12:28

Because then you can set

GPIO,16,%eventvalue%
ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Sponsor ESP Easy, we need you :idea: :idea: :idea:

potzkiin
Normal user
Posts: 28
Joined: 04 Sep 2018, 09:15

Re: Help With Rules

#11 Post by potzkiin » 04 Sep 2018, 13:45

if you can help me with the rule? im pretty new to this..

User avatar
grovkillen
Normal user
Posts: 1900
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

Re: Help With Rules

#12 Post by grovkillen » 04 Sep 2018, 14:00

First of all. I suggest you only monitor the GPIO state of the relay by assigning it to a "Generic Switch" task. Then you can act upon the switch being pressed and if the relay switch is 0 then it will turn to 1 if you use the toggleSwitch example I suggested.

If you want to also be able to turn the relay on or off specifically you can use another event called setSwitch and pass along a 1 or a 0. You will find this if you study the wiki.
ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Sponsor ESP Easy, we need you :idea: :idea: :idea:

potzkiin
Normal user
Posts: 28
Joined: 04 Sep 2018, 09:15

Re: Help With Rules

#13 Post by potzkiin » 04 Sep 2018, 14:34

went trough the wiki for days..can find a solution.
i found not only me struggling with this issue over the net..

potzkiin
Normal user
Posts: 28
Joined: 04 Sep 2018, 09:15

Re: Help With Rules

#14 Post by potzkiin » 04 Sep 2018, 14:55

can i do something like this?
wherever the relay togle the input SW change also?

on Relay01#Relay01 do
if [Relay01#Relay01]=0
gpio,12,0
elese
gpio,12,1
endif
endon

i really dont know how to do what you suggested.

User avatar
grovkillen
Normal user
Posts: 1900
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

Re: Help With Rules

#15 Post by grovkillen » 04 Sep 2018, 15:19

You should try this then.

Code: Select all

On Switch01#State Do
 Event,toggleRelay
EndOn

On toggleRelay Do
 if [Relay01#State]=0
  event,setRelay,1
 else
  event,setRelay,0
 endif
EndOn

On setRelay Do
 GPIO,12,%eventvalue%
EndOn
I suggest you rename the value name to something like "State" since it's bad practice to use the same name for task name and value name.

By using this you can use topic /test/cmd (or whatever your MQTT controller settings are) and send one of three different payloads:

Code: Select all

event,toggleRelay
event,setRelay,1
event,setRelay,0
Last edited by grovkillen on 04 Sep 2018, 17:34, edited 1 time in total.
ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Sponsor ESP Easy, we need you :idea: :idea: :idea:

potzkiin
Normal user
Posts: 28
Joined: 04 Sep 2018, 09:15

Re: Help With Rules

#16 Post by potzkiin » 04 Sep 2018, 16:13

First Thnaks for all your effort to help is much appreciated!
i changed the value to "State" as you suggested

also the rule to fit my names...but i guessing i did something wrong because there is no switch action or mqtt action with event,toggeleRelay01

on System#Boot do
gpio,0,1 // Prevent relay turning on during boot
endon

On sw1#State Do
Event,toggleRelay01
EndOn

On toggleRelay01 Do
if [Relay01#State]=0
event,setRelay01,1
elese
event,setRelay01,0
endif
EndOn

On setRelay01 Do
GPIO,12,%eventvalue%
EndOn
Attachments
state.jpg
state.jpg (40.43 KiB) Viewed 338 times

User avatar
grovkillen
Normal user
Posts: 1900
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

Re: Help With Rules

#17 Post by grovkillen » 04 Sep 2018, 17:21

Code: Select all

toggeleRelay01
Check spelling.

I also see that I misspelled "else" with "elese". I have updated the previous post now.
ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Sponsor ESP Easy, we need you :idea: :idea: :idea:

TD-er
Normal user
Posts: 1052
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Help With Rules

#18 Post by TD-er » 04 Sep 2018, 20:28

Please note that not all GPIO pins are behaving the same.
GPIO0 and 16 are 'special ones'.

- GPIO 0-15 all have a built-in pull-up resistor, just like in an Arduino. GPIO16 has a built-in pull-down resistor.
- GPIO15 is always pulled low, so you can’t use the internal pull-up resistor. You have to keep this in mind when using GPIO15 as an input to read a switch or connect it to a device with an open-collector (or open-drain) output, like I²C.
- GPIO0 is pulled high during normal operation, so you can’t use it as a Hi-Z input.
- GPIO2 can’t be low at boot, so you can’t connect a switch to it.

potzkiin
Normal user
Posts: 28
Joined: 04 Sep 2018, 09:15

Re: Help With Rules

#19 Post by potzkiin » 05 Sep 2018, 08:12

TD-er wrote:
04 Sep 2018, 20:28
Please note that not all GPIO pins are behaving the same.
GPIO0 and 16 are 'special ones'.

- GPIO 0-15 all have a built-in pull-up resistor, just like in an Arduino. GPIO16 has a built-in pull-down resistor.
- GPIO15 is always pulled low, so you can’t use the internal pull-up resistor. You have to keep this in mind when using GPIO15 as an input to read a switch or connect it to a device with an open-collector (or open-drain) output, like I²C.
- GPIO0 is pulled high during normal operation, so you can’t use it as a Hi-Z input.
- GPIO2 can’t be low at boot, so you can’t connect a switch to it.
Thanks for the info!

potzkiin
Normal user
Posts: 28
Joined: 04 Sep 2018, 09:15

Re: Help With Rules

#20 Post by potzkiin » 05 Sep 2018, 08:16

grovkillen wrote:
04 Sep 2018, 17:21

Code: Select all

toggeleRelay01
Check spelling.

I also see that I misspelled "else" with "elese". I have updated the previous post now.
on System#Boot do
gpio,0,1 // Prevent relay turning on during boot
endon

On sw1#State Do
Event,toggleRelay01
EndOn

On toggleRelay01 Do
if [Relay01#State]=0
event,setRelay01,1
else
event,setRelay01,0
endif
EndOn

On setRelay01 Do
GPIO,12,%eventvalue%
EndOn



i attached the log, i can see the commands but no relay toggle.
Attachments
log.jpg
log.jpg (46.37 KiB) Viewed 283 times

User avatar
grovkillen
Normal user
Posts: 1900
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

Re: Help With Rules

#21 Post by grovkillen » 05 Sep 2018, 08:33

Sorry, totally my fault. I'm writing these messages on my phone in the forest of northern Sweden (hunting moose).

Correct syntax for event value is it use "="

Code: Select all

On Switch01#State Do
 Event,toggleRelay
EndOn

On toggleRelay Do
 if [Relay01#State]=0
  event,setRelay=1
 else
  event,setRelay=0
 endif
EndOn

On setRelay Do
 GPIO,12,%eventvalue%
EndOn
And commands over MQTT should be these:

Code: Select all

event,toggleRelay
event,setRelay=1
event,setRelay=0
ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Sponsor ESP Easy, we need you :idea: :idea: :idea:

potzkiin
Normal user
Posts: 28
Joined: 04 Sep 2018, 09:15

Re: Help With Rules

#22 Post by potzkiin » 05 Sep 2018, 09:47

your activity on the woods sound like so much fun :) ....in my place it is not allowed,

any way...
when i call the mqtt with event,setRelay01=1 i can see the rule respond but no relay toggle and also there is no switch action.(even no mqtt topic when pressing on the sw1)

this is my rule:

on System#Boot do
gpio,0,1 // Prevent relay turning on during boot
endon

On sw1#State Do
Event,toggleRelay01
EndOn

On toggleRelay01 Do
if [Relay01#State]=0
Event,setRelay01=1
else
Event,setRelay01=0
endif
EndOn

On setRelay01 Do
GPIO,12,%eventvalue%
EndOn
Attachments
log.jpg
log.jpg (58.81 KiB) Viewed 363 times

User avatar
grovkillen
Normal user
Posts: 1900
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

Re: Help With Rules

#23 Post by grovkillen » 05 Sep 2018, 10:16

It looks like the rules I provided are working as they should. But you now suggest that you want a switch press to send a MQTT message as well, news to me. You do that with the publish command and you can place that in the sw1#State event.

Regarding the relay not responding, are you sure it's connected to GPIO 12? And is the relay01 task correctly configured with name and GPIO?
ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Sponsor ESP Easy, we need you :idea: :idea: :idea:

User avatar
grovkillen
Normal user
Posts: 1900
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

Re: Help With Rules

#24 Post by grovkillen » 05 Sep 2018, 10:21

I see now that your running ancient version R147. The code I provide are for later releases. Sorry! Dude, we really need a better forum that can snatch the info from the unit so we don't do mistakes like this.
ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Sponsor ESP Easy, we need you :idea: :idea: :idea:

potzkiin
Normal user
Posts: 28
Joined: 04 Sep 2018, 09:15

Re: Help With Rules

#25 Post by potzkiin » 05 Sep 2018, 18:42

What stable version do you suggest?

User avatar
grovkillen
Normal user
Posts: 1900
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

Re: Help With Rules

#26 Post by grovkillen » 05 Sep 2018, 18:44

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

User avatar
grovkillen
Normal user
Posts: 1900
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

Re: Help With Rules

#27 Post by grovkillen » 05 Sep 2018, 18:45

But you should always test on a none production unit, so everything is working all right before you start using it for real
ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Sponsor ESP Easy, we need you :idea: :idea: :idea:

potzkiin
Normal user
Posts: 28
Joined: 04 Sep 2018, 09:15

Re: Help With Rules

#28 Post by potzkiin » 05 Sep 2018, 18:45

Thanks! Will upload tommorow:-)

potzkiin
Normal user
Posts: 28
Joined: 04 Sep 2018, 09:15

Re: Help With Rules

#29 Post by potzkiin » 06 Sep 2018, 13:35

Hi again.
i updated the version. to Release mega-20180904
but got the same problem.

1.the SW1 won't toggle the relay.(i cant see any log for switch press either..)
its seems that this rule:
"On setRelay01 Do
GPIO,12,%eventvalue%
EndOn"
when setting it to GPIO 12 where the switch is connected it making the value constant 1 or 0 and make it ignoring the actual input of the switch.
if i remove the GPIO12 from this rule the sw will respond to switch press. but relay wont toggle.

2.mqtt command event,setRelay01=1 change the status of SW1 but wont toggle the relay.

User avatar
grovkillen
Normal user
Posts: 1900
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

Re: Help With Rules

#30 Post by grovkillen » 06 Sep 2018, 17:19

The fact that the MQTT command is setting the switch state and not the relay suggest to me that the GPIO is mixed up.
ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Sponsor ESP Easy, we need you :idea: :idea: :idea:

potzkiin
Normal user
Posts: 28
Joined: 04 Sep 2018, 09:15

Re: Help With Rules

#31 Post by potzkiin » 06 Sep 2018, 17:45

Hi,
i uploaded the devices and rule.
gpio 12 is the switch input
gpio 0 is the relay..
Attachments
Devices.jpg
Devices.jpg (115.23 KiB) Viewed 374 times

User avatar
grovkillen
Normal user
Posts: 1900
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

Re: Help With Rules

#32 Post by grovkillen » 06 Sep 2018, 17:56

Then you need to use GPIO,0,%eventvalue% not 12. But remember that GPIO 0 will be high on boot. This will cause the relay to trigger if the unit reboots.
ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Sponsor ESP Easy, we need you :idea: :idea: :idea:

potzkiin
Normal user
Posts: 28
Joined: 04 Sep 2018, 09:15

Re: Help With Rules

#33 Post by potzkiin » 06 Sep 2018, 18:53

Im using this rule:
on System#Boot do
gpio,0,1 // Prevent relay turning on during boot
endon

User avatar
grovkillen
Normal user
Posts: 1900
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

Re: Help With Rules

#34 Post by grovkillen » 06 Sep 2018, 19:09

Yes but setting the switch to 1 or 0 doesn't make any sense. The switch is only used to get human interaction. The setRelay event should thus be used to set the GPIO-0 to 1 (or 0).
ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Sponsor ESP Easy, we need you :idea: :idea: :idea:

potzkiin
Normal user
Posts: 28
Joined: 04 Sep 2018, 09:15

Re: Help With Rules

#35 Post by potzkiin » 06 Sep 2018, 19:23

Sorry..but i cant understand...im setting a start point when boot and calling gpio 0 (the relay) to start point of 1or0 of the relay .Im setting the relay not the switch.
Im confused..

User avatar
grovkillen
Normal user
Posts: 1900
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

Re: Help With Rules

#36 Post by grovkillen » 06 Sep 2018, 21:17

Just try to change this part

Code: Select all

On setRelay Do
 GPIO,12,%eventvalue%
EndOn
To this

Code: Select all

On setRelay Do
 GPIO,0,%eventvalue%
EndOn
ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Sponsor ESP Easy, we need you :idea: :idea: :idea:

werner_g
Normal user
Posts: 21
Joined: 11 Jun 2017, 14:19

Re: Help With Rules

#37 Post by werner_g » 10 Sep 2018, 12:45

Everlasting questions about rules... Perhaps somebody can have a look on this:

Code: Select all

on Water#state do
   event, Vent01auf=%eventvalue%
endon

on Vent01auf=1 do
   Pulse,16,1,100
   Pulse,12,1,50
   Pulse,13,0,50    //start watering (open Vent1)
   Publish aussen/state/WM/Garten01/Water/Vent1,1
   timerSet,1,300   //timer 1 set for 5 minutes
endon

on Vent01auf=0 do
   timerSet,1,0  //timer1 set to halt
   Pulse,16,1,100
   Pulse,12,0,50
   Pulse,13,1,50  //stop watering (close Vent1)
   Publish aussen/state/WM/Garten01/Water/Vent1,0
endon
MQTT import shows switching of state, the log reports Vent01auf= 1 or 0, but no action on ports or MQTT-publishing happens. Where is my mistake?

User avatar
grovkillen
Normal user
Posts: 1900
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

Re: Help With Rules

#38 Post by grovkillen » 10 Sep 2018, 18:07

werner_g wrote:
10 Sep 2018, 12:45
Everlasting questions about rules... Perhaps somebody can have a look on this:

Code: Select all

on Water#state do
   event, Vent01auf=%eventvalue%
endon

on Vent01auf=1 do
   Pulse,16,1,100
   Pulse,12,1,50
   Pulse,13,0,50    //start watering (open Vent1)
   Publish aussen/state/WM/Garten01/Water/Vent1,1
   timerSet,1,300   //timer 1 set for 5 minutes
endon

on Vent01auf=0 do
   timerSet,1,0  //timer1 set to halt
   Pulse,16,1,100
   Pulse,12,0,50
   Pulse,13,1,50  //stop watering (close Vent1)
   Publish aussen/state/WM/Garten01/Water/Vent1,0
endon
MQTT import shows switching of state, the log reports Vent01auf= 1 or 0, but no action on ports or MQTT-publishing happens. Where is my mistake?
Your not really sending any eventvalue in this part:

Code: Select all

on Water#state do
   event, Vent01auf=%eventvalue%
endon
Maybe you're meaning this?

Code: Select all

on Water#state do
   event, Vent01auf=[Water#state]
endon
ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Sponsor ESP Easy, we need you :idea: :idea: :idea:

werner_g
Normal user
Posts: 21
Joined: 11 Jun 2017, 14:19

Re: Help With Rules

#39 Post by werner_g » 11 Sep 2018, 17:21

Thanks for your input, grovkillen, but this little rule-modification brings my ESP to stop operation. Something is really wrong with your (and of course my) code! Please have a look again.

User avatar
grovkillen
Normal user
Posts: 1900
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

Re: Help With Rules

#40 Post by grovkillen » 11 Sep 2018, 17:30

What version did you use? And you cannot use events like this on Vent01auf=1 do

You probably need to use a dummy device and assign the event value to that one and then do a if statement to see what to do.

But it would certainly be a nice way of doing case statements possible.
ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Sponsor ESP Easy, we need you :idea: :idea: :idea:

User avatar
grovkillen
Normal user
Posts: 1900
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

Re: Help With Rules

#41 Post by grovkillen » 11 Sep 2018, 17:35

You could try:

on Vent01auf=1.00 do

&

on Vent01auf=0.00 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]
Sponsor ESP Easy, we need you :idea: :idea: :idea:

werner_g
Normal user
Posts: 21
Joined: 11 Jun 2017, 14:19

Re: Help With Rules

#42 Post by werner_g » 11 Sep 2018, 18:14

Hi grovkillen, I am using mega-20180625 and have a dozend ESP's running with that. I just wanted to have an event (gpio12, gpio13 and publish) available for using it in different dependencies (SW-switch, HW-switch, sensor-values etc.). To write a code case by case run's OK, but soon I oversize 2048 chars. It sounds too complicated for me to arrange a dummy device.
Oh, I've just see you latest input. Thanks, I will try this the other day.

werner_g
Normal user
Posts: 21
Joined: 11 Jun 2017, 14:19

Re: Help With Rules

#43 Post by werner_g » 11 Sep 2018, 18:19

Vent01auf=1.00 or Vent01auf=0.00: this are my events I want to use.

potzkiin
Normal user
Posts: 28
Joined: 04 Sep 2018, 09:15

Re: Help With Rules

#44 Post by potzkiin » 12 Sep 2018, 09:30

hi again...
i change the rules as you suggested but there are more issues,

- if i manually change the relay with the command /control?cmd=GPIO,0,1
AND then toggle sw1, the relay toggles. but only once(additional sw1 press is doing nothing).

- Also if i send payload: event,toggleRelay01 it only changes once to 0 from 1. and another event wont change the relay state.
- mqtt setRelay01/0 or 1 wont toggle the relay.

Logging: Info (2)
465812041: WD : Uptime 7764 ConnectFailures 2 FreeMem 19656
465837752: EVENT: toggleRelay01
465837779: ACT : Event,setRelay01=0
465837803: Command: event
465837803: EVENT: setRelay01=0
465837821: ACT : GPIO,0,0
465837823: SW : GPIO 0 Set to 0
465842041: WD : Uptime 7764 ConnectFailures 2 FreeMem 19656
465872041: WD : Uptime 7765 ConnectFailures 2 FreeMem 19728
465892175: EVENT: sw1#state=1.00
465892184: ACT : Event,toggleRelay01
465892241: Command: event
465892242: EVENT: toggleRelay01
465892270: ACT : Event,setRelay01=0
465892303: Command: event
465892303: EVENT: setRelay01=0
465892321: ACT : GPIO,0,0
465892323: SW : GPIO 0 Set to 0
465902041: WD : Uptime 7765 ConnectFailures 2 FreeMem 18832
465921973: SW : Switch state 0 Output value 0
465921975: EVENT: sw1#state=0.00
465921985: ACT : Event,toggleRelay01
465922039: Command: event
465922040: EVENT: toggleRelay01
465922068: ACT : Event,setRelay01=0
465922096: SW : Switch state 1 Output value 1
465922099: EVENT: sw1#state=1.00
465922109: ACT : Event,toggleRelay01
465922221: ACT : GPIO,0,0
465922223: SW : GPIO 0 Set to 0
465922228: Command: event
465922229: EVENT: toggleRelay01
465922254: ACT : Event,setRelay01=0
465922286: Command: event
465922287: EVENT: setRelay01=0
465922304: ACT : GPIO,0,0
465922306: SW : GPIO 0 Set to 0
465932041: WD : Uptime 7766 ConnectFailures 2 FreeMem 19728
465935298: SW : GPIO 0 Set to 0
465939671: SW : GPIO 0 Set to 1
465939678: SW : Switch state 1 Output value 0
465939683: EVENT: Relay01#status=0.00
465953978: EVENT: sw1#state=1.00
465953987: ACT : Event,toggleRelay01
465954044: Command: event
465954045: EVENT: toggleRelay01
465954072: ACT : Event,setRelay01=0
465954105: Command: event
465954105: EVENT: setRelay01=0
465954123: ACT : GPIO,0,0
465954125: SW : GPIO 0 Set to 0
465956475: EVENT: sw1#state=1.00
465956485: ACT : Event,toggleRelay01
465956540: Command: event
465956541: EVENT: toggleRelay01
465956570: ACT : Event,setRelay01=0
465956601: Command: event
465956602: EVENT: setRelay01=0
465956620: ACT : GPIO,0,0
465956622: SW : GPIO 0 Set to 0
465957975: EVENT: sw1#state=1.00
465957985: ACT : Event,toggleRelay01
465958044: Command: event
465958044: EVENT: toggleRelay01
465958070: ACT : Event,setRelay01=0
465958097: Command: event
465958098: EVENT: setRelay01=0
465958116: ACT : GPIO,0,0
465958118: SW : GPIO 0 Set to 0
465959042: EVENT: toggleRelay01
465959069: ACT : Event,setRelay01=0
465959098: Command: event
465959099: EVENT: setRelay01=0
465959117: ACT : GPIO,0,0
465959120: SW : GPIO 0 Set to 0
465959173: SW : Switch state 1 Output value 1
465959175: EVENT: sw1#state=1.00
465959184: ACT : Event,toggleRelay01
465960173: SW : Switch state 1 Output value 1
465960175: EVENT: sw1#state=1.00
465960184: ACT : Event,toggleRelay01
465960239: Command: event
465960239: EVENT: toggleRelay01
465960268: ACT : Event,setRelay01=0
465960293: SW : Switch state 0 Output value 0
465960295: EVENT: sw1#state=0.00
465960305: ACT : Event,toggleRelay01
465961321: Command: event
465961322: EVENT: toggleRelay01
465961349: ACT : Event,setRelay01=0
465961382: Command: event
465961383: EVENT: toggleRelay01
465961411: ACT : Event,setRelay01=0
465961438: Command: event
465961439: EVENT: toggleRelay01
465961468: ACT : Event,setRelay01=0
465961985: SW : GPIO 0 Set to 0
465961999: Command: event
465962000: EVENT: toggleRelay01
465962025: ACT : Event,setRelay01=0
465962048: WD : Uptime 7766 ConnectFailures 2 FreeMem 19088
465962049: Command: event
465962050: EVENT: setRelay01=0
465962067: ACT : GPIO,0,0
465962069: SW : GPIO 0 Set to 0
465971855: SW : GPIO 0 Set to 1
465971873: SW : Switch state 1 Output value 0
465971878: EVENT: Relay01#status=0.00
465973935: SW : Switch state 0 Output value 1
465973939: EVENT: Relay01#status=1.00
465973996: Command: event
465973997: EVENT: toggleRelay01
465974025: ACT : Event,setRelay01=0
465974050: Command: event
465974050: EVENT: setRelay01=0
465974068: ACT : GPIO,0,0
465974072: SW : GPIO 0 Set to 0
465977941: SW : GPIO 0 Set to 0
465985990: EVENT: sw1#state=1.00
465985999: ACT : Event,toggleRelay01
465986055: Command: event
465986056: EVENT: toggleRelay01
465986083: ACT : Event,setRelay01=0
465986111: Command: event
465986112: EVENT: setRelay01=0
465986129: ACT : GPIO,0,0
465986131: SW : GPIO 0 Set to 0
465990197: EVENT: sw1#state=1.00
465990206: ACT : Event,toggleRelay01
465990262: Command: event
465990262: EVENT: toggleRelay01
465990290: ACT : Event,setRelay01=0
465990323: Command: event
465990324: EVENT: setRelay01=0
465990342: ACT : GPIO,0,0
465990344: SW : GPIO 0 Set to 0
465992041: WD : Uptime 7767 ConnectFailures 2 FreeMem 18160
465996965: SW : GPIO 0 Set to 1
465996995: SW : Switch state 1 Output value 0
465996998: EVENT: Relay01#status=0.00
466002100: EVENT: sw1#state=1.00
466002109: ACT : Event,toggleRelay01
466002165: Command: event
466002166: EVENT: toggleRelay01
466002194: ACT : Event,setRelay01=0
466002227: Command: event
466002228: EVENT: setRelay01=0
466002246: ACT : GPIO,0,0
466002249: SW : GPIO 0 Set to 0
466012829: EVENT: sw1#state=1.00
466012838: ACT : Event,toggleRelay01
466012894: Command: event
466012895: EVENT: toggleRelay01
466012923: ACT : Event,setRelay01=0
466012954: Command: event
466012954: EVENT: setRelay01=0
466012972: ACT : GPIO,0,0
466012975: SW : GPIO 0 Set to 0
466013929: EVENT: sw1#state=1.00
466013938: ACT : Event,toggleRelay01
466013992: Command: event
466013993: EVENT: toggleRelay01
466014022: ACT : Event,setRelay01=0
466014053: Command: event
466014053: EVENT: setRelay01=0
466014071: ACT : GPIO,0,0
466014073: SW : GPIO 0 Set to 0
466014829: EVENT: sw1#state=0.00
466014839: ACT : Event,toggleRelay01
466014894: Command: event
466014895: EVENT: toggleRelay01
466014921: ACT : Event,setRelay01=0
466014954: Command: event
466014955: EVENT: setRelay01=0
466014973: ACT : GPIO,0,0
466014975: SW : GPIO 0 Set to 0
466016229: EVENT: sw1#state=1.00
466016239: ACT : Event,toggleRelay01
466016295: Command: event
466016296: EVENT: toggleRelay01
466016324: ACT : Event,setRelay01=0
466016356: Command: event
466016357: EVENT: setRelay01=0
466016375: ACT : GPIO,0,0
466016378: SW : GPIO 0 Set to 0
466022043: WD : Uptime 7767 ConnectFailures 2 FreeMem 19728
466052043: WD : Uptime 7768 ConnectFailures 2 FreeMem 19728
466082043: WD : Uptime 7768 ConnectFailures 2 FreeMem 19728
466089033: SW : GPIO 0 Set to 1
466089041: SW : Switch state 1 Output value 0
466089044: EVENT: Relay01#status=0.00
466100643: EVENT: toggleRelay01
466100668: ACT : Event,setRelay01=0
466100690: Command: event
466100691: EVENT: setRelay01=0
466100708: ACT : GPIO,0,0
466100710: SW : GPIO 0 Set to 0
466100738: SW : Switch state 0 Output value 1
466100741: EVENT: Relay01#status=1.00
466103704: EVENT: setRelay01=0
466103721: ACT : GPIO,0,0
466103723: SW : GPIO 0 Set to 0
466104643: EVENT: toggleRelay01
466104667: ACT : Event,setRelay01=0
466104692: Command: event
466104693: EVENT: setRelay01=0
466104710: ACT : GPIO,0,0
466104712: SW : GPIO 0 Set to 0
466112043: WD : Uptime 7769 ConnectFailures 2 FreeMem 19728

potzkiin
Normal user
Posts: 28
Joined: 04 Sep 2018, 09:15

Re: Help With Rules

#45 Post by potzkiin » 12 Sep 2018, 09:31

i read somewhere that a virtual switch could help...can you suggest ho to make it with rules?
or maybe it is not relevant at all...

User avatar
grovkillen
Normal user
Posts: 1900
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

Re: Help With Rules

#46 Post by grovkillen » 12 Sep 2018, 09:42

potzkiin wrote:
12 Sep 2018, 09:31
i read somewhere that a virtual switch could help...can you suggest ho to make it with rules?
or maybe it is not relevant at all...
Sounds to me that you're not actually using the correct name of this part: if [Relay01#Status]=0. Observe that my example uses "state" where you use "status"!
ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Sponsor ESP Easy, we need you :idea: :idea: :idea:

potzkiin
Normal user
Posts: 28
Joined: 04 Sep 2018, 09:15

Re: Help With Rules

#47 Post by potzkiin » 12 Sep 2018, 09:57

actually This is my current rule:

on System#Boot do
gpio,0,1 // Prevent relay turning on during boot
endon

On sw1#state Do
Event,toggleRelay01
EndOn

On toggleRelay01 Do
if [Relay01#state]=0
Event,setRelay01=1
else
Event,setRelay01=0
endif
EndOn

On setRelay01 Do
GPIO,0,%eventvalue%
EndOn

User avatar
grovkillen
Normal user
Posts: 1900
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

Re: Help With Rules

#48 Post by grovkillen » 12 Sep 2018, 10:00

And there you have it, you are not using YOUR name of the relay value... you use my example "state" not YOUR name "status"!
ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Sponsor ESP Easy, we need you :idea: :idea: :idea:

potzkiin
Normal user
Posts: 28
Joined: 04 Sep 2018, 09:15

Re: Help With Rules

#49 Post by potzkiin » 12 Sep 2018, 10:41

OK, thanks for the input i didn't noticed that.
i changed the name to be state

when pressing the SW1 nothing happening to relay.
on the mqtt console i can see it any press make the status go from 0 to 1 with single press.

/test/sw1/state 0
/test/sw1/state 1
Attachments
Devices.jpg
Devices.jpg (58.15 KiB) Viewed 207 times

User avatar
grovkillen
Normal user
Posts: 1900
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

Re: Help With Rules

#50 Post by grovkillen » 12 Sep 2018, 10:51

potzkiin wrote:
12 Sep 2018, 10:41
OK, thanks for the input i didn't noticed that.
i changed the name to be state

when pressing the SW1 nothing happening to relay.
on the mqtt console i can see it any press make the status go from 0 to 1 with single press.

/test/sw1/state 0
/test/sw1/state 1
Sounds like you have the setup for the switch wrong, do you have it as a "normal" switch in the settings?
ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Sponsor ESP Easy, we need you :idea: :idea: :idea:

Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests