One man’s “simple solution” is another’s “complex solution”…
Folks who know me, know that I started the “[Capability Types Suggestions](https://community.smartthings.com/c/developers/new-capability-types)
” Category of the Forum (and, I’m somewhat disappointed it is so quiet after some initial interest … ).
Anyhow, even if something doesn’t become an official new Capability, I find it helpful to see if “concept” can be framed as a Capability … and we can even try to agree on the standard.
So…
#capability Schedule Driver: “capability.scheduleDriver
”
Description: A Device or Service that provides an alternative, reliable implementation of the Scheduling features of SmartThings. Not sure yet whether it should implement all or just some of the features.
Still very roughly…
###Attributes
scheduleName
- stringscheduleList [ scheduleName : string; scheduleType : type; signalName: string, scheduleDetails : cron string or a single datetime ]
signalName
- string; Equivalent to themethod
parameter ofrunIn(seconds, method, options)
(and others).
###Commands
-
schDriver.signalIn(seconds, signalName, [overwrite: true, false])
-
schDriver.signalOnce(dateTime, signalName, [overwrite: true, false]
) -
schDriver.signalOnScheduleDaily(time, signalName)
-
schDriver.signalOnScheduleCron(
cronExpression
, signalName)
-
schDriver.signalEvery5,10,15,30,Minutes(signalName)
-
schDriver.signalEvery1,3,Hours(signalName)
-
schDriver.unscheduleSignal(signalName, [regexp: false, true])
(If regexp is used, this can be quick way to unschedule a whole bunch of stuff like the nativeunschedule()
method… e.g.,schDriver.unschedule("${spp.id}-*, regexp: true)
) -
any others? Perhaps sunrise/sunset with offset option?
###Usage
-
SmartApp must request access to a Device Instance with Capability “Schedule Driver”.
-
In place of any of the “replaced” SmartThings scheduling methods:
(a) Use asignalName
instead of directly referring to themethod
(b)signalName
must be unique across all SmartApps that are using the Device Instance, unless the SmartApps are purposefully sharing a scheduled signal. For example, there might as well be two reserved signalNames … “sunrise
” and “sunset
” which are scheduled by a single SmartApp daily, or are built into the Device Type Handler. For schedules not shared between SmartApps, the developer should always use$app.id
as a prefix in thesignalName
; i.e.,myScheduler.signalIn(seconds, "${app.id}-turnOff")
.
(c) Call the desired Device.Command equivalent to the SmartThings Schedule method.
(d) Important: Next you must subscribe to the Specific Device Event that will be sent by the Device per the schedule. This is wheresignalName
gets mapped to themethod
call.
i.e.,subscribe(device, signalName, method)
(e) Ummm… That’s it? Earlier thoughts of having the Device Type Handler directly trigger a Virtual Switch or Virtual Momentary seem unnecessary, and do not fit the Capability/Type paradigm (since a Device cannot directly call the Command of another Device).
###Implementation
As with any Capability, the method of implementation does not matter, as long as it provides the standard Attributes, Commands, and Events described above.
-
The Schedule Driver Device could be implemented via a physical small processor Thing (e.g., Arduino or rPi) using ZigBee or ThingShield to communicate. All that is required of the physical device is a reliable RTC (real time clock), knowledge of the calendar, a cron library, and storage for “many” schedules. – NB: It is possible that the “calendar logic” could all be handled in the DTH and the DTH just convert every scheduled signal request to just “
secondsFromNow
”. Not sure if this is harder or easier; less or more reliable? -
The Schedule Driver Device could be implemented with LAN connected Server or, slightly less reliable and never a candidate for local execution, with a Cloud-Connected Service (and Service Manager).
The Device Type Handler code is the normal abstraction layer between the Device Object and the Device Thing.
-
It could convert Schedules to something simple like “
secondsFromNow
” and then the physical Thing would return a message whenseconds
have elapsed and the DTH then issues asendEvent
-
Especially if served by a Linux server (LAN or Cloud Service), then implementation via a “cron” service or “cron” library seems efficient and almost trivial. The Device Type would just be a “cron-bridge” … or whatever you’d like to call this concept. Messages to the Service would be formatted as either a single datetime strings or a cron string.
-
Calculation of
sunrise
andsunset
could be done, given access to the geo-location, in the DTH, a Service Manager SmartApp, or by the Thing or Service itself. In the latter case, the Commands above should offer scheduling relative (+/- offset) to Sunrise and Sunset.
Well… that’s my draft.
Does it sound crazy? Overdone, underdone, or just-right?
Though we can refine this (or toss it) via discussion, the only way to figure out if this Capability concept is viable is to actually build a Device Type and Thing/Service that implements it … and see if it works!