Hi all,
Firstly, this will be my first post as I’m new to Smartthings, WebCoRE and the smartthings community, so thank you all for welcoming me and thank you all for helping me so much already.
I’ll just add that if I’ve posted this on the wrong place, any admins please feel free to relocate it in the right place.
So, on to the point of my past…
I’m a software engineer and well versed in all things programming so I realise I have a head start when it comes to programming automations and pistons. But as a programmer I find myself wondering how things work behind the scenes so that I can program with an eye on performance, and ease of managing automations.
Therefore I have a few questions, discussion points and comparisons to try and build my own list of ‘best practices’ that may or may not equate to industry standards.
1: lots of small pistons Vs fewer large pistons
Based on previous experience of similar situations in other languages I’ve taken the decision to try and have 1 piston for each input device, which would ‘listen’ to all of the relevent events on that device.
That being said, there is scope to reduce the size (and complexity) of a piston by separating event listeners into multiple ones.
The real question here is, which is best:
A) loads of small pistons, each with code for a particular event listener for a specific device - could be difficult to manage or cross-talk with other events/devices, but should theoretically allow for better performance as fewer lines of code are loaded for each event listener triggered
B) a piston for each device which contains all event listeners for that one device - which I’m leaning towards - probably likely to be the best balance of performance Vs ease of management
C) a piston for each room, floor or function type comprising lots of devices and event listeners in each - performance will likely be bad but should be easier to manage
I wonder if anybody has ever looked at the performance comparison of lots of small pistons vs a few large pistons?
2: polling devices for current States Vs storing current States in global variables [Solved]
In planning and programming my first few automations I’ve found that expected operations can, and do rely on the current state of some other devices.
For instance (simplest example), when clicking a button next to a light - if the light is on, turn it off, if it’s off, turn it on. (I know in this example I could simply ‘toggle’ the light, but this is just a simple example)
My assumptions based on other languages (which I may be completely wrong about) is that it will take longer to ask for the current state of a device (as the request would travel over the internet) Vs asking for the current value of a Boolean variable (which would exist in the same place the piston code).
The real question here is, which is best:
A) within pistons, poll the device for the current state when it’s needed - likely to be slower
B) have a global variable to store the current state of each device, and add pistons to keep those variable matching those device States - will increase the number of pistons needed to keep the variables up to date. And possibly likely to have performance issues from having a lot more event listeners
C) have a global variable to store the current States of a selection of devices (those which we need to poll) - likely to be the best balance between performance of individual pistons Vs overall performance
I wonder if anybody has ever looked at the performance comparison of polling device States Vs polling global variables, and updating those variables?
[Update]
Following @ogiewon s and others comments, I’ve taken the decision to change my pistons to poll/all the current states of the devices themselves instead of sitting the current states in a variable.
It’s been identified that there should be no performance difference between polling the device Vs polling a variable. In fact a benefit of polling the device is that status will be correct even if it is changed by something else (as a posed to variables being cached on piston execution).
[Update end]
3: using scenes Vs using pistons to set multiple device changes
I’ve initially set up scenes, and pistons are deciding which scene to activate based on several queries.
As I said I’m not long into my experience of using smartthings, but one thing I’m aware of is that activating a scene doesn’t seem to allow a gradual change in brightness (yes I realise some light bulbs have that built in but not all bulbs).
This leads me to feel I need to use pistons to change multiple devices, especially where gradual switch on/off is important.
That’s great for automated activations (from timers and device s such as pushing a button), but I still would like the ability to activate these changes via voice (I have Google assistant all around the house). If I can activate a piston from a Google routine (I know I can activate a smartthings scene in this way), that would be great. If I can’t activate a piston from Google routine, I’ll have to also set up a scene and put up with instant on/off when activated via voice.
Does anybody know if a piston can be activated from Google home routines?
4: power outage recovery
So, this last item is around outages. I’ll say that we rarely get power outages, or internet outages. But, my wife is a real technophobe so if something happens that isn’t as expected compared to non-smart operations, it will be noticed.
The main issue that needs to be addressed is light bulbs in the bedroom. If we have a power cut in the middle of the night, we can’t have all the lights go on with no quick or easy way to switch them back off again.
Of course the best and most desired option is that the lights don’t come on at all.
But I appreciate smartthings has no idea that there’s a power cut until the bulb is repowered, and communicates with smartthings so there may be a delay before the light is switched back off.
This of course will also really on the internet connection being re-established.
So here’s my question. I know that webCoRE is executed in the cloud (relying on the internet being re-established), but does anybody know if something exists that would run on the smartthings hub to return bulbs to their original States (or at least turn off the bulbs in the bedrooms)?
So, that’s my (long) first post to the community, I hope that all of my points and questions make sense, if not please feel free to ask.
If anybody has any suggestions or recommendations, please share. And if any of my assumptions are wrong, please correct me.
And once again, thank you all for your help, and welcoming me to the smartthings community.