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
Blocker
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.
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.
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.
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?
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 {
ā¦
}
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?