Bashio is a bash function library for use with Home Assistant add-ons.
It contains a set of commonly used operations and can be used to be included in add-ons to reduce code duplication across add-ons and therefore making it easier to develop and maintain add-ons.
Main goals:
- Reduce the number of operations needed in add-ons.
- Reduce the amount of code needed in add-ons.
- Make add-on code more readable.
- Providing a trusted and tested code base.
Quicker add-on development, by allowing you to focus on the add-on logic instead of other things.
The library is installed in the Home Assistant Community Add-ons base images and the official Home Assistant base images.
Currently available base images:
- Home Assistant Community Add-ons Alpine Base Image
- Home Assistant Community Add-ons Alpine Python Base Image
- Home Assistant Community Add-ons Debian Base Image
- Home Assistant Community Add-ons Ubuntu Base Image
- Official Home Assistant Alpine Docker Base Image
- Official Home Assistant Alpine Python Docker Base Image
- Official Home Assistant Debian Docker Base Image
- Official Home Assistant Raspbian Docker Base Image
- Official Home Assistant Ubuntu Docker Base Image
Using those images as the base for your Home Assistant add-on will provide this function library out of the box. Our base images are updated frequently and provide the minimal needed base image for a great add-on.
If you want to add Bashio to your own images, please take a look at the Dockerfile of the above base images to see how they are added at build time.
Configuring a Bash script to use the Bashio library is fairly easy. Simply
replace the shebang of your script file, from bash
to bashio
.
Before example:
#!/usr/bin/env bash
set -e
CONFIG_PATH=/data/options.json
USERNAME=$(jq --raw-output '.username // empty' $CONFIG_PATH)
echo "${USERNAME}"
After example with Bashio:
#!/usr/bin/env bashio
USERNAME=$(bashio::config 'username')
bashio::log.info "${USERNAME}"
Bashio has more than 250+ functions available: communicating with the Supervisor API, Have I Been Pwned, file system, logging, configuration handling and a lot more!
The best way to get around would be by looking at the different modules
available in the lib
folder. Each module has its own file, and each
function has been documented inside the codebase.
Furthermore, Bashio is used by the Home Assistant Community Add-ons project, those add-ons will be a great resource of practical examples.
- Some parts of the Supervisor API are not implemented yet.
This repository keeps a change log using GitHub's releases functionality. The format of the log is based on Keep a Changelog.
Releases are based on Semantic Versioning, and use the format
of MAJOR.MINOR.PATCH
. In a nutshell, the version will be incremented
based on the following:
MAJOR
: Incompatible or major changes.MINOR
: Backwards-compatible new features and enhancements.PATCH
: Backwards-compatible bugfixes and package updates.
Got questions?
You have several options to get them answered:
- The Home Assistant Community Add-ons Discord chat server for add-on support and feature requests.
- You could also open an issue here GitHub.
This is an active open-source project. We are always open to people who want to use the code or contribute to it.
We have set up a separate document containing our contribution guidelines.
Thank you for being involved! 😍
The original setup of this repository is by Franck Nijhof.
For a full list of all authors and contributors, check the contributor's page.
MIT License
Copyright (c) 2019-2024 Franck Nijhof
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.