Automate Home Assistant with WebHooks
Tags: webhooks, automated, automation, programming
Published: 2023-12-28 10:48:55

---
title: Automate Home Assistant with WebHooks
published: true
date: 2023-12-27 20:20:50 UTC
tags: Webhooks,Automated,Automation,Programming
canonical_url: https://blog.disane.dev/en/automate-home-assistant-with-webhooks/
---

 ![Automate Home Assistant with WebHooks](https://blog.disane.dev/content/images/2023/12/automate_home-assistant-with-webhooks_banner-6.jpeg)

If you use Home Assistant, you have usually already created many things or devices in Home Assistant. However, there are some use cases where you want to carry out automations (and corresponding actions) in Home Assistant, but these are not triggered by Home Assistant itself. This is where WebHooks come into play.

## What are webhooks

In essence, webhooks are nothing more than API endpoints. You can find out exactly what API endpoints are in my introduction to REST APIs 👇

[

Understanding and using REST APIs

APIs: Ubiquitous and everyone uses them , albeit directly. But what are they for and how do they work? We explain 💡

 ![Automate Home Assistant with WebHooks](https://blog.disane.dev/content/images/size/w256h256/2023/11/--D---Logo-Black.png)Disane.dev - Personal tech blogMarco Franke

 ![Automate Home Assistant with WebHooks](https://blog.disane.dev/content/images/2023/11/rest_api-standard-erklart_banner-1.jpeg)
](https://blog.disane.dev/rest-api-standard-erklart/)

These defined endpoints are provided by systems, in this case Home Assistant, and (usually) expect a predefined structure.

So we can pass data to a system and feed the other system with data or indicate that an action has just been performed.

I myself use such a WebHook in n8n (I have already [written an article](https://blog.disane.dev/n8n-unleashed/) on this) to send a notification to my cell phone via Home Assistant when I publish a new blog article. Since I plan many articles in advance, it's always nice to see that an article has been posted.

## How are WebHooks defined in Home Assistant?

In Home Assistant, it's quite easy to define WebHooks. All we need to do is create a new automation and select "Webhook" as the entry point.

![Automate Home Assistant with WebHooks](https://blog.disane.dev/content/images/2023/12/image.png)

Each of these WebHooks is then given a fixed ID with which it can be accessed. With Home Assistant, the WebHooks are always specified as `POST` or `PUT`, so that data can also be transferred there. A `GET` would have the disadvantage that you can only deliver data via the query string.

This means that we could access our WebHook as follows:

```
POST https://homeassistant.local/api/webhook/-mNLpFGdHRSK0fhJIFDEOydyM
```

If we now fire the request with cURL, we will see our request in the automation processes:

![Automate Home Assistant with WebHooks](https://blog.disane.dev/content/images/2023/12/image-1.png)

If we also provide it with data as `JSON` in the `body`, we will also see this:

![Automate Home Assistant with WebHooks](https://blog.disane.dev/content/images/2023/12/image-2.png)
_Transferring the data to the WebHook in Postman_

![Automate Home Assistant with WebHooks](https://blog.disane.dev/content/images/2023/12/image-3.png)
_Received data in Home Assistant_

In the automation itself, we have our data in the trigger. In a Home Assistant template, we can access it with `{{ trigger.json }}`.

💡

I will come back to how exactly this works with the templates in Home Assistant in a later article. At this point, however, I would like to refer you to the documentation on [Templating](https://www.home-assistant.io/docs/configuration/templating/?ref=blog.disane.dev).

We can then use this data to fire a notification in Home Assistant, for example:

```
service: notify.notify
data:
  title: Post published 📑
  message: "'{{ trigger.json.name }}' published"

```

And that's your first WebHook written and ready for use.  
  
Cheers 🤙