Page 1 of 2

Help With Rules

Posted: 04 Sep 2018, 09:21
by potzkiin
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?

Re: Help With Rules

Posted: 04 Sep 2018, 10:08
by grovkillen

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.

Re: Help With Rules

Posted: 04 Sep 2018, 10:25
by potzkiin
im using
"payload": "GPIO,0,1 or 0",
"topic": "/test/cmd"

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

Re: Help With Rules

Posted: 04 Sep 2018, 10:35
by grovkillen
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.

Re: Help With Rules

Posted: 04 Sep 2018, 11:12
by potzkiin
yes i try it and i got the same results..

Re: Help With Rules

Posted: 04 Sep 2018, 11:26
by potzkiin
as i understand i need some rule to listen to my mqtt command an execute the switch mode according to the mqtt topic...

Re: Help With Rules

Posted: 04 Sep 2018, 11:51
by grovkillen
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.

Re: Help With Rules

Posted: 04 Sep 2018, 12:21
by potzkiin
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.

Re: Help With Rules

Posted: 04 Sep 2018, 12:27
by grovkillen
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.

Re: Help With Rules

Posted: 04 Sep 2018, 12:28
by grovkillen
Because then you can set

GPIO,16,%eventvalue%

Re: Help With Rules

Posted: 04 Sep 2018, 13:45
by potzkiin
if you can help me with the rule? im pretty new to this..

Re: Help With Rules

Posted: 04 Sep 2018, 14:00
by grovkillen
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.

Re: Help With Rules

Posted: 04 Sep 2018, 14:34
by potzkiin
went trough the wiki for days..can find a solution.
i found not only me struggling with this issue over the net..

Re: Help With Rules

Posted: 04 Sep 2018, 14:55
by potzkiin
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.

Re: Help With Rules

Posted: 04 Sep 2018, 15:19
by grovkillen
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

Re: Help With Rules

Posted: 04 Sep 2018, 16:13
by potzkiin
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

Re: Help With Rules

Posted: 04 Sep 2018, 17:21
by grovkillen

Code: Select all

toggeleRelay01
Check spelling.

I also see that I misspelled "else" with "elese". I have updated the previous post now.

Re: Help With Rules

Posted: 04 Sep 2018, 20:28
by TD-er
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.

Re: Help With Rules

Posted: 05 Sep 2018, 08:12
by potzkiin
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!

Re: Help With Rules

Posted: 05 Sep 2018, 08:16
by potzkiin
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.

Re: Help With Rules

Posted: 05 Sep 2018, 08:33
by grovkillen
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

Re: Help With Rules

Posted: 05 Sep 2018, 09:47
by potzkiin
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

Re: Help With Rules

Posted: 05 Sep 2018, 10:16
by grovkillen
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?

Re: Help With Rules

Posted: 05 Sep 2018, 10:21
by grovkillen
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.

Re: Help With Rules

Posted: 05 Sep 2018, 18:42
by potzkiin
What stable version do you suggest?

Re: Help With Rules

Posted: 05 Sep 2018, 18:44
by grovkillen

Re: Help With Rules

Posted: 05 Sep 2018, 18:45
by grovkillen
But you should always test on a none production unit, so everything is working all right before you start using it for real

Re: Help With Rules

Posted: 05 Sep 2018, 18:45
by potzkiin
Thanks! Will upload tommorow:-)

Re: Help With Rules

Posted: 06 Sep 2018, 13:35
by potzkiin
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.

Re: Help With Rules

Posted: 06 Sep 2018, 17:19
by grovkillen
The fact that the MQTT command is setting the switch state and not the relay suggest to me that the GPIO is mixed up.

Re: Help With Rules

Posted: 06 Sep 2018, 17:45
by potzkiin
Hi,
i uploaded the devices and rule.
gpio 12 is the switch input
gpio 0 is the relay..

Re: Help With Rules

Posted: 06 Sep 2018, 17:56
by grovkillen
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.

Re: Help With Rules

Posted: 06 Sep 2018, 18:53
by potzkiin
Im using this rule:
on System#Boot do
gpio,0,1 // Prevent relay turning on during boot
endon

Re: Help With Rules

Posted: 06 Sep 2018, 19:09
by grovkillen
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).

Re: Help With Rules

Posted: 06 Sep 2018, 19:23
by potzkiin
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..

Re: Help With Rules

Posted: 06 Sep 2018, 21:17
by grovkillen
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

Re: Help With Rules

Posted: 10 Sep 2018, 12:45
by werner_g
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?

Re: Help With Rules

Posted: 10 Sep 2018, 18:07
by grovkillen
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

Re: Help With Rules

Posted: 11 Sep 2018, 17:21
by werner_g
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.

Re: Help With Rules

Posted: 11 Sep 2018, 17:30
by grovkillen
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.

Re: Help With Rules

Posted: 11 Sep 2018, 17:35
by grovkillen
You could try:

on Vent01auf=1.00 do

&

on Vent01auf=0.00 do

Re: Help With Rules

Posted: 11 Sep 2018, 18:14
by werner_g
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.

Re: Help With Rules

Posted: 11 Sep 2018, 18:19
by werner_g
Vent01auf=1.00 or Vent01auf=0.00: this are my events I want to use.

Re: Help With Rules

Posted: 12 Sep 2018, 09:30
by potzkiin
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

Re: Help With Rules

Posted: 12 Sep 2018, 09:31
by potzkiin
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...

Re: Help With Rules

Posted: 12 Sep 2018, 09:42
by grovkillen
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"!

Re: Help With Rules

Posted: 12 Sep 2018, 09:57
by potzkiin
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

Re: Help With Rules

Posted: 12 Sep 2018, 10:00
by grovkillen
And there you have it, you are not using YOUR name of the relay value... you use my example "state" not YOUR name "status"!

Re: Help With Rules

Posted: 12 Sep 2018, 10:41
by potzkiin
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

Re: Help With Rules

Posted: 12 Sep 2018, 10:51
by grovkillen
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?