The smart bot to the rescue to automate tedious tasks around your home
Installation is easy:
poetry install --no-dev
# Run a shell in the virtualenv
poetry shell
Any homebot configuration is real python code which can be linted, tested, highlighted and many more
like any other python code. In comparison to other configuration formats - for example yaml configurations -
it is easy to spot errors cause your IDE (like PyCharm) will highlight errors.
By now homebot only supports slack to listen for messages from users.
You need to setup a bot account in slack (documentation will follow).
Create a python file (I will call it run.py) and paste the following content into it:
from homebot import (
AssetManager,
Flow,
Orchestrator,
actions,
formatter as fmt,
listener,
processors
)
assets = AssetManager()
# Secrets
SLACK_TOKEN = assets.secret('slack_token')
slack_action = actions.slack.SendMessage(token=SLACK_TOKEN)
help_processor = processors.Help()
listener = listener.slack.DirectMention(token=SLACK_TOKEN)
flows = [
Flow(
processor=processors.Error(),
formatters=[fmt.StringFormat(
"Processing of `{ctx.incoming}` failed: `{payload.error_message}`\n"
"```{payload.trace}```"
)],
actions=[slack_action]
),
Flow(
processor=processors.UnknownCommand(),
formatters=[fmt.StringFormat(
f"Command is invalid: `{{payload.command}}`. Try `{help_processor.command}`."
)],
actions=[slack_action]
),
Flow(
processor=processors.Version(),
formatters=[
fmt.StringFormat("Homebot version `{payload}` is up and running...")
],
actions=[slack_action]
),
Flow(
processor=help_processor,
formatters=[fmt.help.TextTable(), fmt.slack.Codify()],
actions=[slack_action]
)
]
orchestra = Orchestrator(listener, flows)
This setups a bot that is able to handle errors (processors.Error), unknown commands from the user (processors.UnknownCommand()),
provide a help / usage message to slack channel (processors.Help) and can show the current version (processors.Version).
After that you can call
# If you did not name it run.py change it to suit your needs!
python homebot run run.py
to run homebot.
Go to your slack workspace where the bot is installed, invite the bot to a channel and try out the different commands:
# Remark: <botname> is the name of your bot. Replace to suit your needs
# Show the help / usage page of your bot
@<botname> help
# Show the current version of homebot
@<botname> version
TBD
TBD
docker run -it --rm \
-v `pwd`/configs/complex:/config \
-e HASS_URI=${HASS_URI} \
-e HASS_TOKEN=${HASS_TOKEN} \
-e SLACK_TOKEN=${SLACK_TOKEN} \
-e SLACK_BOT_ID=${SLACK_BOT_ID} \
hazard/homebot:0.1.1
Content type
Image
Digest
Size
136.8 MB
Last updated
over 6 years ago
docker pull hazard/homebot:develop-arm