Home Assistant <-> Loxone integration
I was looking for a simple and efficient integration between Home Assistant and Loxone but I couldn’t find one. All I found were integrations using MQTT@Loxberry or ioBroker. I wanted something without these unnecessary layers.
The use cases for such an integration are usually needed for integrations that don’t exist in Loxone and neither in ioBroker/Loxberry (or are hard to use). The following guide is focusing on bi-directional communication of Home Assistant entities called sensors and switches.
Overview
Integration uses Home Assistant’s and Loxone’s REST APIs + some automations. General idea is as follows:
HA -> Loxone
HA automation triggers on a change from one of monitored entities.
The automation send HTTP POST call to Loxone REST API.
It is available for use after being defined as an Virtual Input (using it’s entities name).
Loxone -> HA
Use Virtual Output to HA’s REST API. Using this method you can call any service exposed from HA - for example entity state change or even a script.
Setting up HA -> Loxone integration
Partly based on https://community.home-assistant.io/t/sending-data-from-home-assistant-to-loxone/625396 The general concept is as follows:
Add a rest_command to your
configuration.yaml
to send updates from Home Assistant to Loxonerest_command: update_loxone: url: "http://<LoxoneUser>:<LoxonePassword>@10.0.0.IP/dev/sps/io/{{ parameter }}" method: GET
For each sensor you want to monitor create a Virtual Input. Use a name without domain name, ie.
sensor.sun_radiation
becomessun_radiation
in Loxone's VILoad my blueprint: https://my.home-assistant.io/redirect/blueprint_import/?blueprint_url=https://raw.githubusercontent.com/cayco/dotfiles/master/loxone_inputs.yaml to initiate sending updates
Save the blueprint, and pick
sensors
,binary_sensors
and switches you would like to send to LoxoneUse Loxone’s API to receive changes
For the reverse direction, use Home Assistant’s REST API to receive communication from Loxone’s Virtual Outputs
How it works
For the HA->Loxone communication
You define an automation that runs on every change of the selected entities and calls to Loxone’s official API.
However it runs only if the changed entities are of type: sensor,
binary_sensor
and switch
. If you want to add another type, you should create your own blueprint and add these new types in the filter
. Note, that my blueprint converts on
to 1 and off
to 0. You might need similar conversions for some other exotic/non-compatible with Loxone entities.
For Loxone->HA communication
You define a VO in Loxone and call Home Assistant REST API to communicate.
Setting up Loxone -> HA integration
Create a new Virtual Output with your HA IP as Address
You are going to create HTTP POST request now.
The simplest way is to head to the developers' tools section and using UI select a service and parameters you want to execute
After that, switch to YAML mode and copy everything after the
data:
entryGo to any YAML->JSON converter and past there you parameters, for example https://jsonformatter.org/yaml-to-json
Enter these parameters into "HTTP body for ON or into a Status block (and enter
<v>
into the body field)Command for ON is
/api/services/
+ domain name (replace dot with /, for example:switch/turn_off
)Now you need to get long-lived authorization key from HA. Go to https://my.home-assistant.io/redirect/profile, scroll to the bottom and create a token there
In the "HTTP header for ON" in Loxone paste your token with some necessary wrappings, example:
Authorization: Bearer TOKENTOKEN\r\nContent-Type: application/json
You are going to use this token for all you HA calls
Make sure the HTTP Method for ON is POST and you are NOT selected "Use as Digital Output"
Now, use this VO to pass the value/state to HA
Sometimes you can just call service /api/services/switch/turn_off
with just a { "entity_id": "switch.switch_name }
in the body, however sometimes you need to call it with multiple parameters. Use Status block to prepare JSON for that.
For example, setting both brightness and warmth of a light would require the following body of the REST call:
{
"entity_id": "light.light_name”,
"brightness_pct": <v2>,
"kelvin": <v1>
}
You can get these parameters from Lightning Controller output by decoding the Lumitech DMX type messages like that:
Where formulas for warmth and brightness could be calculate as instructed in this forum post.
Debugging
HA->Loxone
Debugging could be achieved by configuring the a debug level logging for your command in configuration.yaml
like that
logger:
default: warning
logs:
homeassistant.components.rest_command: debug
Loxone->HA
I’m not if there is a better way (I’ve been learning Loxone for a week now) but I define an additional VO to another Linux machine where netcat is run to show me an output of every call on the port it runs. Here, it runs on the 8008 port:
Assuming netcat runs on host 10.0.0.175 you’d set up your VO like that:
Then, use this VO in any Loxone’s flow you’d like to see how it the query is built:
Testing
Sometime you’d need just create your HTTP POST request by hand using curl like that: