Skip to content

Home automation with HubHazard

Posted on: August 31, 2020

background

Most home automation systems are trying to take the user as far from the code as possible. You have to configure everything with buttons and drop-downs. When it comes to simple automations, like if-this-then-that it’s super handy - a couple of clicks and you’re done. This way of creating automations still works in some more complex situations, but when you have to involve variables and nested conditions, it becomes a nightmare. Modifying any of those not-really-complex automations requires a lot of clicking and quite often you can’t even see the whole system at a glance since it exists in several independent pieces.

As a software developer, I get pretty annoyed by the lack of an easy option of creating complex automations with code. I want my smart home to be really smart while staying sane at the same time! That’s where HubHazard comes in.

What is HubHazard?

Basically, HubHazard is a simple Node.js server that allows you to easily write smart home automations using Typescript. It’s targeted towards people with basic programming skills. You don’t have to be a professional developer to use it effectively.

Easy to start with

Just use the ready-made project template, add you configuration file (the template comes with an example file to copy) and you’re ready to automate!

Easy to write automations

Adding an automation to your smart home shouldn’t be a hassle and that’s why HubHazard is allowing you to write an automation as a simple class:

@Injectable()
export class BasicAutomation extends Automation {
// Each automation needs to have a unique name
readonly name = "Basic automation";
// Register trigger that will execute this automation every 15 seconds
readonly triggers = [TimerTrigger.every(15, "seconds")];
// Handle the timer event
async handleEvent() {
console.log("Hey! I was triggered!");
}
}

Easy local hosting

Every smart home enthusiast wants their home to remain smart even when there’s no internet connection. Most automation services rely on the cloud and when there’s no connection, nothing works. [HubHazard][https://github.com/hubhazard/core] solves this problem by being built on the Node.js platform. It’s extremely easy to host on devices like the $5 Raspberry Pi Zero W. This way you can communicate with your hub directly. No more high latency and internet-dependent automations.

Safety of Typescript

The usage of Typescript in the HubHazard instead of plain Javascript allows for a familiar coding experience (for JS devs) but with lots of safeguards protecting you from making mistakes. In addition, all modern IDEs will provide code suggestions, so there’s less of a need to search for things in [the documentation][https://github.com/hubhazard/core/wiki].

Modular design

The HubHazard server is built using the Nest.js framework. This allows you to create your own modules that can extend the functionality of the server. If you want to integrate a different hub other than the Hubitat hub, go ahead and use the ready-made HubHazard module template!

Why does it exist?

Throughout my journey of building a smart home, I used many different solutions to automate things. Each one of them had some problem, that in my case was considered a big problem:

All I wanted was a user-friendly way of writing automations using a popular programming language. I also wanted the automations to be executed locally. I ended up with the Hubitat Elevation hub and created the HubHazard server.

Now everything is running locally, fast and exists in the form of a versionable Typescript codebase.

Up next

In the next article I’ll explain how to start with HubHazard in minutes using the HubHazard Basic Template.

👍 6 likes on dev.to 👍 be the first one to comment on dev.to