Light control based on various triggers

I had a very well working Groovy app I try to replicate and was wondering which alternative to groovy to use or if something already exists. The features are as follows:

Light Controller

  • Assign a Switch or Light which will be controlled
  • Identify if the switch/light offers dimming and/or colour capability and enable further options (see below)

Controller Triggers

  • Assign a motion device and allow to set after how many minutes no motion the light should be switched off


  • Assign a contact sensor device to block swithcing off the light in case the contact is closed before the last movement.

Enable options if light supports dimmer/colour

  • Allow to set Day/Night mode to Disabled, Light Sensor, Local Sunset/Sunrise or Specific times
  • If Day/Night mode is not disabled and dependent on the light attribute, allow Light level and Color to be set differently for Day and Night

I have to source code for the app, but I guess I can only use that for reference.

Looking forward to hear your suggestions.

Thanks, goppi

You should be able to do most this using ST Routines. One thing to keep in mind is that you often need a 2nd routine to turn a light off. You can also use virtual switches like a variable, but again you might need another routine.

You are currently allowed to have 1000 automations, so needing a 2nd or 3rd routine shouldn’t case you to run out of automations.

1 Like

The logic that is in the code is far too complex for ST Routines due to the dependencies on each other. I tried that once using virtual switches and I got to perhaps 70% of the logic. I’m really looking for an alternative to Groovy that allows for full flexibility.

Have you tried SharpTools?

1 Like

No, haven’t tried anything other than ST Routines, IFTTT and Groovy. Didn’t like IFTTT at all - was just too slow and too simply.

Is SharpTools very powerful?

Is there a platform that makes use of the Rest API and has a visual editor to have a speedy development, but with the ability to go into coding where necessary?

SharpTools is a great tool in the same class as webcore. Light years above IFTTT.


I had a go with SharpTools, but hit a dead end. How can you compare the creation time of the current State of two devices. In Groovy I did this:
def motiontime = (now() - motion1.currentState(“motion”).rawDateCreated.time+10000)/1000
def doortime = (now() - sensor1.currentState(“contact”).rawDateCreated.time)/1000
if (motiontime<doortime) {

} else {



I would post your question on the SharpTools Forum.

SharpTools Community

1 Like

The timestamps are not exposed directly on the ‘state’ of devices, but it is available on the events that are received (unofficially/undocumented). It’s a bit of an advanced use of expressions, so bear with me on the explanation. You could setup rules that trigger off the motion or door and then snapshot the timestamp to a variable.

Shown above is an example showing the use of an expression to set a variable with the timestamp of the event. It wasn’t clear if your trigger was the door or the motion (or both) that causes the comparison to be evaluated, but you could adapt the rule to fit your needs and add in the comparison wherever makes sense for your use case.

Note that the timestamps are ISO Strings with quotes around them (eg. JSON Strings), so we can then parse that into a date/time value and compare the values directly. Assuming each of the variables was already initialized with an ISO timestamp string, here’s what that might look like in an expression:


Thanks for the explanation. Very helpful. I’m going to try this, but because I have to create all those rules for every single room separately, converting the Groovy code into SharpTools will be a nightmare to setup, maintain and trobuleshoot.

Samsung has changed it’s direction with SmartThings significantly by not offering an equivalent way to Groovy.

  • SmartThings (ex API) on it’s own seems to support very simple setups well.
  • The likes of SharpTools in addition allows for a bit more advanced setups.
  • For “complex” setups, you will have to switch over to API’s which creates a whole new headache to setup an environment on which your code runs let alone how to access it from your phone, etc.

Is that the end of life for SmartThings for people like me - that like to have more advanced setups, easy maintainability, with concerns on security? Is the solution to move over to Hubitat?