Azure Service Bus

The Azure Service Bus integration allows you to send messages to Azure Service Bus from within Home Assistant.

First-time setup

This assumes you already have an Azure account. Otherwise, create a free account here.

You need to create a Service Bus namespace; you can follow this guide.

You must then create a Shared Access Policy for the Service Bus with Send claims or use the RootManageAccessKey from your namespace (this key has additional claims, including managing the event hub and listening, which are not needed for this purpose), for more details on the security of Service Bus go here. Alternatively you can create a dedicated key for only one queue or topic, to restrict access to only that queue or topic.

Once you have the connection string with Send policy, you can set up the integration itself.

Important

The queue or topic that you are sending to needs to exists with the service bus namespace before you use it within Home Assistant. See here for how to set up a queue and here for setting up a topic and subscriptions.

Configuration

Add the following lines to your configuration.yamlThe configuration.yaml file is the main configuration file for Home Assistant. It lists the integrations to be loaded and their specific configurations. In some cases, the configuration needs to be edited manually directly in the configuration.yaml file. Most integrations can be configured in the UI. [Learn more] file. After changing the configuration.yamlThe configuration.yaml file is the main configuration file for Home Assistant. It lists the integrations to be loaded and their specific configurations. In some cases, the configuration needs to be edited manually directly in the configuration.yaml file. Most integrations can be configured in the UI. [Learn more] file, restart Home Assistant to apply the changes. The integration is now shown on the integrations page under Settings > Devices & services. Its entities are listed on the integration card itself and on the Entities tab.

# Example configuration.yaml entry
notify:
  - platform: azure_service_bus
    connection_string: !secret servicebus_connection_string
    topic: t-test
  - platform: azure_service_bus
    connection_string: !secret servicebus_connection_string
    queue: q-test

Configuration Variables

name string (Optional, default: notify)

Setting the optional parameter name allows multiple notifiers to be created. The notifier will bind to the notify.NOTIFIER_NAME action.

connection_string string Required

Connection string found in the Azure portal, with send claim in the key.

queue string (Exclusive)

Which queue to send notifications on.

topic string (Exclusive)

Which topic to send notifications on.

Tip

If you plan to send all state changes from one or more entities within Home Assistant, you should consider using the Azure Event Hub integration instead.

Usage

The notification service will translate the data given to a JSON object on the service bus. The message field will always be set, but the fields target and title are optional and are only included in the service bus message if set. Any input given in the data section, will be flattened to the root of the JSON object and follow the structure given. All input given in the data section will be included in the message.

See the example below for how an automation trigger translates to a message on the service bus.

automation:
  - alias: "Sunset Service Bus message"
    triggers:
      - trigger: sun
        event: sunset
    actions:
      - action: notify.test_queue
        data:
          message: "Sun is going down"
          title: "Good evening"
          data:
            sun_direction: "Down"
            custom_field: 123
            custom_object:
              trigger_more: true
              explain: "It's starting to get dark"

The message that can be retrieved from a queue or topic subscription:

{
  "message": "Sun is going down",
  "title": "Good evening",
  "sun_direction": "Down",
  "custom_field": 123,
  "custom_object": {
    "trigger_more": true,
    "explain": "It's starting to get dark"
  }
}