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.
Web service
If you do not have a running instance of Home Assistant you can deploy one on your cluster.
helm install homeassistant spacetime/homeassistant
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 |