# Ignore events from automation

**URL:** https://discourse.nodered.org/t/ignore-events-from-automation/53194
**Category:** General
**Created:** [4 November 2021 03:06 UTC](https://discourse.nodered.org/t/ignore-events-from-automation/53194 "2021-11-04T03:06:39Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![Leonti](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/leonti/32/50435_2.png) [@Leonti](https://discourse.nodered.org/u/Leonti)
#### Post date: [4 November 2021 03:06 UTC](https://discourse.nodered.org/t/ignore-events-from-automation/53194/1 "2021-11-04T03:06:39Z")

</div>

Hi!

Is there a way to distinguish events coming from a physical button press vs events triggered by automation?

I have Tasmota light switches which are communicating with Home Assistant via MQTT.  
What I'm trying to do is to use of of the switches to turn all lights to on and off.  
I also want this switch to represent the overall state of the switches.

Let's call the main switch the `all_switch`, it's not connected to the wiring, so I would use it for input and for it's LED indicator.  
Then I have `switch_1` and `switch_2`

I want to use `all_switch` to turn `switch_1` and `switch_2` on or off both at the same time.  
Also, when I turn either `switch_1` or `switch_2` `on` then `all_switch` should also be `on`. This way I will know that some of the lights are still on and I can turn them off by pressing the `all_switch`.  
On the other hand, when both `switch_1` and `switch_2` are `off`, `all_switch` should also be `off`.

The problem with implementing it is that once I detect that `switch_1` is `on` I will want to turn `all_switch` `on` which in turn will trigger turning all of the lights on.

So is there a way to turn the switch `on`, but ignore subsequent `on` event from that switch, because I know it's coming from automation and not from the physical press?

Cheers,  
Leonti

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [4 November 2021 09:03 UTC](https://discourse.nodered.org/t/ignore-events-from-automation/53194/2 "2021-11-04T09:03:36Z")

</div>

Welcome to the forum @Leonti

So we can understand better could you post the flow you currently have so we can see how you are handling the switches. Export just the nodes to do with the switch handling. See this post for how to post flows here - [How to share code or flow json](https://discourse.nodered.org/t/how-to-share-code-or-flow-json/506)

---

<div class="post-metadata">

### Author: ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)
#### Post date: [4 November 2021 09:39 UTC](https://discourse.nodered.org/t/ignore-events-from-automation/53194/3 "2021-11-04T09:39:20Z")

</div>

you should be able to add another or different property to the messages from each source - eg topic from the button - which you could then use to tell them apart later in the flow.

---

<div class="post-metadata">

### Author: ![Leonti](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/leonti/32/50435_2.png) [@Leonti](https://discourse.nodered.org/u/Leonti)
#### Post date: [5 November 2021 02:10 UTC](https://discourse.nodered.org/t/ignore-events-from-automation/53194/4 "2021-11-05T02:10:16Z")

</div>

Hi guys, thanks for your replies!  
I'm attaching the flow in progress which exhibits the issue I'm trying to overcome.  
So at the moment when "Study room" button is pressed I want to turn the "All lights" switch on. I only want it to switch on so the indicator would indicate that at least a single light in my apartment is on. That particular switch is not connected to any wiring (apart from the power).

When "All lights" switch is pressed I want to turn the light in a bathroom and living room, but only if it's physically pressed, not by automation.

So what's happening now is:

1. I press the switch in the study room, which turns "All lights" on
2. "All lights pressed" is being triggered and turns on other lights, which is not desirable, since I didn't actually press "All lights" button.

So in this situation, how to I detect whether "All lights pressed" event is coming from a physical press or whether it was triggered by another flow/subflow?

 ![all_lights_flow](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/e/5e8fdf354d2a877e62bb645e298ef180eb370376.png)  
[all\_lights\_flow.json](https://discourse.nodered.org/uploads/short-url/3XIKMc67Nlh5jDCHweVYuTnacaq.json) (6.8 KB)

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [5 November 2021 09:05 UTC](https://discourse.nodered.org/t/ignore-events-from-automation/53194/5 "2021-11-05T09:05:48Z")

</div>

You had not mentioned that this is a Home Assistant question. Few here use HA, you might be better asking on a HA forum.

---

<div class="post-metadata">

### Author: ![Leonti](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/leonti/32/50435_2.png) [@Leonti](https://discourse.nodered.org/u/Leonti)
#### Post date: [6 November 2021 00:45 UTC](https://discourse.nodered.org/t/ignore-events-from-automation/53194/6 "2021-11-06T00:45:20Z")

</div>

I didn't think it was HA-specific question. To me, it ultimately boils down to distinguishing whether event was coming externally (physical button press) or from automation (Node Red).  
Where HA is concerned I will always be getting an 'on' event no matter how it was initiated.

What I was thinking about is some kind of pattern where you call a function, it sets a timestamp in some global variable and later when I receive "All lights pressed" I'd check current time against that timestamp and if the difference is less then say 200ms I know it came from automation, so I can just ignore it.

Maybe this kind of pattern is more common in HA, will ask there, thanks!

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [6 November 2021 15:35 UTC](https://discourse.nodered.org/t/ignore-events-from-automation/53194/7 "2021-11-06T15:35:14Z")

</div>

Change the dashboard switch settings so it doesn't pass through messages it receives, so when you get an event from the dashboard switch you know it is from the switch.

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)
#### Post date: [5 January 2022 15:35 UTC](https://discourse.nodered.org/t/ignore-events-from-automation/53194/8 "2022-01-05T15:35:39Z")

</div>

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
