Rules, syntax in if ...

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
Loops
New user
Posts: 6
Joined: 28 Sep 2015, 21:13

Rules, syntax in if ...

#1 Post by Loops » 19 Sep 2016, 20:07

Hi all !

I've installed the release 120 in a Sonoff ESP https://www.itead.cc/sonoff-wifi-wireless-switch.html.
In this device we have a relay and a monostable switch (NO).
I want to write a rule to activate the relay when i push the button, and desactivate it when i push again the button.

It is possible to add in a rule a if with a "GPIO" directly ???
Something like this :

Code: Select all

on Bouton_ESP#Switch do
  if [GPIO-0]=0
    gpio,12,0    
  else
    gpio,12,1    
  endif
endon
Thank you for your help !!!

JC

dlefol
Normal user
Posts: 26
Joined: 11 Nov 2015, 23:28

Re: Rules, syntax in if ...

#2 Post by dlefol » 28 Sep 2016, 22:29

Hi
This is discussed in a couple of places in the forum with different solution proposed.
In my case I use the following rule:

on MainSwitch#Switch do
if [MainSwitch#Switch]=0
gpio,12,0
else
gpio,12,1
endif
endon

on Relay#Relay do
if [Relay#Relay]=0
gpio,13,1
else
gpio,13,0
endif
endon


With the following devices declared:
1 Switch input MainSwitch GPIO-0
2 Switch input Relay 316 GPIO-12


Which means that the physical button which is on GPIO 0 (device MainSwitch) triggers the rules which activate the GPIO 12 (the relay) and this in turns activate the rule to activate the LED on or off. This enables to have the LED in the correct position even when a command is sent from domoticz instead of using the physical button.

As been working ok for a couple of days here.

Hope this helps. Otherwise look at the other solution proposed on the forum.

uhrheber
Normal user
Posts: 22
Joined: 26 Sep 2016, 14:03

Re: Rules, syntax in if ...

#3 Post by uhrheber » 29 Sep 2016, 09:35

Or you could just define the switch input as a "Push Button Active Low" and omit the second rule, because the switch will toggle automatically.

dlefol
Normal user
Posts: 26
Joined: 11 Nov 2015, 23:28

Re: Rules, syntax in if ...

#4 Post by dlefol » 01 Nov 2016, 21:52

Yes actually the rules I posted before is not good as sometimes the lights start flashing due to a timing conflict in the two rules and the command sent from my central controller. I now use the solution posted there :
viewtopic.php?f=2&t=1867&p=8627&hilit=s ... ules#p8627

and it s stable and easier.

Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 59 guests