Home Assistant
Home Assistant is an open source platform for home automation. It provides integrations with many devices and supports a Home Assistent Rest API for reading and setting parameters. You can use homeassistant as a gateway to integrations that are supported by this platform.
Web service
To install homeassistant on your local cluster run:
mkdir homeassistant
cd homeassistant
curl -O https://raw.githubusercontent.com/axxem/spacetime/main/docker/homeassistant/docker-compose.yml
docker compose up -d
Make sure that the file config/configuration.yaml contains the following settings:
http:
use_x_forwarded_for: true
trusted_proxies:
- 172.25.0.0/16 # Docker network range
- 127.0.0.1
Configuration
Open a web browser to http://[IP_ADDRESS]:8123 where the IP_ADDRESS is the the address of the server where kubernetes is installed. Follow the onboarding procedure. Go to the user profile and create a long lived access token.
Secret
Create a secret with name 'Homeassistant' and the following fields:
| field | value |
|---|---|
| type | script |
| token | [TOKEN] |
| script | Homeassistant |
Script
Create a script with a get and set function that calls the Home Assistant REST API.
The Home Assistant API can be accessed via the name of the service in the cluster homeassistant.
const get = async (object, context) => {
let options = {
url: 'http://homeassistant:8123/api/states/' + object,
headers: {
'Authorization': 'Bearer ' + context.token
}
}
let response = await fetch(options.url, options);
let data = await response.json()
return data
}
const set = async (object, value, context) => {
let options = {
url: 'http://homeassistant:8123/api/services/climate/set_temperature',
method: 'POST',
body: JSON.stringify({"entity_id" : object, "temperature": value, "hvac_mode": "heat"}),
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer ' + context.token,
}
}
let response = await fetch(options.url,options);
let data = await response.json()
return data
}
Connector
Create a connector with name Homeassistant and data source Homeassistant. To read temperature from an object in Homeassistant with entity_id climate.zone1, add the following object mapping:
| topic | value |
|---|---|
| home.hvac | climate.zone1 |
To read the temperature setting and actual temperature add the following key mapping:
| key | value |
|---|---|
| thermostat | attributes.temperature |
| temperature | attributes.current_temperature |