There are two distinct options for hosting your Automation as a SmartApp: AWS Lambda and Webhook. The best hosting option for your Automation depends on a number of factors, both objective and subjective. Below, we look at a few general guidelines to help you choose the appropriate hosting solution.
Before hosting your own Automation, be sure to check out Rules. When all services and Device features involved in a Rule are local, Rules execute locally on a Hub, allowing you to benefit from greater speed, stability, and security than cloud-reliant solutions.
AWS Lambda is one of the simplest ways to self-host an Automation if the language support and tooling AWS offers adequately supports your development efforts.
Lambda Use Cases
Lambda is better suited for latency-tolerant Automations, such as asynchronous data processing or scheduled actions where multiple-second latency is acceptable.
Examples of latency-tolerant Automations where Lambda may be an ideal solution include:
- Most scheduled actions, such as scheduled device executions
- Data processing applications
- Aggregating device usage in a unique way to display later
- Keeping a custom log of when certain doors are accessed, etc.
Lambda is ever-changing as advancements in the underlying technologies are made, and typical times for cold starts and when they will happen in customers' workloads is not always known. For an official AWS definition of what a cold start is and how it may affect different application patterns, see Operating Lambda: Performance optimization – Part 1.
SmartThings enforces a 10 second execution request timeout. If you find your Automation is approaching or exceeding this threshold, you may need to utilize Lambda optimization strategies, or switch to a Webhook server that can provide lower latency.
A Webhook SmartApp is an HTTP server that accepts and responds to callbacks from SmartThings. In some circumstances, this solution involves more setup and configuration at the benefit of flexibility in programming languages, developer tooling, and several code-hosting options.
Webhook Use Cases
Webhook is better suited for actions based on real-time events or other latency sensitive Automations where milliseconds matter.
Examples of latency sensitive Automations where Webhook may be an ideal option include:
- Controlling devices based on real-time events
- Open Close Lighting Control (trivial example that is best implemented as a Rule based Automation)
- Security/safety related notifications
Webhook SmartApp implementations do not have to be limited to only cloud provider hosting, they only need to be publicly reachable. Something as small as a Raspberry Pi can offer a low-cost solution to hosting your solutions locally.
- Regardless of which hosting solution you choose, consider your location when configuring. If using a cloud provider like AWS, select a region that will provide the lowest latency for your Automation.
- Look closely at hosting provider terms to ensure their usage tiers match your application appropriately.