BLOG
How to Build a Smart Home System with Nerves and Grizzly
In a recent Nerves in Action webinar, Matt Ludwig from SmartRent detailed how his company is leveraging the Elixir/Nerves technology stack to create robust, fault-tolerant, and convenient home automation systems. In particular, Ludwig has spearheaded an effort to develop a library called Grizzly, which allows Nerves devices to use Elixir in order to “speak Z-Wave”. Watch the video recording here:
So what’s Z-Wave? Just like Wi-Fi and Bluetooth, Z-Wave is a machine communication protocol that lets our devices talk to each other. The main difference, however, is that it’s custom-built for smart home systems.
So, before we get into Grizzly itself, let’s get up to speed on Z-Wave.
Z-Wave: A Quick Primer
Developed by Silicon Labs and maintained by the Z-Wave Alliance, this radio communication technology has come a long way since its initial release in 1999. In fact, there are over 100 million Z-Wave devices deployed globally, including over 3,000 unique, certified devices that are made by around 700 different brands.
This brings us to the first main advantage of Z-Wave: interoperability. Any certified Z-Wave device is guaranteed to work out of the box with other Z-Wave devices. This makes it easy to add new devices to your local network by pairing them with your Z-Wave smart home hub and facilitates information sharing across devices.
Speaking of shared data, Z-Wave creates a full mesh network where every smart home device can talk to every other device without having to go through a centralized gateway. Not only does this expand our network’s range, but it also lets us do some really cool stuff, such as automatically turn on the smart lights when we come home and activate smart locks to open the door.
Another advantage of using Z-Wave is increased smart home security. This benefit is twofold: first, by taking our smart devices off the internet, we cut down our attack surface to mitigate the risk of exposing vulnerabilities to an untrusted network, and, second, because Z-Wave uses S2 security, which includes AES-128 encryption, we prevent unauthorized devices from connecting to the Z-Wave LAN.
The last feature of Z-Wave that we want to highlight is the reason it’s so suitable for home IoT in the first place. Its low overheads and low power requirements let us make the most of our constrained resources. Since IoT devices like smart thermostats, smart locks, or smart speakers don’t have as much processing power or batteries as large as those found in laptops, tablets, or even smartphones, we want to keep our protocols as lightweight as we can.
Grizzly: The Perfect Marriage between Z-Wave and Nerves
Very loves Nerves, an Elixir-based platform that’s custom-built for IoT, so it’s no surprise that Grizzly caught our attention. Not only is it built on top of the Phoenix Framework, just like NervesHub, but Grizzly also simplifies the deployment and maintenance of home IoT ecosystems.
The main piece of Grizzly is send_command, where we specify the ID of the node that we want to control, the command we want to issue, and any parameters or options for that command. Here’s an example of the syntax:
When we send a command, we’ll usually get back a report. Similar to an HTTP response, a Grizzly report gives us the status of the device, a confirmation of the command, and any data that we request. If you’re an Elixir developer, the response struct looks like this:
This back-and-forth forms the backbone of Grizzly communications over Z-Wave, and it opens the door to all the options that we can find in the Grizzly “cookbook”, such as adding/removing devices, locking/unlocking doors, switching on/off lights, and much more.
If you’re interested in seeing a live demo of Grizzly in action, check out Matt Ludwig’s hello-home GitHub repository. It’s full of examples for configuring a Z-Wave controller, setting up the mesh network, and running Elixir commands to operate these smart devices.
Conclusion
If you’re excited to learn more about how to build a smart home system, checking out Grizzly is a great place to start. This is one of the main reasons we’re active contributors to open-source software projects like Nerves: when we open the door to free collaboration, we’re able to achieve so much more together.
With Elixir and Nerves as a solid foundation, we’re building a comprehensive IoT ecosystem that takes advantage of diverse technologies, such as Z-Wave, to optimize the Internet of Things for individualized use cases.
Interested in using Nerves in your next IoT project? Find out more about our Nerves development services today.