Is it possible to configure HA to differentiate motion and manual button pressed?

I’m new to Home Assistant. Before I start purchasing equipment and dive into Home Assistant ecosystem, there’s always this one thing I can’t get it to work currently.

I have a bunch of smart light switches around the house. I want to set it up where if a user manually pressed the button on the switch then the light will turn on forever until the user manually turns it off. Otherwise if the motion sensor no longer senses any motion within 15 minutes then the light will turn off automatically. Currently regardless if I pressed the button, the light will turn off within 15 minutes if there is no motion. Is it possible to configure HA to resolve this issue? If there’s a way to differentiate the difference between manual press and motion sensing, I think it can be done.

If these are currently two different automations you have set up in HA, then yes they definitely can be combined to work as you desire.

If both these functions as currently setup are provided in hardware by the one same button/motion sensor combo hooked directly to a light, impossible to say.

First off, how is your Smart Switch connected to Home Assistant? I ask because I don’t want to assume that it is, simply because there are so called smart switches that do exactly what you describe, but are really a dumb switch with a built in timer and motion detector.
If, in fact, your switch is connected to HA, where is the 15 minute delay defined? Is it a configuration parameter of the device or are you using a delay or timer in an automation? Lastly, can you see the device and its parameters in the Developer Tools states tab?
Also, can you send an internet link to the switch you are using, so we can see what features it exposes to Home Assistant.
Once you can answer these basic questions, we can try to help you further.

Currently the sensor and the smart switch are two separate hardware. They’re both connected to my SmartThings hub and also accessible via Alexa.

These smart devices are not connected to HA. I’m exploring HA options since I couldn’t get them to work like I stated in my initial post.

I do have one smart switch that combines a sensor; however, a majority of my smart switches I do have a separate motion sensor that works with the switch. These are some of the IoT I have.

Switches:

  • Kasa smart 3-way switch KS230 KIT v2
  • Kasa Smart WiFi Motion Sensor Switch KS200M
  • Kasa Smart 3 Way Switch HS210
  • Zooz Z-Wave Plus Wall Dimmer Switch ZEN22
  • Smart Dimmer Switch by Martin Jerry
  • WeMo (F7C059) Dimmer Wifi Light Switch
  • Zooz Z-Wave Plus On Off Wall Switch ZEN21
  • Wemo F7C030fc Light Switch

Sensors:

  • SAMSUNG SmartThings GP-U999SJVLBAA
  • SAMSUNG SmartThings Water Leak Sensor
  • Ring Alarm Contact Sensor
  • Ring Flood Freeze

Plugs:

  • TP-Link Tapo Smart Plug Mini 15A
  • Smart Plug ESICOO, WiFi Plugs
  • NEO Z-Wave Plus Smart Mini Power Plug
  • Etekcity WiFi Smart Plug

I do have a Ring door bell and a Nest thermostat. However, my biggest issue is the light switch.

OK, so the switch is currently connected to your SmartThings Hub, correct? Is that how it is being turned OFF after 15 minutes? If not, please explain how that switch is being turned off.

As Mayhem_SWE stated, it is possible to achieve what you want in HA, especially if the switch and motion sensor are two separate devices. You’ll needing simple automation to turn the light on with motion, a delay of 15 minutes (or a 15 minute timer) and then an action to turn the light off IF there has been no motion for x minutes.
If you also want the light to turn off after a manual turn on, you’ll need a second automation to turn the light off after a period of time, again using motion as a conditional statement.

One bit of advice; keep your automation focused one single action until you are very comfortable creating automations, scripts and other actions. Write ONE automation to turn on a light triggered by your motion sensor and include the necessary delay and then a turn off action. Here is a simple example. This code turns on the Kitchen under cabinet lights (UCL’s) triggered by motion after 11pm, waits 2 minutes then turns them back off:

- id: kitchen_ucls_on_after_2300
  alias: Kitchen UCLs on after 2300
  initial_state: TRUE
  mode: restart
  triggers:
    - trigger: state
      entity_id:
        - binary_sensor.kitchen_4in1_motion
        - binary_sensor.living_room_4in1_motion
      from: "off"
      to: "on"
  conditions:
    - condition: time
      after: "23:00:00"
      before: "06:00:00"
  actions:
    - action: light.turn_on
      data:
        entity_id: light.kitchen_uc_leds
    - action: light.turn_on
      data:
        entity_id: light.coffee_bar_leds
        brightness: 127
    - delay: "00:02:00"
    - action: light.turn_off
      data:
        entity_id: light.kitchen_uc_leds
    - action: light.turn_off
      data:
        entity_id: light.coffee_bar_leds

I’d be glad to help you develop the code, but it would be very helpful if you could identify the switch and motion detector you’d like to use for this (and confirm that they are connected to HA and not the SmartThings hub.)

1 Like
1 Like

Thank you very much for the sample code. At the moment I’m exploring HA’s capabilities to see if it’ll solve some of my issues. Once I see that it can, I will have to invest in a dedicated hardware to host HA.

By the way, when do I use Python or YAML on HA’s environment?

There are several ways to create automations in HA. The easiest is to use the graphical interface. It provides a simple way to create code without actually writing any code. This simplicity comes at the cost of advanced programming options. YAML coding is a more advanced way to create anything from simple to very complex code. Python is typically only used for creation of the core code, add ones and other high level coding. Some users create complex code in python, but this is not the typical way most users interact with HA. Beginners typically use the GUI until their skills and needs bring them to YAML coding. When, or if, this occurs depends on the complexity of the system you want to build. Many users get by just fine using the GUI and can automate lights, switches and even audio.
Personally I don’t use the GUI, and code entirely in YAML. I have a very extensive home automation system that I continue to improve and expand on a regular basis, so YAML just makes life easier for me. I do not use Python directly for any my configuration, nor do I build or create add ons, integrations or other user extensions. I see myself as beyond a beginner, but by no means an expert. I’ve been using Home Assistant for about 9 or 10 years now, nearly since its beginning in 2013.
I think you’ll find HA a very capable platform that can support a wide variety of devices, API ‘s and has the power to build anything from a simple to a very complex home automation system. In essence, your creativity will not be hampered by HA’s abilities.

1 Like

Thank you so much for the explanation. I will slowly work my way into HA’s environment. I surely be back for more help and suggestions. Thanks a bunch!

Is your HA environment up and running? Let’s focus on that first.

Once the HA environment is up and running, I would recommend you start small. Maybe start with only the KS200M, moving it into HA via this HA integration. You could at least use this KS200M as a test bed to see what HA has to offer.

I don’t have KS200M so would not know for sure, but if this specific Kasa switch would let you independently control the switch (via wifi) regardless the motion sensor status - meaning it would let you decouple the motion sensor and the on/off switch - I’m pretty confident that you can achieve what you asked earlier:

And, back to your python or yaml question - no I don’t think you would need either. You might want to use those only if you are trying to do advanced stuff, but given the robustness of the HA automation engine these days, very likely you would not need to touch codes - the GUI is pretty capable these days.

I moved away from ST back in 2018 and never (need nor want to) look back.

== sidebar ==
I noticed you have a couple of z-wave devices. To include those into HA, you will need at least a z-wave USB stick (that is connected to your HA environment) to accommodate all the devices you have listed.

One automation

2 triggers
Switch to ON
Sensor to detected

Each trigger has seperate ID. Switch and sensor

If switch (condition: trigger ID switch) turn on
No else

If sensor(condition:trigger ID sensor) turn on >> wait 15 >> turn off
No else

Sorry @tmjpugh but OP will need more than that for the automation.
If someone manually turned on the switch, and then 3 minutes later the motion sensor also detected another movements, then the sensor would supersede the previous manual turning on with the wait 15min and off automation… a behavior that is not what OP is looking for.

Logically, and as Magnus mentioned above, it would be 2 automations (or 2 flows in the same automation). The “manually switching on the light” automation would have to also disable the sensor automation flow, and turning the light back on only until someone manually switching the light off.

Another approach is to adapting Tom’s direction (also) above, to build context-aware automations. More complex, but more elegant.

===
Anyways, OP, for the time being let’s focus on getting the HA up and running.

You can add a condition for not turned on by switch

2 automations work just as well and easier