# How to prevent lights from turning off by Homey-Flow when I turn them manually

**URL:** <https://community.homey.app/t/how-to-prevent-lights-from-turning-off-by-homey-flow-when-i-turn-them-manually/116052>\
**Category:** Questions & Help\
**Tags:** z-wave, homey-pro\
**Created:** [September 14, 2024, 11:28pm UTC](https://community.homey.app/t/how-to-prevent-lights-from-turning-off-by-homey-flow-when-i-turn-them-manually/116052 "2024-09-14T23:28:26Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Giovanni\_Dienstmann](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/giovanni_dienstmann/32/112852_2.png) [@Giovanni\_Dienstmann](https://community.homey.app/u/Giovanni_Dienstmann)\
**Post date:** [September 14, 2024, 11:28pm UTC](https://community.homey.app/t/how-to-prevent-lights-from-turning-off-by-homey-flow-when-i-turn-them-manually/116052/1 "2024-09-14T23:28:26Z")

</div>

I have my lights connected to Homey via the Shelly Wave relays, in a way that they turn on and off based on automation that use either motion sensors directly, or “zone active” triggers. They were wired in a way that the physical switches on the wall retain their normal functioning

Now the problem is that sometimes I want to turn on the light and leave it on, and it’s not working. Here is what happens:

- I manually turn on a corridor light because I’ll need to spend some time there
- As I walk in, the motion sensor triggers a motion alarm (even though the light is already on)
- After 30 seconds, the motion sensor send a “alarm turned off”, which triggers the automation and turn off the light.

To solve this I’d imagine we would need to be able to differentiate, in Homey, if a light was turned on via an automation or manually via the switch. How to do that?

I believe there is a simple solution to this, but I’m still too much of a home automation newbie to figure it out 🤷🏼

---

<div class="post-metadata">

**Author:** ![Peter\_Kawa](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/peter_kawa/32/173848_2.png) [@Peter\_Kawa](https://community.homey.app/u/Peter_Kawa)\
**Post date:** [September 15, 2024, 1:16am UTC](https://community.homey.app/t/how-to-prevent-lights-from-turning-off-by-homey-flow-when-i-turn-them-manually/116052/2 "2024-09-15T01:16:55Z")

</div>

Hi Giovanni,

I once made a similar flow example

> [@The Flow Exchange(r) - Exchange Your Flows with Others!](https://community.homey.app/t/the-flow-exchange-r-exchange-your-flows-with-others/68981/84):
>
> # Zone activated Device with Manual Device OnOff option
> 
> When you have, say, a garage with (a) motion sensor(s), and (a) (garage)door sensor(s), the light should turn on for 3 minutes after a motion event, or an opened garagedoor;  
> While there’s movement, lights stay on;  
> When the button gets pushed, lights should turn on, and stay on until the button is pushed again.
> 
> ![Screenshot 2023-09-17 at 03-11-50 1.HomeyPro Peter](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/d/c/dc5e2a670aff248e5dc0f34e5574e59fe968955a.png)
> 
> ### Apps used:
> 
> - [Chronograph](https://homey.app/a/nl.fellownet.chronograph)

---

<div class="post-metadata">

**Author:** ![Giovanni\_Dienstmann](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/giovanni_dienstmann/32/112852_2.png) [@Giovanni\_Dienstmann](https://community.homey.app/u/Giovanni_Dienstmann)\
**Post date:** [September 15, 2024, 1:54am UTC](https://community.homey.app/t/how-to-prevent-lights-from-turning-off-by-homey-flow-when-i-turn-them-manually/116052/3 "2024-09-15T01:54:28Z")

</div>

Thank you, I’ll try this out and let you know how it goes. It’s my first advanced flow so there will be a bit of a learning curve for me.

---

<div class="post-metadata">

**Author:** ![robertklep](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/robertklep/32/160628_2.png) [@robertklep](https://community.homey.app/u/robertklep)\
**Post date:** [September 15, 2024, 5:12am UTC](https://community.homey.app/t/how-to-prevent-lights-from-turning-off-by-homey-flow-when-i-turn-them-manually/116052/4 "2024-09-15T05:12:13Z")

</div>

> [@Giovanni\_Dienstmann](#):
>
> To solve this I’d imagine we would need to be able to differentiate, in Homey, if a light was turned on via an automation or manually via the switch. How to do that?

How I solved this (conceptually):

- put the Shelly in detached mode, which means it decouples the “switch” action from the “turn light on/off” action
- when the switch is turned on, it means the light should always be on, even if no motion has been detected anymore
- when the switch is turned off, the lights are turned on/off depending on the motion state

---

<div class="post-metadata">

**Author:** ![Giovanni\_Dienstmann](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/giovanni_dienstmann/32/112852_2.png) [@Giovanni\_Dienstmann](https://community.homey.app/u/Giovanni_Dienstmann)\
**Post date:** [September 15, 2024, 7:39am UTC](https://community.homey.app/t/how-to-prevent-lights-from-turning-off-by-homey-flow-when-i-turn-them-manually/116052/5 "2024-09-15T07:39:52Z")

</div>

But would this prevent the motion trigger automation from turning off the lights when the switch was first turned on manually?

---

<div class="post-metadata">

**Author:** ![robertklep](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/robertklep/32/160628_2.png) [@robertklep](https://community.homey.app/u/robertklep)\
**Post date:** [September 15, 2024, 7:43am UTC](https://community.homey.app/t/how-to-prevent-lights-from-turning-off-by-homey-flow-when-i-turn-them-manually/116052/6 "2024-09-15T07:43:50Z")

</div>

Like I said, I described how it works conceptually. In a flow you need to add a condition to check if the switch is on, and if so, not turn off the lights.

I basically have these flows (well, automations, as I use Home Assistant):

- WHEN there is motion THEN turn on the light
- WHEN the switch is set to “on” THEN turn on the light
- WHEN there is no more motion AND the switch is set to “off” THEN turn off the lights

---

<div class="post-metadata">

**Author:** ![Giovanni\_Dienstmann](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/giovanni_dienstmann/32/112852_2.png) [@Giovanni\_Dienstmann](https://community.homey.app/u/Giovanni_Dienstmann)\
**Post date:** [September 17, 2024, 9:33am UTC](https://community.homey.app/t/how-to-prevent-lights-from-turning-off-by-homey-flow-when-i-turn-them-manually/116052/7 "2024-09-17T09:33:35Z")

</div>

The challenge that I’m having is differentiating the trigger based on whether the lights were turned on directly from the wall switch, instead of as a result of a flow. Any idea how to do that?  
The image attached is what I tried, but it didn’t work. Apparently the “Turned on” state gets triggered not only when turning on from the switch but also when turned on via a flow.

 ![Screenshot of Google Chrome at 17 Sep 2024 at 7_32_29 PM](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/d/6/d65443ed07f4669590429d84242e6f9e0e6a3725.png)

---

<div class="post-metadata">

**Author:** ![robertklep](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/robertklep/32/160628_2.png) [@robertklep](https://community.homey.app/u/robertklep)\
**Post date:** [September 17, 2024, 9:49am UTC](https://community.homey.app/t/how-to-prevent-lights-from-turning-off-by-homey-flow-when-i-turn-them-manually/116052/8 "2024-09-17T09:49:06Z")

</div>

Does your Shelly device actually have a detachable switch option? Because if not, my solution isn’t going to work.

---

<div class="post-metadata">

**Author:** ![Giovanni\_Dienstmann](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/giovanni_dienstmann/32/112852_2.png) [@Giovanni\_Dienstmann](https://community.homey.app/u/Giovanni_Dienstmann)\
**Post date:** [September 17, 2024, 10:11am UTC](https://community.homey.app/t/how-to-prevent-lights-from-turning-off-by-homey-flow-when-i-turn-them-manually/116052/9 "2024-09-17T10:11:31Z")

</div>

I am not sure what you mean.  
This is the product that I am using for all lights at home: [Shelly Qubino Z-Wave 2PM Double Relay Switch - SmartHome](https://www.smarthome.com.au/product/shelly-qubino-z-wave-2pm-double-relay-switch/)

---

<div class="post-metadata">

**Author:** ![robertklep](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/robertklep/32/160628_2.png) [@robertklep](https://community.homey.app/u/robertklep)\
**Post date:** [September 17, 2024, 10:23am UTC](https://community.homey.app/t/how-to-prevent-lights-from-turning-off-by-homey-flow-when-i-turn-them-manually/116052/10 "2024-09-17T10:23:32Z")

</div>

As I explained, the way I’ve set this up is in detached mode. This is available on Shelly WiFi devices, I don’t know if it’s also available on Z-Wave devices.

What this does is logically detach the switch from the relay. In other words, changing the state of the switch does not change the state of the relay. All it does is send Homey a signal “Hey, the state of the switch changed”, and you can then, with a flow, act on that (or not).

That way, you can check the state of the switch and stop the light from turning off after 3 minutes of inactivity (when the switch is set in the “On” position, you keep the light on). It’s similar to what you’re doing with the “ManualOn-Ensuite” variable, however, based on a _physical_ state (that is, the position of the switch).

AFAIK, the “Turned on/off” cards cannot differentiate between flow or switch, so you can’t use them, and I don’t know if there’s even a solution. The flow that @Peter_Kawa is showing uses a separate Button device, but in your case there isn’t one.

---

<div class="post-metadata">

**Author:** ![Giovanni\_Dienstmann](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/giovanni_dienstmann/32/112852_2.png) [@Giovanni\_Dienstmann](https://community.homey.app/u/Giovanni_Dienstmann)\
**Post date:** [September 18, 2024, 10:05am UTC](https://community.homey.app/t/how-to-prevent-lights-from-turning-off-by-homey-flow-when-i-turn-them-manually/116052/11 "2024-09-18T10:05:43Z")

</div>

Thanks. I’ll email Shelly support and see if that is possible with Shelly Wave.

---

<div class="post-metadata">

**Author:** ![Phil\_Bro](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/phil_bro/32/78156_2.png) [@Phil\_Bro](https://community.homey.app/u/Phil_Bro)\
**Post date:** [September 20, 2024, 8:15pm UTC](https://community.homey.app/t/how-to-prevent-lights-from-turning-off-by-homey-flow-when-i-turn-them-manually/116052/12 "2024-09-20T20:15:36Z")

</div>

The detach mode is a solution. I would prefer suggesting a flow adjustment on the sensor, detaching will result the shelly does not know what the actual status is when switched by Homey instead of manual (I suppose) Keep it normal the state will be as is, regardless manual or flow switched.

If it detects movement (current it will switch shelly on), change:

THEN check if the shelly is ON,

YES → do nothing  
NO → switch on

Simple as that.

---

<div class="post-metadata">

**Author:** ![Phil\_Bro](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/phil_bro/32/78156_2.png) [@Phil\_Bro](https://community.homey.app/u/Phil_Bro)\
**Post date:** [September 20, 2024, 8:20pm UTC](https://community.homey.app/t/how-to-prevent-lights-from-turning-off-by-homey-flow-when-i-turn-them-manually/116052/13 "2024-09-20T20:20:31Z")

</div>

You need to use a variable which is set to (f.i.) the value 2 if the flow has switched on the light, 1 if set manual (by detecting change on the status of the shelly) and will return set to 0 when off. So in the flow you use a query to check the light, not the state if it’s on, but the variable you use.

Phil

EDIT  
I have something similar going with a 2-stand motor, it cannot be used in setting 1 + 2, it must be 1 or 2. In order to do so I use queries on a variable to see if the motor (shelly 2P) is set manual to 1 or 2 or by flow (time-based). It protects the option to switch 2 when 1 is on and vice versa.

---

<div class="post-metadata">

**Author:** ![Giovanni\_Dienstmann](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/giovanni_dienstmann/32/112852_2.png) [@Giovanni\_Dienstmann](https://community.homey.app/u/Giovanni_Dienstmann)\
**Post date:** [September 20, 2024, 10:49pm UTC](https://community.homey.app/t/how-to-prevent-lights-from-turning-off-by-homey-flow-when-i-turn-them-manually/116052/14 "2024-09-20T22:49:01Z")

</div>

Thanks, I’ll try this!

---

<div class="post-metadata">

**Author:** ![robertklep](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/robertklep/32/160628_2.png) [@robertklep](https://community.homey.app/u/robertklep)\
**Post date:** [September 21, 2024, 4:43am UTC](https://community.homey.app/t/how-to-prevent-lights-from-turning-off-by-homey-flow-when-i-turn-them-manually/116052/15 "2024-09-21T04:43:51Z")

</div>

> [@Phil\_Bro](#):
>
> detaching will result the shelly does not know what the actual status is when switched by Homey instead of manual

Shelly knows both the state of the switch and of the relay. At least it does on Home Assistant, which I use.

> [@Phil\_Bro](#):
>
> You need to use a variable which is set to (f.i.) the value 2 if the flow has switched on the light, 1 if set manual (by detecting change on the status of the shelly) and will return set to 0 when off. So in the flow you use a query to check the light, not the state if it’s on, but the variable you use.

You don’t need to use variables if you use the method that I described. Since Shelly can read the state of the switch, it can be used as an override for the motion sensor. But I explained all this a number of times already.

---

<div class="post-metadata">

**Author:** ![Phil\_Bro](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/phil_bro/32/78156_2.png) [@Phil\_Bro](https://community.homey.app/u/Phil_Bro)\
**Post date:** [September 21, 2024, 7:43am UTC](https://community.homey.app/t/how-to-prevent-lights-from-turning-off-by-homey-flow-when-i-turn-them-manually/116052/16 "2024-09-21T07:43:10Z")

</div>

Ok Robert, if both shelly states are readable, they can be put in queries, I agree with you. Thanks!

---

<div class="post-metadata">

**Author:** ![Giovanni\_Dienstmann](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/giovanni_dienstmann/32/112852_2.png) [@Giovanni\_Dienstmann](https://community.homey.app/u/Giovanni_Dienstmann)\
**Post date:** [September 21, 2024, 9:42am UTC](https://community.homey.app/t/how-to-prevent-lights-from-turning-off-by-homey-flow-when-i-turn-them-manually/116052/17 "2024-09-21T09:42:12Z")

</div>

Okay, so I think I got this to work. For those who visit this thread in the future, this is my flow:

 ![Screenshot of Google Chrome at 21 Sep 2024 at 7_40_56 PM](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/9/2/9240c477be141718e465c4c180154b4f20c4d430.png)

---

<div class="post-metadata">

**Author:** ![Wim\_Post](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/wim_post/32/56793_2.png) [@Wim\_Post](https://community.homey.app/u/Wim_Post)\
**Post date:** [September 22, 2024, 10:00am UTC](https://community.homey.app/t/how-to-prevent-lights-from-turning-off-by-homey-flow-when-i-turn-them-manually/116052/18 "2024-09-22T10:00:22Z")

</div>

What borders me is : your variable ‘PIR motion detected’ is set to no, when there actually might be motion.

I would create a variable ‘light X is turned on manually’ which is set to YES when you manually turn on the lights. And to NO, when you turn off the lights

When motion is detected check the value of ‘ light X is turned on manually’  
If YES; no action. If NO; action.

Same when motiondetection ends.

---

<div class="post-metadata">

**Author:** ![Giovanni\_Dienstmann](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/giovanni_dienstmann/32/112852_2.png) [@Giovanni\_Dienstmann](https://community.homey.app/u/Giovanni_Dienstmann)\
**Post date:** [September 22, 2024, 10:50am UTC](https://community.homey.app/t/how-to-prevent-lights-from-turning-off-by-homey-flow-when-i-turn-them-manually/116052/19 "2024-09-22T10:50:13Z")

</div>

That was my initial approach, but it didn’t work, because “light turned on” is equally triggered whether it was turned on by the switch or by a Flow.  
The Flow above seems to be working so far.

---

<div class="post-metadata">

**Author:** ![Wim\_Post](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/wim_post/32/56793_2.png) [@Wim\_Post](https://community.homey.app/u/Wim_Post)\
**Post date:** [September 22, 2024, 11:07am UTC](https://community.homey.app/t/how-to-prevent-lights-from-turning-off-by-homey-flow-when-i-turn-them-manually/116052/20 "2024-09-22T11:07:50Z")

</div>

I see. I have several buttons around the house at strategic places. For example above the kitchen countertop. Normally the light turnes on by the lightsensor. But sometimes I need more light. And I don’t want the lightsensor to turn off the light.

So my trigger is a button pressed. You turn the light on manually by the app?

[Next page](https://community.homey.app/t/how-to-prevent-lights-from-turning-off-by-homey-flow-when-i-turn-them-manually/116052.md?page=2)
