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 Sending data from Home Assistant to Loxone The general concept is as follows:

  1. Add a rest_command to your configuration.yaml to send updates from Home Assistant to Loxone

    1. rest_command: update_loxone: url: "http://<LoxoneUser>:<LoxonePassword>@10.0.0.IP/dev/sps/io/{{ parameter }}" method: GET
  2. For each sensor you want to monitor create a Virtual Input. Use a name without domain name, ie. sensor.sun_radiation becomes sun_radiation in Loxone's VI

  3. Load my blueprint: Link to Blueprints: start import – My Home Assistant to initiate sending updates

  4. Save the blueprint, and pick sensors, binary_sensors and switches you would like to send to Loxone

  5. Use Loxone’s API to receive changes

  6. 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

  1. Create a new Virtual Output with your HA IP as Address

  2. You are going to create HTTP POST request now. 

    1. The simplest way is to head to the developers' tools section and using UI select a service and parameters you want to execute

      1.  

    2. After that, switch to YAML mode and copy everything after the data: entry

      1.  

    3. Go to any YAML->JSON converter and past there you parameters, for example YAML to JSON Converter Online

    4. Enter these parameters into "HTTP body for ON or into a Status block (and enter <v> into the body field)

      1.  

    5. Command for ON is /api/services/ + domain name (replace dot with /, for example: switch/turn_off)

    6. Now you need to get long-lived authorization key from HA. Go to Link to User profile – My Home Assistant, scroll to the bottom and create a token there

    7. In the "HTTP header for ON" in Loxone paste your token with some necessary wrappings, example: Authorization: Bearer TOKENTOKEN\r\nContent-Type: application/json

    8. You are going to use this token for all you HA calls

    9. Make sure the HTTP Method for ON is POST and you are NOT selected "Use as Digital Output"

  3. 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: