Action requiring conditional timings?

I’m a newbie to HA and to the forum, and this is my first post. I think what I am looking for is pretty straightforward but I’m also a bit daunted by the sheer size and scale of information available in the forum.

So, my office desk has a lamp which I want to control according to whether I am at the desk or not. I’m planning to attach a SmartSense Multi sensor to the chair and plug the lamp in to a SmartPower Outlet. When I first sit down I want the lamp to stay on for at least 60 minutes. Outside the first 60 minutes I want the lamp to go out after five minutes of inactivity. I have chosen the multi sensor over a presence sensor because there are other things going on in the office which should not affect the lighting of the desk, and the chair is on castors and I very rarely sit rock steady for long.

I read somewhere the programming should be easily achieveable in webCoRE. While I’m happy to get stuck in and dirty my hands, I hope you can indulge me on this one. Is it too much to hope somebody has done something similar before?

typically, motion sensors are utilized since they are more sensitive to movement. So a motion sensor under the desk that sees your feet come can trigger the light to come on for 60 min, only once per day or between certain times like 8am to 10 am. Then during other hours, you can set motion to trigger the lamp on and turn off after 5 min of no motion. These automations can be made very quickly using the built in Lighting automation smart app from the smartthings app.

If the condition of “have I already been at my desk” is very important, you might need webcore. There are many ways to achieve this. One way could be creating a variable and setting its status. The variable might be (satAtmyDeskYet). The condition to change it would be motion before 11:59pm.

Here’s an example, although I’m sure others can provide better code options. I haven’t tested it just trying to give you a starting place:

execute
if
Master Bath Motion Sensor’s motion changes to active
and
{@AlreadyDid60minToday} is false
then
with
Master Bath Indirect Lighting
do
Turn on;
Wait 60 minutes;
Turn off;
Set variable {@AlreadyDid60minToday} = true;
end with;
else
if
Master Bath Motion Sensor’s motion changes to active
and
{@AlreadyDid60minToday} is false
then
with
Master Bath Indirect Lighting
do
Turn on;
Wait 5 minutes;
Turn off;
end with;
end if;
end if;
if
{@AlreadyDid60minToday} is true
then
Wait until midnight;
Set variable {@AlreadyDid60minToday} = false;
end if;
end execute;

1 Like

for most webcore questions there is a dedicated webcore discussion board [deleted]

1 Like

You are also going to need a reset point.

What determines when the 60 minute timer kicks in again. The next day or if inactivity is greater than so many hours?

You will need to weigh that into your equation as well. I agree with Matt as well, for what you want to accomplish, webCoRE is probably the right direction to take.

In addition to his suggestion of possibly using a variable in webCoRE, you could also create a virtual switch that when that gets turned on, the light stays on for 60 minutes period and then when that switch turns off, then any time motion is sensed the light will only come on for 5 minutes at a time while that switch is off, and remains on for 5 minutes. Then after it turns off, if you are at your desk and move your feet again, it comes on for another 5 min. But as I stated before, you will need to figure out what the reset point is to allow the 60 minute rule to kick back in. Just some thoughts.

1 Like

Food for thought from Matt_Behnken and WB70. Thanks guys. I have plenty more reading to do. One silly oversight on my part - it hadn’t even occured to me to put a sensor under the desk!

Perhaps my description was overcomplicating the situation. What I want boils down to three rules:

  • if movement detected and light is off then turn light on; T=0
  • if T>0 and T<60 light stays on
  • if T>=60 and no movement detected in previous 5 minutes turn light off

I’m still hoping there is some code already out there i can reuse or at least borrow from :).

With that being said, it could be even simpler if you were to put a motion sensor under the desk. Forget the 60 minute rule for a minute, and just focus on the 5 minutes on.

If you were to setup a rule in Smart Lighting that turns the light on when the motion sensor under the desk is active, then turn the lights on, and then the additional rule to turn off after 5 minutes. If you are at your desk and move during that 5 minutes that automation will kick in again leaving the light that is already on for another 5 minutes. If you then decide to walk away for a break, the light will turn off after the 5 minutes.

If for whatever reason you are at your desk and your legs are frozen for 5 minutes and the motion sensor doesn’t go active and the light turns off, just move your leg or foot so that motion is active again and the light comes on.

That’s just the KISS method rather than the need to over do it.

Or the approach, if the sensor is triggered from underneath, leave the light on for 60 minutes, period. Then if there is no motion for an hour it shuts off. I like the 5 minutes though myself. Cost saving :slight_smile:

nice formula, mapping out the solution is the hardest part!

For webcore, you’ll have to install the smart app, authorize a browser, and replace the devices with your own. I don’t know how to implement a 60 minute countdown that isn’t interrupted by new motion on the sensor. The true/false seems pretty close to the functionality you want. And yes virtual devices work just like Boolean variables, so that route would also work.

//
/* webCoRE Piston #998 */
/
/
/* Author : MattyB /
/
Created : 11/7/2017, 1:06:41 AM /
/
Modified : 11/25/2017, 1:29:40 AM /
/
Build : 2 /
/
UI version : v0.2.0fe.20171109 */
/**************************************************************/

define
boolean 60minuteTimerRunYetToday; /* */
end define;

execute
if
(
Desk Motion Sensor 1’s motion changes to active
and
(
{60minuteTimerRunYetToday} is not true
)
)
then
with
DeskLamp
do
Turn on;
Wait 60 minutes;
Set variable {60minuteTimerRunYetToday} = true;
Turn off;
end with;
else
if
Desk Motion Sensor 1’s motion changes to active
and
(
{60minuteTimerRunYetToday} is true
)
then
with
DeskLamp
do
Turn on;
Wait 5 minutes;
Turn off;
end with;
else
if
{$time24} is '01:00:00 GMT-0600 (MST)'
then
Set variable {60minuteTimerRunYetToday} = false;
end if;
end if;
end if;
if
end if;
end execute;

Can’t fault your reasoning. However the 60 minute rule is essential to any solution.

1 Like