Rules using 'OR"

Moderators: grovkillen, Stuntteam, TD-er

Message
Author
Dick60
Normal user
Posts: 242
Joined: 11 Feb 2018, 17:35
Location: The Netherlands

Rules using 'OR"

#1 Post by Dick60 » 20 May 2020, 10:59

According the WIKI I can you the 'OR' statement in rules.
on test do
if [test#a]=0 or [test#b]=0 or [test#c]=0
event,ok
else
event,not_ok
endif
endon

I adjusted the example to my needs but it does not work. Can anybody help me around?
I have 2 switches I can make them 1 or 0. Depending the status it will (de-)activate the generalswitch.

On generalswitch do
if [switch1#State]=1 or [switch2#State]=1
gpio,0,0
else
gpio,0,1
endif
endon

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

Re: Rules using 'OR"

#2 Post by grovkillen » 20 May 2020, 11:04

What 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:

Dick60
Normal user
Posts: 242
Joined: 11 Feb 2018, 17:35
Location: The Netherlands

Re: Rules using 'OR"

#3 Post by Dick60 » 20 May 2020, 11:48

Sorry forgot to mention, the latest one 15052020

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Rules using 'OR"

#4 Post by TD-er » 20 May 2020, 13:27

Code: Select all

if [switch1#State]=1 or [switch2#State]=1
Try printing the switch state into a logentry, just to make sure you compare to the correct value and also to see if you even get into that part of the rules.

For example is there a task named 'generalswitch' ?
You refer to it in the On ... do part

Dick60
Normal user
Posts: 242
Joined: 11 Feb 2018, 17:35
Location: The Netherlands

Re: Rules using 'OR"

#5 Post by Dick60 » 20 May 2020, 14:18

no there isn't a 'generalswitch' task. What I read in the wiki is that it is possible to use this kind of rule. Wrong intepretation. So what si the approch for me, do you have an example for me how to het this working?

Dick60
Normal user
Posts: 242
Joined: 11 Feb 2018, 17:35
Location: The Netherlands

Re: Rules using 'OR"

#6 Post by Dick60 » 20 May 2020, 15:40

is this the way to continue???? It does not work but advise please.

On switch1#State do
if [switch1#State]=1
event,generalswitch
endif
endon

On generalswitch do
if [switch1#State]=1
gpio,0,1
else
gpio,0,0
endif
endon

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

Re: Rules using 'OR"

#7 Post by grovkillen » 20 May 2020, 16:49

Try this (GPIO 14 just as an example):

Code: Select all

On switch1#State do
GPIO,14,[switch1#State#Z]
endon
Or inverted:

Code: Select all

On switch1#State do
GPIO,14,[switch1#State#!Z]
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]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you :idea: :idea: :idea:

Dick60
Normal user
Posts: 242
Joined: 11 Feb 2018, 17:35
Location: The Netherlands

Re: Rules using 'OR"

#8 Post by Dick60 » 20 May 2020, 17:28

this is working
On switch1#State do
GPIO,14,[switch1#State#Z]
endon

but how can I use the 'OR'' statement
if switch1=1 or switch2=1

the Generalswitch must be set to 1

User avatar
Ath
Normal user
Posts: 3416
Joined: 10 Jun 2018, 12:06
Location: NL

Re: Rules using 'OR"

#9 Post by Ath » 20 May 2020, 17:33

You're almost there, something like this should work:

Code: Select all

On switch1#State do
  event,generalswitch
endon

On switch2#State do
  event,generalswitch
endon

On generalswitch do
  if [switch1#State]=1 or [switch2#State]=1
    gpio,0,1  // Turn on
  else
    gpio,0,0  // Turn off
  endif
endon
/Ton (PayPal.me)

Dick60
Normal user
Posts: 242
Joined: 11 Feb 2018, 17:35
Location: The Netherlands

Re: Rules using 'OR"

#10 Post by Dick60 » 20 May 2020, 18:03

Thanks a lot for all the support. Now it makes sence to implement it in my project.
Have a great day.

ssd
Normal user
Posts: 53
Joined: 19 Aug 2020, 12:04

Re: Rules using 'OR"

#11 Post by ssd » 20 Aug 2020, 07:12

Hi,
I am using the latest version of ESPeasy i.e ESPEasy_ESP82xx_mega-20200812 and new to using ESPeasy.

I am controlling GPIO,12 by domoticz and GPIO,13 by using the wall switch and GPIO,14 is used to toggle the relay which will turn the lights on. I am attaching the connections and written rules to control the light using both physical switch and domoticz simultaneously. I am facing an issue that the GPIO,14 toggles. Can anyone here guide me to resolve my issue or write new set of rules?

Domoticz input :- GPIO-12,configured as default in hardware - Name- RL2
Wall switch input:- GPIO-13, configured as input in hardware :- Name- wall
Relay connected to the light:- GPIO-14, configured as default in hardware:- Name- Relay

Rules:-
On Relay#state=0 do
if [RL2#state]=0 and [wall#state]=0
gpio,14,1
elseif [RL2#state]=1 and [wall#state]=0
gpio,14,1
elseif [RL2#state]=0 and [wall#state]=1
gpio,14,1
elseif [RL2#state]=1 and [wall#state]=1
gpio,14,1
endif
endon

On Relay#state=1 do
if [RL2#state]=0 and [wall#state]=0
gpio,14,0
elseif [RL2#state]=1 and [wall#state]=0
gpio,14,0
elseif [RL2#state]=0 and [wall#state]=1
gpio,14,0
elseif [RL2#state]=1 and [wall#state]=1
gpio,14,0
endif
endon

Any kind of help will be appreciated...

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Rules using 'OR"

#12 Post by TD-er » 20 Aug 2020, 09:23

You're making it too complex.

First of all, the combination of acting on an external state and the internal state of the relay makes it very hard (next to impossible) to get it right.

There are several solutions, of which there is one specific for Domoticz (using MQTT).
Try using Plugin 19: Output - Domoticz MQTT Helper (see also the very sparse documentation)

ssd
Normal user
Posts: 53
Joined: 19 Aug 2020, 12:04

Re: Rules using 'OR"

#13 Post by ssd » 20 Aug 2020, 10:16

Thank you for the quick response.
As I am new to ESPeasy can you give me any more information regarding Domoticz MQTT helper or some examples regarding the same?

Also, can I use a check trigger for both switches simultaneously in on....do format in ESPeasy rules as this can resolve the issue I guess?

for example:-
on RL2#state do
on wall#state do
if condition
action
endif
endon
endon

In this case, RL2 needs to be triggered every time any condition is to be satisfied, only triggering wall switch does not do any actions. So if it is possible to trigger both the switches then I can work on respective condition to get the output.

I want to use a single switch, a relay, and domoticz simultaneously so that bulb can be switched on by both domoticz and wall switch without any dependency. Is it possible

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Rules using 'OR"

#14 Post by TD-er » 20 Aug 2020, 11:28

No you cannot 'nest' triggers.
Also this will never work as an event will only be dealt with one after the other.

What you can do, is evaluate the state of "the other" condition like you tried in the first attempt.
However, that's going to lead to a rather unstable state of the GPIO pin as it is not only set by your rules but also via the controller.

Like I said there is a number of possible solutions here, each with their own limitations.

You can just send all button presses to Domoticz and let Domoticz switch the state of the relay.
Drawback is that there is some delay between action and reaction and also it won't work at all if there is no connection to Domoticz.

You can use the Domoticz MQTT helper I mentioned, this one does force the selected pin exactly to the state Domoticz expects it to be.
So for example your switch is at GPIO-0 and assigned IDX 120. (as is in the example here)
You can add a Domoticz MQTT helper to switch your relay for you and all you need to do there is set the same IDX (120) as used in the button switch task and set the GPIO pin of your relay. (GPIO-12 in my setup)

Then add a small rule like this:

Code: Select all

on Button1#switch do
  if [Button1#switch]=1
    gpio,12,1
  else
    gpio,12,0
  endif
endon
This allows the switch to also work locally regardless of the connectivity to Domoticz.

Fun part is, when you add another switch on another node (set to active low for example, if using a push button) and use the same IDX value there, you can also toggle the relay on the other node via the MQTT broker as Domoticz will update the state and switch the relay via the Domoticz MQTT helper.

ssd
Normal user
Posts: 53
Joined: 19 Aug 2020, 12:04

Re: Rules using 'OR"

#15 Post by ssd » 20 Aug 2020, 13:03

TD-er wrote: 20 Aug 2020, 11:28 No you cannot 'nest' triggers.
Also this will never work as an event will only be dealt with one after the other.

What you can do, is evaluate the state of "the other" condition like you tried in the first attempt.
However, that's going to lead to a rather unstable state of the GPIO pin as it is not only set by your rules but also via the controller.

Like I said there is a number of possible solutions here, each with their own limitations.

You can just send all button presses to Domoticz and let Domoticz switch the state of the relay.
Drawback is that there is some delay between action and reaction and also it won't work at all if there is no connection to Domoticz.

You can use the Domoticz MQTT helper I mentioned, this one does force the selected pin exactly to the state Domoticz expects it to be.
So for example your switch is at GPIO-0 and assigned IDX 120. (as is in the example here)
You can add a Domoticz MQTT helper to switch your relay for you and all you need to do there is set the same IDX (120) as used in the button switch task and set the GPIO pin of your relay. (GPIO-12 in my setup)

Then add a small rule like this:

Code: Select all

on Button1#switch do
  if [Button1#switch]=1
    gpio,12,1
  else
    gpio,12,0
  endif
endon
This allows the switch to also work locally regardless of the connectivity to Domoticz.

Fun part is, when you add another switch on another node (set to active low for example, if using a push button) and use the same IDX value there, you can also toggle the relay on the other node via the MQTT broker as Domoticz will update the state and switch the relay via the Domoticz MQTT helper.
Thank you so much. ( As I mentioned above: My Relay is connected to ESP - GPIO 14 and my physical( one way wall ) switch is connected as an INPUT to ESP - GPIO 13. I am passing 3.3V through this switch. I want to operate my Relay by Domoticz as well as Physical switch.)
I have one questions: Going ahead with your suggestion, I am not understanding on how to assign same idx for Domoticz MQTTHelper and my physical wall switch, as when I operate the wall switch I see the high/low status on ESPEasy but not on Domoticz. Is the status sent to Domoticz in this case?

PS: I am new to ESPEasy. I am a little confused.

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Rules using 'OR"

#16 Post by TD-er » 20 Aug 2020, 14:24

You have to add a Domoticz controller (preferrably MQTT) and make sure you link the task to that controller.
Only a few controllers support IDX values, so if you see a controller to be linked to the task and it is a Domoticz controller you will see the IDX field.

In Domoticz, when you add a (dummy) device, it will get an IDX value assigned and you simply have to use that one in ESPEasy. There is no other way around as Domoticz assigns the IDX values.

So this is how you link the switch task to the Domoticz controller.
In the Domoticz MQTT helper task you only have a single field (along with the GPIO selector) where you can set the IDX value.
Use the same value there as you use in the switch task, the one assigned by Domoticz.

ssd
Normal user
Posts: 53
Joined: 19 Aug 2020, 12:04

Re: Rules using 'OR"

#17 Post by ssd » 20 Aug 2020, 15:35

TD-er wrote: 20 Aug 2020, 14:24 You have to add a Domoticz controller (preferrably MQTT) and make sure you link the task to that controller.
Only a few controllers support IDX values, so if you see a controller to be linked to the task and it is a Domoticz controller you will see the IDX field.

In Domoticz, when you add a (dummy) device, it will get an IDX value assigned and you simply have to use that one in ESPEasy. There is no other way around as Domoticz assigns the IDX values.

So this is how you link the switch task to the Domoticz controller.
In the Domoticz MQTT helper task you only have a single field (along with the GPIO selector) where you can set the IDX value.
Use the same value there as you use in the switch task, the one assigned by Domoticz.
I tried according to your suggestion but I guess the switch and the MQTT helper are not linked and the status is not updated on domoticz. Am I missing any additional settings to be done in domoticz?

User avatar
Ath
Normal user
Posts: 3416
Joined: 10 Jun 2018, 12:06
Location: NL

Re: Rules using 'OR"

#18 Post by Ath » 20 Aug 2020, 16:41

On ESPEasy you can add a Switch device (name: Relay), connected to GPIO-14 (mine is on GPIO-12) and the matching IDX in Domoticz, to get the status from your ESP to Domoticz. To control that same relay from Domoticz, you add a device MQTT Helper, that you give the same IDX and GPIO value.
And I also have a real button configured, device Switch, name: Button, type: Normal switch (on GPIO-0 for a Sonoff S2x).

Then in ESPEasy I have a single rule that acts on the button being pressed:

Code: Select all

On Button#State=0 do
  if [Relay#State]=0
    gpio,12,1
  else
    gpio,12,0
  endif
endon
That's how I have all my Sonoff S20's configured, and it works like a charm.
/Ton (PayPal.me)

ssd
Normal user
Posts: 53
Joined: 19 Aug 2020, 12:04

Re: Rules using 'OR"

#19 Post by ssd » 21 Aug 2020, 07:17

Ath wrote: 20 Aug 2020, 16:41 On ESPEasy you can add a Switch device (name: Relay), connected to GPIO-14 (mine is on GPIO-12) and the matching IDX in Domoticz, to get the status from your ESP to Domoticz. To control that same relay from Domoticz, you add a device MQTT Helper, that you give the same IDX and GPIO value.
And I also have a real button configured, device Switch, name: Button, type: Normal switch (on GPIO-0 for a Sonoff S2x).

Then in ESPEasy I have a single rule that acts on the button being pressed:

Code: Select all

On Button#State=0 do
  if [Relay#State]=0
    gpio,12,1
  else
    gpio,12,0
  endif
endon
That's how I have all my Sonoff S20's configured, and it works like a charm.
Thanks for the help. The functioning is on the spot that is not the issue. The issue is the status of Switch on domotics is not getting updated when I operate the relay using a physical/Wall switch. So when I turn off the really using physical switch there is no update on domoticz dashboard. Hence, I guess MQTT helper is not working for me. Can use sendtoHTTP in rules to control the status of the switch on dashboard without using MQTT helper?

Following will be the details for my setup:-
1)Domoticz switch -> GPIO-14 -> on hardware the pin is at default -> the relay will be connected to the same GPIO-14-->Name(RL2)
2) The physical switch is connected to GPIO-13 --> Name(wall)
Rule:-
on wall#state do
if [RL2#state]=0
gpio,14,1
else
gpio,14,0
endif
endon
3) What if I add SendToHTTP in the above rule and not use DomoticzMQTThelper can it directly update the status of the switch RL2 on dashboard?

P.S:- I am unable to attach any images otherwise I would have updated certain pictures for more clarification.

User avatar
Ath
Normal user
Posts: 3416
Joined: 10 Jun 2018, 12:06
Location: NL

Re: Rules using 'OR"

#20 Post by Ath » 21 Aug 2020, 08:49

What type of switch is the wall-switch? A push-button or a flip-switch, that stays in the last position?
/Ton (PayPal.me)

User avatar
Ath
Normal user
Posts: 3416
Joined: 10 Jun 2018, 12:06
Location: NL

Re: Rules using 'OR"

#21 Post by Ath » 21 Aug 2020, 08:54

Ah, and, assuming you run Domoticz on a Raspberry Pi, did you also install Mosquitto there, as the MQTT add-on to Domoticz? I think to us 'techies', that's kind of default/standard, because out of the box, Domoticz doesn't speak MQTT :shock:
/Ton (PayPal.me)

ssd
Normal user
Posts: 53
Joined: 19 Aug 2020, 12:04

Re: Rules using 'OR"

#22 Post by ssd » 21 Aug 2020, 08:59

Ath wrote: 21 Aug 2020, 08:54 Ah, and, assuming you run Domoticz on a Raspberry Pi, did you also install Mosquitto there, as the MQTT add-on to Domoticz? I think to us 'techies', that's kind of default/standard, because out of the box, Domoticz doesn't speak MQTT :shock:
Okay. Will install MQTT on raspberry pi and restart. Btw does the use of MQTT involve delays in operating devices?

ssd
Normal user
Posts: 53
Joined: 19 Aug 2020, 12:04

Re: Rules using 'OR"

#23 Post by ssd » 21 Aug 2020, 08:59

Ath wrote: 21 Aug 2020, 08:49 What type of switch is the wall-switch? A push-button or a flip-switch, that stays in the last position?
It's a flip switch(one way)

ssd
Normal user
Posts: 53
Joined: 19 Aug 2020, 12:04

Re: Rules using 'OR"

#24 Post by ssd » 21 Aug 2020, 09:08

Ath wrote: 20 Aug 2020, 16:41 On ESPEasy you can add a Switch device (name: Relay), connected to GPIO-14 (mine is on GPIO-12) and the matching IDX in Domoticz, to get the status from your ESP to Domoticz. To control that same relay from Domoticz, you add a device MQTT Helper, that you give the same IDX and GPIO value.
And I also have a real button configured, device Switch, name: Button, type: Normal switch (on GPIO-0 for a Sonoff S2x).

Then in ESPEasy I have a single rule that acts on the button being pressed:

Code: Select all

On Button#State=0 do
  if [Relay#State]=0
    gpio,12,1
  else
    gpio,12,0
  endif
endon
That's how I have all my Sonoff S20's configured, and it works like a charm.
I am trying a way around now...I have removed MQTT from the picture,as it was giving me hard time...I am thinking of using SendToHTTP command.
So following is the setup....
Following will be the details for my setup:-
1)Domoticz switch -> GPIO-14 -> on hardware the pin is at default -> the relay will be connected to the same GPIO-14-->Name(RL2)
2) The physical switch(flip switch with two values on and off(one-way)) is connected to GPIO-13 --> Name(wall)
Rule:-
on wall#state do
if [wall#state]=1
gpio,14,1
SendToHTTP 192.168.0.100,8080,/json.htm?type=param=switchlight&command&idx=2&switchcmd=On
else
gpio,14,0
SendToHTTP 192.168.0.100,8080,/json.htm?type=param=switchlight&command&idx=2&switchcmd=Off
endif
endon
but the status is not getting updated on my domoticz dashboard switch with index 2 but the same command is working when i post it in the browser?
Is there some thing wrong with the command I am using? If not, what is the problem?

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Rules using 'OR"

#25 Post by TD-er » 21 Aug 2020, 09:15

I think that's the issue here.
The switch ("normal switch" mode) will only send an update of its state when it is toggled.

Let's assume this state: ESP state 0 / Domoticz state 1

Normal switch mode:
If you toggle the ESP switch, then it will only send "1" to Domoticz, which is not a change.
As soon as you toggle it back, you would expect Domoticz to follow.

Active Low mode:
Toggle the wall switch on the ESP and it will not send any update, toggle it back and Domoticz will change state.


I think we're missing an extra mode here on the switch plugin.
For flip switches, you need a "toggle" mode, which does act the same as with "active low" for a push button, but reacts on a change of the GPIO state.

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Rules using 'OR"

#26 Post by TD-er » 21 Aug 2020, 09:17

In Tools => Advanced, you have the option "SendToHTTP wait for ack"
Can you test with that checked?

ssd
Normal user
Posts: 53
Joined: 19 Aug 2020, 12:04

Re: Rules using 'OR"

#27 Post by ssd » 21 Aug 2020, 09:24

TD-er wrote: 21 Aug 2020, 09:17 In Tools => Advanced, you have the option "SendToHTTP wait for ack"
Can you test with that checked?
I tested it now, it says HTTP:command_HTTP_SendToHTTP Error:HTTP/1.1.401 Unauthorized^
Timeout while reading input data!

What authorization do I need to give?

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Rules using 'OR"

#28 Post by TD-er » 21 Aug 2020, 10:20

Do you have a password set to Domoticz?
Or does your configuration only accept traffic on HTTPS?

Edit:
Just thinking... I'm not 100% sure Domoticz should return some acknowledgement.
But returning a 401 is just strange.

ssd
Normal user
Posts: 53
Joined: 19 Aug 2020, 12:04

Re: Rules using 'OR"

#29 Post by ssd » 21 Aug 2020, 10:32

TD-er wrote: 21 Aug 2020, 10:20 Do you have a password set to Domoticz?
Or does your configuration only accept traffic on HTTPS?

Edit:
Just thinking... I'm not 100% sure Domoticz should return some acknowledgment.
But returning a 401 is just strange.
It's working now...I had website protection switched on Domoticz. I just removed my website protection and it is working fine now. Thank you for your help.
Is there any way in which we can use SendToHTTP using username and password used for website protection?

Edit:
Using domoticz without website protection seems risky and if I turned it on it will affect my functionality. What is the way to get out of this situation?

Edit
Everything is working fine now...It was a noob mistake from my side I did not update the user in ESPeasy controller settings...Thank you for all kinds of help from your side.It's a great community and I appreciate your quick responses. Thank You!! :D :D

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Rules using 'OR"

#30 Post by TD-er » 21 Aug 2020, 12:40

You're welcome and glad it is working now.

ssd
Normal user
Posts: 53
Joined: 19 Aug 2020, 12:04

Re: Rules using 'OR"

#31 Post by ssd » 25 Aug 2020, 07:07

TD-er wrote: 21 Aug 2020, 12:40 You're welcome and glad it is working now.
Hello again, I am facing a problem in the same scenario. When I turn ON and OFF the switch continuously with high frequency the relay goes into the toggle mode and then I had to reset the NodeMCU to get it back to normal functioning. Is there any solution to this problem? Need some assistance in this scenario.

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Rules using 'OR"

#32 Post by TD-er » 25 Aug 2020, 17:19

Sounds like there may be a delay and queue of rules event processing.

What you can do is to start a timer and store the right state where you now try to set the GPIO pin.
For example, you store the state in variable 1 and set the (new) msec timer.
As soon as this timer expires, you set the GPIO to the state stored in the variable.

If you set the timer to something like 500 msec, then you still have a quick response, but you eliminate such a queue effect when trying to switch at a high frequency.

ssd
Normal user
Posts: 53
Joined: 19 Aug 2020, 12:04

Re: Rules using 'OR"

#33 Post by ssd » 26 Aug 2020, 07:54

TD-er wrote: 25 Aug 2020, 17:19 Sounds like there may be a delay and queue of rules event processing.

What you can do is to start a timer and store the right state where you now try to set the GPIO pin.
For example, you store the state in variable 1 and set the (new) msec timer.
As soon as this timer expires, you set the GPIO to the state stored in the variable.

If you set the timer to something like 500 msec, then you still have a quick response, but you eliminate such a queue effect when trying to switch at a high frequency.
I have never used a timer or msec timer before. Also, Do you expect me to store the values of the variable in rules or with some other feature? Can you help me with a specific example as I have never used timers and variables before? It will be easier to understand. Thank you. :D

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Rules using 'OR"

#34 Post by TD-er » 26 Aug 2020, 11:20

You first have to make sure rules are enabled (Tools -> Advanced)
Then you can start having a look at the timerset documentation here: https://espeasy.readthedocs.io/en/lates ... rset#timer

In this topic (as in this forum topic, not the documentation link) a number of rules examples are already given.

ssd
Normal user
Posts: 53
Joined: 19 Aug 2020, 12:04

Re: Rules using 'OR"

#35 Post by ssd » 26 Aug 2020, 12:15

TD-er wrote: 26 Aug 2020, 11:20 You first have to make sure rules are enabled (Tools -> Advanced)
Then you can start having a look at the timerset documentation here: https://espeasy.readthedocs.io/en/lates ... rset#timer

In this topic (as in this forum topic, not the documentation link) a number of rules examples are already given.
Okay, will check and let you know. Thank you.

ssd
Normal user
Posts: 53
Joined: 19 Aug 2020, 12:04

Re: Rules using 'OR"

#36 Post by ssd » 31 Aug 2020, 10:51

TD-er wrote: 26 Aug 2020, 11:20 You first have to make sure rules are enabled (Tools -> Advanced)
Then you can start having a look at the timerset documentation here: https://espeasy.readthedocs.io/en/lates ... rset#timer

In this topic (as in this forum topic, not the documentation link) a number of rules examples are already given.
Hello,
I am trying the solution that you suggested for high frequency switching. I have pulled down gpio,16 externally as I was unable to use internal pull down command.I have used the following rule but now the gpio is toggling constantly.Can you kindly help me with this problem??
Rule.
On Hall_light#state do
gpio,16,[dummy#var1]
timerset,1,1
endon
On Rules#Timer=1 do
gpio,16,[dummy#var1]
timerset,1,1
endon

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Rules using 'OR"

#37 Post by TD-er » 31 Aug 2020, 11:00

What is the 'source' of the Hall_light ?
Is that also working on GPIO 16?
How is that switch task (assuming it is using the switch plugin) configured? As "normal switch" or "active low" or "active high" ?

ssd
Normal user
Posts: 53
Joined: 19 Aug 2020, 12:04

Re: Rules using 'OR"

#38 Post by ssd » 31 Aug 2020, 11:21

TD-er wrote: 31 Aug 2020, 11:00 What is the 'source' of the Hall_light ?
Is that also working on GPIO 16?
How is that switch task (assuming it is using the switch plugin) configured? As "normal switch" or "active low" or "active high" ?
Source of Hall light is a physical switch connected to gpio,14
when gpio,14 is high gpio,16 is high and the light turns on(It is a continuation of the setup discussed earlier under this subject).
It is configured as switch-input, normal switch.

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Rules using 'OR"

#39 Post by TD-er » 31 Aug 2020, 11:50

Maybe you can give the complete rules and some summary of what is intended purpose.
This thread is already quite long and several things have been proposed, so it is hard to find exactly what is intended, what problems you currently see and what the full rules are you're using.

So:
- rules
- How is GPIO14 connected (via switch apparently)
- How is GPIO16 connected (has it a task assigned, or do you only set it via rules, thus it is an output?)
- What resistor value do you use on GPIO-16 to pull down? (not sure if that's the way to go by the way, as GPIO-16 is a bit special)
- What is your intended result (you're setting GPIO-16 with value of the dummy, but where is the dummy value set) ?

ssd
Normal user
Posts: 53
Joined: 19 Aug 2020, 12:04

Re: Rules using 'OR"

#40 Post by ssd » 31 Aug 2020, 12:50

TD-er wrote: 31 Aug 2020, 11:50 Maybe you can give the complete rules and some summary of what is intended purpose.
This thread is already quite long and several things have been proposed, so it is hard to find exactly what is intended, what problems you currently see and what the full rules are you're using.

So:
- rules
- How is GPIO14 connected (via switch apparently)
- How is GPIO16 connected (has it a task assigned, or do you only set it via rules, thus it is an output?)
- What resistor value do you use on GPIO-16 to pull down? (not sure if that's the way to go by the way, as GPIO-16 is a bit special)
- What is your intended result (you're setting GPIO-16 with value of the dummy, but where is the dummy value set) ?
Firstlyl, apologies for making this thread quite long but I am unable to create a new post and hence I am writing under the same topic.
1)Rules:-
On Hall_light#state do
gpio,16,[dummy#var1]
timerset,1,1
endon
On Rules#Timer=1 do
gpio,16,[dummy#var1]
timerset,1,1
endon
Top

2) GPIO 14 is connected to a wall switch(One way) which gives 3.3v on turning on and 0 on turning it off

3) GPIO 16 is connected to the relay and it's the only function is to operate the light(load)

4) 220ohm resistor is used to pull down the GPIO -16

5)When I do high frequency switching like continuous on off, then irrespective of the GPIO used maybe it is 16 or 4, it starts toggling and stops after certain amount of time. My intention is to stop this toggling in high frequency switching scenario.

6)As I am newbie in using ESPeasy I have very limited knowledge regarding the rules and hence it is my first time using a variable and a timerset. So please let me know if I am doing something wrong. I have gone through documentation but I was unable find a example that would help me to achieve my intentions.

Sorry, for the long threads again..
Last edited by ssd on 31 Aug 2020, 13:11, edited 1 time in total.

Micha_he
Normal user
Posts: 369
Joined: 07 Feb 2018, 19:14
Location: Helmstedt, Germany

Re: Rules using 'OR"

#41 Post by Micha_he » 31 Aug 2020, 13:10

Maybe it's better to activate "LongPress"-event and use:

On Hall_light#state=10 do (or On Hall_light#state=11 do) to switch your output-GPIO. This avoids short (0-500ms) switching operations.

My idea:

Code: Select all

On Hall_light#state=11 do
  GPIO,16,1
endon

On Hall_light#state=0 do
  GPIO,16,0
endon
Or,.... I didn't understand what you want to get ?!
Last edited by Micha_he on 31 Aug 2020, 13:32, edited 1 time in total.

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Rules using 'OR"

#42 Post by TD-er » 31 Aug 2020, 13:12

Don't feel sorry, it is just that I do read lots of threads, so every now and then I also start to feel lost in the information needed.
So it was just to make sure I didn't miss any info and also for someone else jumping in the conversation a summary like this is also helping to get the information all in one place again as it is easy over overlook some missing key information part or update.

And since it is about the same problem, I don't think creating a new topic would have made it more clear.
I wonder why you can't create a new topic by the way. Maybe it has to do with a recent update of the forum anti spam plugins, that you now need to have a minimum number of posts first? (we're seeing lots of spam activity lately)


When I look at your rules, I wonder how the data is set in the dummy task.
A dummy can only receive data via a command like taskvalueset.
So where is it set?

And if it is set in some other part of the rules, maybe it would be a better idea to only set the GPIO pin in the timer block, not in the event handler of the switch.

Code: Select all

On Hall_light#state do
  timerset,1,1
endon

On Rules#Timer=1 do
  gpio,16,[dummy#var1]
  timerset,1,1
endon
Disadvantage is that you may introduce a delay of 1 second before it will first change the relay state after pressing the button.

ssd
Normal user
Posts: 53
Joined: 19 Aug 2020, 12:04

Re: Rules using 'OR"

#43 Post by ssd » 31 Aug 2020, 14:30

TD-er wrote: 31 Aug 2020, 13:12 Don't feel sorry, it is just that I do read lots of threads, so every now and then I also start to feel lost in the information needed.
So it was just to make sure I didn't miss any info and also for someone else jumping in the conversation a summary like this is also helping to get the information all in one place again as it is easy over overlook some missing key information part or update.

And since it is about the same problem, I don't think creating a new topic would have made it more clear.
I wonder why you can't create a new topic by the way. Maybe it has to do with a recent update of the forum anti spam plugins, that you now need to have a minimum number of posts first? (we're seeing lots of spam activity lately)


When I look at your rules, I wonder how the data is set in the dummy task.
A dummy can only receive data via a command like taskvalueset.
So where is it set?

And if it is set in some other part of the rules, maybe it would be a better idea to only set the GPIO pin in the timer block, not in the event handler of the switch.

Code: Select all

On Hall_light#state do
  timerset,1,1
endon

On Rules#Timer=1 do
  gpio,16,[dummy#var1]
  timerset,1,1
endon
Disadvantage is that you may introduce a delay of 1 second before it will first change the relay state after pressing the button.
I tried this rule but in this case the relay is switched on and off when I turn on the wall switch.

ssd
Normal user
Posts: 53
Joined: 19 Aug 2020, 12:04

Re: Rules using 'OR"

#44 Post by ssd » 31 Aug 2020, 14:43

Micha_he wrote: 31 Aug 2020, 13:10 Maybe it's better to activate "LongPress"-event and use:

On Hall_light#state=10 do (or On Hall_light#state=11 do) to switch your output-GPIO. This avoids short (0-500ms) switching operations.

My idea:

Code: Select all

On Hall_light#state=11 do
  GPIO,16,1
endon

On Hall_light#state=0 do
  GPIO,16,0
endon
Or,.... I didn't understand what you want to get ?!
I tried it but the output pin is turned on irrespective of the wall switch status. I guess it won't work as it is a physical wall switch and not push button switch.

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Rules using 'OR"

#45 Post by TD-er » 31 Aug 2020, 15:26

I'm still missing the part of your code where the dummy value is set.

ssd
Normal user
Posts: 53
Joined: 19 Aug 2020, 12:04

Re: Rules using 'OR"

#46 Post by ssd » 02 Sep 2020, 07:07

TD-er wrote: 31 Aug 2020, 15:26 I'm still missing the part of your code where the dummy value is set.
I did not set any dummy value for the code. Can you help me with some documentation or an example where I can set a dummy value?

Micha_he
Normal user
Posts: 369
Joined: 07 Feb 2018, 19:14
Location: Helmstedt, Germany

Re: Rules using 'OR"

#47 Post by Micha_he » 02 Sep 2020, 07:56

Look here: https://www.letscontrolit.com/wiki/inde ... rial_Rules under TaskValueSet.

But what should the variable do? The basic description of what the rule should do is still missing.
Only: Switch Hall_light=On then change GPIO16 to 1 and when switch Hall_light=Off the change GPIO16 back to 0 ? And prevent short ON-switching!

No other switches are connected?
Then my rule should work !? Maybe it's better, when you show us your device configurations.

ssd
Normal user
Posts: 53
Joined: 19 Aug 2020, 12:04

Re: Rules using 'OR"

#48 Post by ssd » 02 Sep 2020, 08:15

Micha_he wrote: 02 Sep 2020, 07:56 Look here: https://www.letscontrolit.com/wiki/inde ... rial_Rules under TaskValueSet.

But what should the variable do? The basic description of what the rule should do is still missing.
Only: Switch Hall_light=On then change GPIO16 to 1 and when switch Hall_light=Off the change GPIO16 back to 0? And prevent short ON-switching!

No other switches are connected?
Then my rule should work !? Maybe it's better when you show us your device configurations.
The rest of the functionality is working perfectly for me but the problem arises when I do high frequency switching. It goes into toggle mode and I want to prevent that scenario. I am unable to share the screenshots of the device configurations on ESPeasy. Is there any specific format for the image to be shared? I tried Your rule but it toggles continuously when I turn the appliance on using the Wall switch.

Micha_he
Normal user
Posts: 369
Joined: 07 Feb 2018, 19:14
Location: Helmstedt, Germany

Re: Rules using 'OR"

#49 Post by Micha_he » 02 Sep 2020, 08:30

And your 'wall switch' is connected to GPIO14 and the device-name is 'Hall_light' ?
And GPIO14 has a pull-down/pull-up resistor? Is the switch connected to 3.3V or ground?

The state of the switch device only go to a value 11, when the longpress-time has passed.
State 0 occurs immediately. You can see it in the log while you toogle the wall-switch.

How this single rule supposed to generate constant switching?

ssd
Normal user
Posts: 53
Joined: 19 Aug 2020, 12:04

Re: Rules using 'OR"

#50 Post by ssd » 02 Sep 2020, 09:01

Micha_he wrote: 02 Sep 2020, 08:30 And your 'wall switch' is connected to GPIO14 and the device-name is 'Hall_light' ?
And GPIO14 has a pull-down/pull-up resistor? Is the switch connected to 3.3V or ground?

The state of the switch device only go to a value 11, when the longpress-time has passed.
State 0 occurs immediately. You can see it in the log while you press/release the switch.

How this single rule supposed to generate constant switching?
It is not a press and release kind of switch. It is a physical wall switch(one way) which has two poles, so when you press it down it is ON and when you press it upwards it is off.
GPIO 14 is connected to this switch and the name is "Wall_Hall_Light"...This GPIO is set as input in hardware
GPIO 16 is pull down and connected to the relay that operates the appliance with name "Hall_light".

GPIO14 and GPIO16 has same idx w.e.f to domoticz as a server. So when GPIO14 is 1 GPIO 16 also changes its state because of same idx on domoticz which inturn switches the relay to turn on the appliance

I have updated the rule as:-
on Wall_Hall_Light#state do
if [dummy#var1]=0
TaskValueSet 14,1,0
else
TaskValueSet 14,1,1
endif
endon

On Wall_Hall_Light#state do
timerset,1,1
endon

On Rules#Timer=1 do
gpio,14,[dummy#var1]
timerset,1,1
endon

But the problem still persist....

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Google [Bot] and 24 guests