https://www.home-assistant.io/, the docs https://www.home-assistant.io/docs/ and the forum https://community.home-assistant.io/
When having dedicated Raspberry device for Home Assistant follow guides as https://www.home-assistant.io/installation/raspberrypi/ and get directly a Raspberry Home Assistant SD card image. This way gets the Home Assistant Operating System.
If an abbreviation for home assistant is used, please use ha and not hass. in German hass means hate and home assistant is something to love ;)
It is also possible to install Home Assistant OS in Virtual Box.
See https://www.home-assistant.io/installation/linux/ after it is installed virtual box starts showing a text console running the Home Assistant CLI (a console line interface). when typing login the prompt changes to the linux root. localectl status and localectl set-keymap de_CH-latin1 to get swiss german key map. exit bring back the ha> prompt. host shutdown shuts down Home Assistant in the proper smooth way.
It also tells to use http://homeassistant.local:8123 and http://homeassistant.local:4357/
If the Raspberry is serving primary for other purposes than Home Assistant then Home Assistant can be added and installed in a container https://www.home-assistant.io/installation/
Home Assistant Operating System will come with the App Store, allowing to install additional supported applications to the Home Assistant OS.
Home Assistant in a container makes use of the running host system. It does not come with the App Store but the additional applications (and any other application) can be installed the host system using its package manager.
See https://www.home-assistant.io/installation/alternative/#install-home-assistant-container or https://www.home-assistant.io/installation/raspberrypi-other. There are different container solutions but the guide focuses on docker. Docker must be first installed
Running home assistant in docker works well, however soon other docker container applications as MQTT mosquitto, go2rtc or EspHome are desired to be used as well.
Therefor it is recommended to run HomeAssistant with docker-compose https://www.linurs.org/linux/Docker.html#docker%20compose
Before starting the installing it decide for:
Time Zone TZ=<Europe/Zurich>
Path where the home assistant docker configuration goes as /opt/docker/homeassistant.
Then create this directory sudo mkdir -p /opt/docker/homeassistant
Give permission for the local user
sudo chown -R $(id -u):$(id -g) /opt/docker/homeassistant
docker run -d --name homeassistant --privileged --restart=unless-stopped -e TZ=Europe/Zurich -v /opt/docker/homeassistant:/config -v /run/dbus:/run/dbus:ro --network=host ghcr.io/home-assistant/home-assistant:stable
If successful docker starts and since home-assistant docker container is not on the local machine it gets downloaded from docker hub and this takes a while.
--network=host makes that the local machines IP address can be used and not the docker one showed by sudo ifconfig
docker ps -a shows if homeassistant is running.
For automatically startup a systemd file needs to be created: sudo touch /etc/systemd/system/homeassistant.service
[Unit] Description=Home Assistant Container Requires=docker.service After=docker.service [Service] Type=oneshot RemainAfterExit=yes WorkingDirectory=/opt/docker/homeassistant ExecStart=/usr/bin/docker run -d --name homeassistant --privileged --restart=unless-stopped -e TZ=Europe/Zurich -v /opt/docker/homeassistant:/config -v /run/dbus:/run/dbus:ro --network=host ghcr.io/home-assistant/home-assistant:stable ExecStop=/usr/bin/docker stop -t 60 homeassistant ExecStopPost=/usr/bin/docker rm -f homeassistant [Install] WantedBy=multi-user.target
docker ps -a check if docker still runs homeassistant
docker stop homeassistant stop it
docker rm homeassistant remove temporary files
sudo systemctl daemon-reload make the system aware of the new service
sudo systemctl enable homeassistant.service tell it to start it automatically next boot
sudo systemctl start homeassistant.service start it manually
sudo systemctl status homeassistant.service check its status
sudo journalctl -u homeassistant.service -f check its log
to update homeassistant
Stop the service sudo systemctl stop homeassistant.service
get the update docker pull ghcr.io/home-assistant/home-assistant:stable it will also tell if there is an update
docker rm homeassistant remove temporary files
sudo systemctl start homeassistant.service start it again
HACS contains not yet released features and can be installed with: https://www.hacs.xyz/docs/use/
cd <path to homeassistants container directory>/ subdirectory where docker-compose.yml is
sudo wget -O - https://get.hacs.xyz | sudo bash -
To get <path to homeassistants container directory>/custom_components/hacs
Restart Home Assistant docker compose down && docker compose up -d and add the HACS integration and follow the authorization procedure
A HACS command appears in the sidebar.
Installing HACS Integration follow the steps go to HACS serach and download the Integration. The Homeassistant asks to restart it. After that add the Integration as it would be no HACS integration. The installation will ask for the configuration data as username and password if required.
With HACS installed the WebRTC Camera integration is available can can be installed. WebRTC is used among go2RTC the media stream server that can be run as docker application.
It then pops up among the other official integrations (where not much can be configured).
A WebRTC Camera card can be added to the dashboard to show live video streams with relatively slow delay. Add as url the go2rtc stream name.
HACS contains Easee EV Charger. Read the instructions from HACS that also point to links as https://github.com/nordicopen/easee_hass/wiki
When adding the Easee EV Charger Integration, password and username of the Easee account are requested. After this a list of all Easee stations appears where the ones of interest can be selected
Those configuration steps take some time.
,
Once installed, it can be accessed as http://<ip address>:8123
There is also an app available for mobile devices
Some terms to know
Integrations are ways to communicate to devices or protocols
Entity ID are identifiers of states to be exchanged. States are values as on or off, or a numeric value and can be seen as data. State changes can be used in triggers as events to be processed.
Helpers can take their data from everywhere including Home Assistant User Interface. So helpers do not need hardware. Helpers can count
Dashboards can be created holding Cards and the cards hold Entities. There is also the Grid Card that holds other Cards and allows therefore to group Cards.
Scripts are as automations but do not have triggers. Scripts have therefore be used in automations.
Scenes allow to send actions to multiple devices instead of sending actions to multiple times to individual devices
Blueprints are automation templates and scripts to not need ti start from zero
Tags are NFC or QR tags that can be used as triggers
Sensors are entities that provide a value
A switch can provide its value but can also be toggled, it is therefore bi-directional
A light is like a switch but has additional functionality, as brightness and RGB color
/home/homeassistant/.homeassistant hold the data including yaml files
Automations is the logic added to Home Assistant that takes inputs or events and controls outputs or actions. It is what Home Assistant does automatically. Automations have triggers.
Automations can be created and edited via the gui or yaml.
Some evolution is going on how to write the yaml code and unfortunately it can look very different between new HA and old HA setups. Backward compatibility might work. Gui will create yaml in the actual version.
If it gets complicated then the logic can be moved into python code and have it communicate to HA using MQTT
The following are older yaml code examples:
Turn on an output of a tasmota device at 8 o'clock:
alias: Tasmota Switch On at 20:00
description: Turn on switch.tasmota2 at 20:00
trigger:
- platform: time
at: "20:00:00"
action:
- service: switch.turn_on
target:
entity_id: switch.tasmota2
data: {}
Or turn it on at sunset:
alias: Tasmota Switch On at sunset
description: Turn on switch.tasmota2 at sunset
trigger:
- platform: sun
event: sunset
offset: "0"
condition: []
action:
- service: switch.turn_on
target:
entity_id: switch.tasmota2
data: {}
mode: single
And a humidity alarm:
alias: Humidity Alarm Bathroom On
description: Humidity is above level
trigger:
- platform: numeric_state
entity_id: sensor.shellyplusuni_a0a3b36865f4_humidity
above: 45
condition: []
action:
- type: turn_on
device_id: f9ecf0bcd602949c51a780527ac19b57
entity_id: switch.shellyplusuni_a0a3b36865f4_switch_0
domain: switch
mode: single
Make sure the MQTT integration is working and setup. Then add the Tasmota integration to home assistant.
Device discovery does not work anymore for Tasmota
Use the GUI of the Tasmota device and setup its MQTT setting
Shelly's https://www.shelly.com/ appear as WLAN servers creating their own network and have ip addresses as http://192.168.33.1
The first step is using a WLAN capable PC and check for available WLAN networks as SSID: Shelly1PMMiniG3-<number> . Then connect to the network. After this open a browser with http://192.168.33.1 and the Shelly's device web page appears
Now configure the WLAN settings so it uses the same network as the home assistant device. A static address can be set to have a defined IP address. Then enable the network to have now the Shelly accessible to home assistant and it stops blinking its red LED. It however stays also in its SSID: Shelly1PMMiniG3-<number> using http://192.168.33.1. Everybody could connect to it, so it is a cyber security issue, set a user name and password and to be more safe disable the shelly's access point feature. This however has the risk that a factory reset might be required in the future, if password or user names will be lost or if the WLAN home network changes.
Enable access point when modifying something on the WLAN home network. If it goes wrong then the Shelly can be accessed otherwise a factory reset is required.
Factory resets could be done by pressing the buttons on the shelly's for longer than 10s or if no button is present by multiple quick power on off cycles.
Since it is now connected to the Internet it is time to check for firmware updates.
The Shelly has lot of functions and features to configure and operate itself without using home assistant. If using home assistant, it needs therefore be taken care that no interference between the home assistant and the local Shelly configuration occurs.
The Shelly and home assistant must communicate themselves using one out of the many protocols available. However both must use and understand the same protocol.
Many Shelly's are directly found by Home Assistant and will be directly integrated in its GUI.
However some Shelly's as Generation 3 are not detected yet and can be used by defining their protocol. One common protocol (not just for Shelly's) is MQTT. If not having Home assistant OS or Supervised then a MQTT broker is missing so sudo apt install mosquitto mosquitto-clients and configure mosquitto.
If it is discovered automatically check the IP address. If the address is a wireguard address then ignore the device and add a OctoPrint device with the local private network address
When adding the OctoPrint device to Home assistant then the OctoPrintes user name needs to be entered and OctoPrint started. OctoPrint then asks to grant the connection.
There are different implementations for webcams in OctoPrint. OctoPrint tries to use them but not to set them up. Therefore the Webcam can use the Home Assistant MJPEG IP Camera Integration using a stream as http://<ip>:8080/stream. The Picture Entity Card can then be used to show the camera stream.
Add the time & date integration then add the clock card in a dashboard.
To get date add again time & date integration and select now date add an entity card to show it.
Selecting AM or 24 is done in the user setting
To see day of the week add a Markdown card with:
type: markdown
content: |
## {{ now().strftime('%A') }}
The GUI has its limits for configuration especially when integrations are missing or generic communication protocols are used. In this case the configuration file is usually in /home/homeassistant/.homeassistant/configuration.yaml needs to be edited.
If working in a console work as user home assistant:
sudo -u homeassistant -H -s
In Home Assistant Gui Developer Tools CHECK CONFIGURATION https://www.home-assistant.io/common-tasks/core/#configuration-check or source /srv/homeassistant/bin/activate and hass --script check_config
For new items a restart is necessary after that modifications need just a YAML reload, click an green tick should appear.
To get a modular configuration configuration.yaml can includes other yaml files. To move out the mqtt stuff in a separate mqtt.yaml file add to configuration.yaml
mqtt: !include mqtt.yaml
then create the mqtt.yaml without repeating mqtt again:
sensor:
- name: "raspi_soc_temperature"
state_topic: "raspi/soc/temperature"
Friendly names are names put in quotes *This is a friendly name" and are written as a human would do. To be come computer readable it is converted in lowercase with underscore names having a prefix as sensor.and are then used as entity ID: sensor.this_is_a_friendly_name
It is assumed that a MQTT broker as mosquitto is running and configured in Home Assistant running.
When running mosquitto in a docker container it must be able to communicate with homeassistant. One way of doing this is setting in docker-compose.yml
network_mode: host
then it can be accessed under 127.0.0.1.
For password less communication in a local LAN anonymous must bee set in mosquitto.conf
listener 1883 allow_anonymous true persistence true persistence_location /mosquitto/data/ log_dest file /mosquitto/log/mosquitto.log
To test that subscribed MQTT arrive, a MQTT message needs to be published.
If there is no MQTT publisher, create one with a script that reads and publishes the raspberries SoC temperature.
If mosquitto is installed as regular application requiring a password create and run the script:
#! /bin/bash mosquitto_pub \ -t "raspi/soc/temperature" \ -m "$(/usr/bin/vcgencmd measure_temp | sed -E 's/temp=([0-9]+\.[0-9]+).*/\1/')" -u<username>-P<password>
Having a published MQTT message, check in an other console that subscribing is working:
mosquitto_sub -t "raspi/soc/temperature" -u <username> -P <password>
If mosquitto runs in docker use the following commands to publish:
/usr/bin/docker exec mosquitto mosquitto_pub -h localhost -t "raspi/soc/temperature" -m "$(/usr/bin/vcgencmd measure_temp | sed -E "s/temp=([0-9]+\.[0-9]+).*/\1/")"
and to subscribe:
/usr/bin/docker exec mosquitto mosquitto_sub -t "raspi/soc/temp erature"
sed is used to just get the numerical value.
The script could be added to cron:
*/15 * * * * /opt/RaspiTemperature/raspitemp.sh
or to see cron error messages:
*/15 * * * * /opt/RaspiTemperature/raspitemp.sh >> /tmp/raspitemp-cron.log 2>&1
Now edit ha-config/configuration.yaml
mqtt:
sensor:
- name: "raspi_soc_temperature"
state_topic: "raspi/soc/temperature"
In Home Assistant -> Developer Tools -> CHECK CONFIGURATION and reload the or all YAML
A new entity sensor.raspi_soc_temperature should now appear and can be used as in a sensor card.
The payload might be json instead of single data. For every data structured in Json a separate MQTT entry must be done, some data is nested so the path needs to be included. The entries would look as:
sensor:
- name: "raspi_soc_temperature"
state_topic: "raspi/soc/temperature"
- name: "raspi_manager_battery_soc"
state_topic: "raspi/manager"
value_template: "{{ value_json['battery' ].soc }}"
- name: "raspi_manager_power"
state_topic: "raspi/manager"
value_template: "{{ value_json.power }}"
Shelly Mini1PMG3 is not yet directly supported in Home Assistant and has a rather complicated payload to be turned on. Everything is therefore be packed into payload_on and payload_off
switch:
- name: "mini1pmg3"
command_topic: "shelly1pmminig3-5432044f7414/rpc"
payload_on: '{"id": 1, "src": "hass", "method":"Switch.Set", "params":{"id":0,"on":true}}'
payload_off: '{"id": 1, "src": "hass", "method":"Switch.Set", "params":{"id":0,"on":false}}'
retain: false
There is no state_topic and value_template therefore it works just in the publishing direction. To have mosquitto know the payload in case the Shelly Mini1PMG3 is powered off and will be powered on later retain: true must be set.
To have a switch bidirectional, a state_topic must be added, since the switch status is inside json a value_template is required and since the state data is different from command data, state_on and state_off is defined. To work it well during power on an off retain is set to true:
switch:
- name: "mini1pmg3"
command_topic: "shelly1pmminig3-5432044f7414/rpc"
payload_on: '{"id": 1, "src": "hass", "method":"Switch.Set", "params":{"id":0,"on":true}}'
payload_off: '{"id": 1, "src": "hass", "method":"Switch.Set", "params":{"id":0,"on":false}}'
retain: true
state_topic: "shelly1pmminig3-5432044f7414/status/switch:0"
value_template: "{{ value_json.output }}"
state_on: true
state_off: false
There are more then on way to do something in Home Assistant, this might be a source of confusion.
Templates allow a more generic way and are flexible way to handle things. Publishing MQTT topics is also possible within a template section:
template:
- button:
- name: "MQTT Button 1"
press:
service: mqtt.publish
data:
topic: "object_detection/switch"
payload: 1
- name: "MQTT Button 2"
press:
service: mqtt.publish
data:
topic: "object_detection/switch"
payload: 2
- name: "MQTT Button 3"
press:
service: mqtt.publish
data:
topic: "object_detection/switch"
payload: 3.
Results from command line calls can be used as entities by adding to configuration.yaml
command_line:
- sensor:
name: "Raspberry Pi CPU Temperature"
unique_id: rpi_cpu_temperature
command: "cat /sys/class/thermal/thermal_zone0/temp"
scan_interval: 60
unit_of_measurement: "°C"
value_template: "{{ (value | float / 1000) | round(1) }}"
The same entities can be appear in two forms:
"Camera 1 Raw" as used in the GUI and configuration.yaml
sensor.camera1_raw as used in the dashboard cards
Give it a unique id so the gui editor can find it and handle the connection between the different forms.
One way is to put a MAC address in the identifier to assure it stays unique
unique_id: "raspi4_soc_temp-e45f016dc555"
If applicable give a unit to the value
unit_of_measurement: "W"
Dashboards are the ones appearing in the main window of homeassistant, The list of dashboards appear in the sidebar. Via Settings > Dashboards they can be managed and new dashboards added. Some dashboards as Overview are build in, others are user added.
Dashboards can be edited with the GUI but also as YAML.
Dashboards can have views that are like tabs. This prevents to have too many dashboards listed on the sidebar
Dashboards have view layouts how they place the cards on it (Section, Masonry), so it adapts to any screen size.
Masonry puts cards side by side. If a row is full the next card will be placed underneath the shortest card.
Sections, has sections that hold a group of cards, the sections are then added sequentially on the screen.
An other way is using cards that can contain other cards, as the grid card or the HACS Layout Card (that must be downloaded and installed first). This gives better control how to place the cards but might not work well if different screens are used.
Cards can be added to dashboards.
The grid card helps how to put cards on a dashboard. The dashboard will just see the grid card and not its contents. The cards are put side by side to the grid card until all columns are full then it starts with a new row. It allows cards to spawn multiple columns
Home Assistant is shown as a web page. Web pages can have Java Scripts and those JavaScripts can be debugged the regular way using a featured web browser.
Create the Javascript config/www/hello-card.js
class HelloCard extends HTMLElement {
setConfig(config) {
this.config = config;
this.innerHTML = `<ha-card header="Hello Card">
<div style="padding: 16px;">Hello World!</div>
</ha-card>`;
}
set hass(hass) {
// will be called on each state-update
}
getCardSize() {
return 1;
}
}
customElements.define("hello-card", HelloCard);
In Settings Dashboard add as resource /local/hello-card.js
Using a YAML of manual card Home Assistant will be aware of such scripts and runs them.
type: custom:hello-card entity: sensor.elevator_position min: 1 max: 10
If entities are used in the card they need to be added and can have a restriction as min and max
If the the subdirectory www had to be create manually it might be save fails.
Check http:// if it finds and open the file. If not Home Assistant is not aware about the directory and a restart might solve the issue.<hostname>:8123/local/hello-card.js
The tag <div> inserts HTML code into the manual card inside the Home Assistant page.
Instead of simple text svg xml code can be added.
It is available via Settings > Voice Assistant and allows to enter commands via voice.
Add assistant gives it a name and configures it as for the languages spoken. It appears then in the menu and can be set as being the preferred.
There is also the offer to get the cloud service that also offers connection to Google Assistant and Amazon Alexa.
For first tests just the written sentences must be understood, so language to speech and speech to language can be left empty.
In settings > Developer Tools > Assist is a Sentence parser, Enter a command like: Go to 3 a YAML file is created but HomeAssistant is juts guessing what to do with this voice command and this is probably not want is desired
In automations the trigger "when a sentence is said" can be set. And for test the action "Set conversation response" with a text (without {{....}} template).
Triggers can understand sentences with variables as: Go to {floor} and "Set conversation response" with "sent to {{ trigger.slots.floor }}"
Instead a "Set conversation response" action a "MQTT publish" action can be defined with its topic and payload {{ trigger.slots.floor }}
Linux Voice Assistant LVA https://github.com/OHF-Voice/linux-voice-assistant (replaced wyoming) is the listener and passing forward part it supports also wake-words and obviously deals with the microphone and speaker.
Kiosk mode means converting a PC's full featured graphical desktop into a simple touch screen.
First decide on portrait or landscape mode and then remove the on screen keyboard.
Test Font sizes and probably set a dark theme.
Both the browser chromium and home assistant need to use their kiosk mode.
Once header and sidebar are turned off they can almost not be turned on again. Therefore create a home assistant Kiosk user so just the Kiosk user will have no header and sidebar.
Restrict the Kiosk user rights as no administrator and login just from local network. The kiosk mode affects individual dashboards. So if something goes wrong select an other dashboard showing the header and sidebar.
Open chromium http://<hostname or IP>:8123 without kiosk option and log in as Kiosk user.
Make sure "keep me logged in" is selected
chromium --kiosk http://<hostname or IP>:8123 will open in kiosk mode. If something goes wrong Alt + F4 will exit.
http:// from a remote computer and ssh will still work as usual. so pkill chromium will terminate as well<hostname or IP>:8123
To have it started after power up add to ~/.config/labwc/autostart (try first without --kiosk, --password-store=basic prevents popping up the keyring authentication window and --user-data-dir will move the chomium Kiosk data as cookies, cache away from the regular users data)
# Chromium starten sleep 30 chromium \ --user-data-dir=/home/<username>/.config/chromium-kiosk \ --password-store=basic \ --kiosk \ http://<IP or hostname of home assistant>:8123 &
Sleep 30 seconds sleep is added to give time since home assistant must run before chromium accesses it.
The next step is putting home assistant in Kiosk mode to hide the header and side bars. Install Kiosk Mode from HACS and restart home assistant.
Go to Settings and select the desired dashboard to be put in kiosk mode then click on Raw configuration editor and put on top of the yaml code:
kiosk_mode:
user_settings:
- users:
- Kiosk
hide_sidebar: true
hide_header: true
Now refresh the browser, header and side bar should have been gone.
Having one dashboard in Kiosk mode is probably not enough a button to open an other dashboard might be desired.
Add a button card to the dashboard to open the map dashbord. Enter to yaml:
type: button name: Map icon: mdi:map tap_action: action: navigate navigation_path: /map/0
/map/0 is the path as shown in the url when opening the map dashboard
A accepted e-mail server as gmail needs to be used and a user e-mail address and application password must be created.
Add the SMPT integration and configure it with; sender e-mail, sender name, host as smtp.gmail.com, port, connection security, username and application password
And finally add an automation to automations.yaml:
alias: Raspberry Pi SoC Temperature Warning
description: Notification too high SoC temperature
triggers:
- trigger: numeric_state
entity_id: sensor.raspi_soc_temperature
above: 78
for:
minutes: 15
conditions: []
actions:
- action: notify.send_message
target:
entity_id: notify.gmail_urs_linurs_org
data:
title: ⚠️ Raspberry Pi Temperature high
message: >
SoC-Temperature is {{ states('sensor.raspi_soc_temperature')
}}°C
mode: single
The id must be unique and sensor.raspi_soc_temperature must be the proper existing entity name
Backup can be configured to go to the local device. During the configuration an encryption key is generated. The backup is therefore encrypted since it contains sensitive data as for authentications.
There are multiple places to show, create and export the key. Some places create a new key and therefore a previous key and its backup using it might be lost.
The backup goes to the config/backups directory that is if docker is user put as volume in its persistent location.
Via Settings System Backup the backup can be downloaded to a remote computer but requires the encryption key. The downloaded backup will be unencrypted so store it on a safe place. The backup contains the home assistant config directory.
Everything persistent created is defined in docker-compose.yml it is the config directory of home assistant. So create a copy or even put it under git.
Remember the current running version of the Homeassistant core and its frontend. If the update goes bad then adding the version to docker-compose.yml will bring back the previous version
Create a home assistant backup or copy everything under the persistent docker volume that points to the config directory to a safe place.
cd <to directory of docker-compose.yml> and docker compose pull homeassistant gets new version of just home assistant and not all the other containers inside docker-compose.yml
docker compose up -d homeassistant does the update
HACS needs to be updated separately. HACS itself and the HACS components as it integrations.
Now repeat the same for the other containers listed in docker-compose.yml