#Discord as an assist chat

1 messages · Page 1 of 1 (latest)

kindred quartz
#

would it be possible to use Discord private chat/server with a bot to use it as like an assistant chat?
i know there's an integration to get messages/notifications from HA, but is there a way to send commands from discord to HA?

hollow valley
#

not directly but maybe you could write a discord bot that takes the commands you type and sends them to a webhook which then processes them through the assist pipeline and pushes the output through the discord through the normal integration.

no idea how to go about this in practical terms but as a concept.... maybe it would work?

kindred quartz
#

You can use Discord to send commands to Home Assistant by setting up a Discord bot that connects to your Home Assistant instance through its API or webhooks. Here’s a simple way to do it:

🔧 What You Need:
1. Home Assistant running (you already have this!)
2. A Discord bot
3. Some code (usually in Python) to connect them

🧠 Basic Steps:
1. Create a Discord Bot
• Go to Discord Developer Portal
• Create an application → Add a bot
• Copy the bot token
2. Invite the bot to your server
• Generate an OAuth2 URL with bot permissions
• Use the link to add the bot to your server
3. Write a Python script using discord.py and Home Assistant’s API
Example:

import discord
import requests

TOKEN = 'YOUR_DISCORD_BOT_TOKEN'
HASS_TOKEN = 'YOUR_HOME_ASSISTANT_LONG_LIVED_ACCESS_TOKEN'
HASS_URL = 'http://YOUR_HASS_IP:8123/api/services/light/turn_on'

client = discord.Client()

@client.event
async def on_message(message):
if message.author == client.user:
return

if message.content == '!lighton':
    headers = {
        'Authorization': f'Bearer {HASS_TOKEN}',
        'Content-Type': 'application/json',
    }
    data = {"entity_id": "light.living_room"}
    requests.post(HASS_URL, headers=headers, json=data)
    await message.channel.send("💡 Light turned on!")

client.run(TOKEN)

4.    Run the bot script and test it by typing !lighton in your Discord server
#

.
this is what Chatgpt suggested
what do you think?

hollow valley
#

sure maybe, i havent done it. but its AI code so if it doesnt work then dont be supprised. read up on the documention of all the stuff involved and see if you can put the pieces together

kindred quartz
#

but what he suggesting is to have a python working 24/7 right?

hollow valley
#

yeah you would need whatever is running your bot to be running.
you could maybe write it in a container then run it on HA as an an addon. or even potentially write it as an integration

kindred quartz
hollow valley
#

yeah a python script running a discord bot is not gunna take alot of resources

kindred quartz
hollow valley
kindred quartz
hollow valley
#

addons are just docker containers

kindred quartz
hollow valley
#

it was just a passing suggestion of a possible solution. although a custom_integration might also run the way you need to also

#

or run it on another system

kindred quartz
#

damn

hollow valley
#

it was just a possible suggestion

kindred quartz
#

because the home assistant bot i already add it, as i use it for the itnegrations

kindred quartz