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.

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.yaml file:

# 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 service notify.NOTIFIER_NAME.

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.

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"
    trigger:
      platform: sun
      event: sunset
    action:
      service: 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"
  }
}