What is it? It's a bot for Discord Servers. The bot is able to control your Home Assistant entities and report states.
What can it do? The bot is equipped with the following features:
- Report entity state
- Control entities (later version)
- Report events
- Hook into automations
First, you must create a Discord integration (called an "application") to allow your bot to interface with your Discord server.
- Visit the Discord Developer Portal
- Create a
New Application
, give it any name you'd like - In the application settings screen, select
OAuth2
from the side-nav - Check the box next to
Bot
in theScopes
field. Copy the link this has generated into your browser, and authenticate the bot to your desired server. At this point you will see the bot user join your server. - Now, select
Bot
from the sidebar - Click
Add Bot
(Yes do it
) - Copy the
Token
from theBot
settings screen. Save this token.
Congratulations! You've completed the Discord setup!
Add this repository to your HassIO add-on store:
- Copy the repository URL (
https://github.com/nwilging/hass-discord-bot
) - Login to Home Assistant, select
Hass.io
from the sidebar (orSupervisor
for HassIOversion > 0.150.0
) - Select
Add-on Store
tab - Paste the repository URL into the
Add new repository by URL
input box and clickADD
- Now you may install the add-on.
The only configuration needed is the discord_token
. Once installed, setup your config as follows
(an example should be generated for you):
{
"discord_token": "<your discord token from the steps above>",
"named_entities": ["// We will talk about these later!"],
}
Click Save
. Now the bot is ready to run! Click Start
to start the service, scroll towards the
bottom of the page and Refresh
the log to show the startup output. This will be useful for debugging
issues. A successful startup log looks similar to:
Starting HassIO Discord Bot...
Loaded 0 named entities.
HTTP Server started
Logged in as test-bot#1234!
Congratulations, you've completed the bot setup!
The bot may be invoked with !bot
. It will ignore all other messages, all commands should be
prefixed with !bot
.
The state
command can be used to report the current state of entities in Home Assistant. It
requires 1 argument, entity_id
.
Usage
!bot state light.living_room_light
Named entities allow you to assign aliases to Home Assistant's already confusing (but consistent
and usable!) name generation. The named_entities
field in the configuration of the add-on is
an array or objects, which define a named entity.
The syntax of a single named entity object is:
{
"alias": "<desired alias for entity>",
"name": "<a human-readable name for the entity, as it will display in Discord>",
"entity": "<the entity's ID from Home Assistant>"
}
An example named entity may be:
{
"alias": "door.front",
"name": "Front Door",
"entity": "sensor.front_door_sensor"
}
Named entity aliases serve as "variables" to use in commands to the bot. Using the state
command
and the above example, a command to the bot may look like:
!bot state door.front
This will be interpreted as:
!bot state sensor.front_door_sensor
The bot opens a websocket connection to Home Assistant and subscribes to the following events:
discord_bot.message
You may hook into automations using these events. In the Actions
section of your automation,
select Fire event
for Action type
, add the desired event name to Event
input, and the respective
configuration for the event to Service data
.
When an automation is run, Home Assistant will fire the event you've specified in the actions section of the automation. This event will be picked up by the bot's websocket client and processed accordingly.
Syntax:
{
"message": "<desired message to be sent>",
"channel": "<name of channel to send message to, without #>"
}
Example:
{
"message": "The front door is open.",
"channel": "general"
}