Most of this thread was about Dobiss integration and I thought that it would be good to have a new post with a clearer title on this topic.
I have an old Dobiss SX domotica system in my house with an IP interface module attached to it.
My goal: get the ability to control my lights and dimmers from within Home Assistant.
The config I ended up with, is an optimized version of the config from @pergola.fabio which was described here.
The following is part of my configuration.yaml:
Shell commands:
shell_command:
dobiss: bash /config/python_scripts/dobiss.sh {{module}} {{id}} {{power}}
update_light_state: "curl -k -X POST -H \"Authorization: Bearer \"{{bearer}}\"\" -d '{\"state\": \"{{power}}\",\"attributes\": {\"brightness\": \"{{brightness}}\",\"assumed_state\": true, \"supported_features\": 1}}' http://192.168.1.52:8123/api/states/light.{{api}}"
- dobiss: this is used to control the lights (on/off/level) – you’ll find the content of this script below
- update_light_state: this is used to update the light state on my dashboard immediately after I change a light state from within Home Assistant
Sensor:
sensor:
- platform: command_line
command: 'python3 /config/python_scripts/dobissreceive.py'
name: dobiss
scan_interval: 15
This sensor polls my Dobiss system every 15 seconds. The purpose of this is to update the state of each light in Dobiss in case a physical switch is used to control a light. – you’ll find the content of this script below
Input number:
input_number:
living_spots_salon:
name: Living Spots salon
initial: 0
min: 0
max: 255
step: 1
This input number is used for the lamps which are dimmable. In the config below you’ll see that we recalculate this number to a value which works for Dobiss (0 - 90 in steps of 10):
- From Home Assistant => Dobiss we calculate from 255 to 90
- From Dobiss to Home Assistant we calculate it the other way around => from 90 to 255
Light:
light:
- platform: template
lights:
slaapkamer_jongens_spots:
friendly_name: Slaapkamer jongens Spots
value_template: "{{ states.sensor.dobiss.state[0:2] != '00' }}"
turn_on:
- service: shell_command.dobiss
data_template:
module: 41
id: 00
power: 01
- service: shell_command.update_light_state
data_template:
bearer: !secret dobiss_state_bearer
power: "on"
api: "slaapkamer_jongens_spots"
turn_off:
- service: shell_command.dobiss
data_template:
module: 41
id: 00
power: 00
- service: shell_command.update_light_state
data_template:
bearer: !secret dobiss_state_bearer
power: "off"
api: "slaapkamer_jongens_spots"
living_spots_salon:
friendly_name: Living Spots salon
value_template: "{{ states.sensor.dobiss.state[64:66] != '00' }}"
level_template: "{{ ( states.sensor.dobiss.state[64:66] | int(base=16) / 90 * 255 ) | int }}"
turn_on:
- service: input_number.set_value
data:
entity_id: input_number.living_spots_salon
value: 255
- service: shell_command.dobiss
data_template:
module: 44
id: 01
power: 01
- service: shell_command.update_light_state
data_template:
bearer: !secret dobiss_state_bearer
power: "on"
api: "living_spots_salon"
turn_off:
- service: input_number.set_value
data:
entity_id: input_number.living_spots_salon
value: 0
- service: shell_command.dobiss
data_template:
module: 44
id: 01
power: 00
- service: shell_command.update_light_state
data_template:
bearer: !secret dobiss_state_bearer
power: "off"
api: "living_spots_salon"
set_level:
- service: input_number.set_value
data_template:
entity_id: input_number.living_spots_salon
value: "{{ brightness }}"
- service: shell_command.dobiss
data_template:
module: 44
id: 01
power: "{{ '%02.f'%((((states.input_number.living_spots_salon.state | float / 255 ) * 90) // 10) * 10) }}"
- service: shell_command.update_light_state
data_template:
bearer: !secret dobiss_state_bearer
power: "on"
brightness: "{{ states.input_number.living_spots_salon }}"
api: "living_spots_salon"
And here are the scripts I’ve used.
Script dobiss.sh
#!/bin/bash
#dobiss 43 01 01 => dobiss: bash /config/dobiss.sh {{module}} {{id}} {{power}}
echo -e "\xED\x43\x31\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xAF\xAF\x"$1"\x"$2"\x"$3"" | nc 192.168.1.9 1001
Script dobissreceive.py:
#!/usr/bin/python3
import socket
import codecs
import binascii
# IP of the Dobiss IP interface
host = '192.168.1.9'
port = 1001
mySocket = socket.socket()
mySocket.connect((host,port))
# Max 24 lights can be polled with one command. Syntax is {{module}}{{id}} e.g. 4100: module 41 light 00
message = binascii.a2b_hex ("ED63300000000000000000000000AFAF4100410141024103410441054106410741084109410A410B420042014202420342044205420642074300430143024303")
mySocket.send(message)
data = mySocket.recv(1024)
data = binascii.hexlify(data).decode()
message2 = binascii.a2b_hex ("ED63300000000000000000000000AFAF430443054306430743084309430A44004401440244034404440544064407450045014502450346004601460246034604")
mySocket.send(message2)
data2 = mySocket.recv(1024)
data2 = binascii.hexlify(data2).decode()
message3 = binascii.a2b_hex ("ED63300000000000000000000000AFAF460546064607FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF")
mySocket.send(message3)
data3 = mySocket.recv(1024)
data3 = binascii.hexlify(data3).decode()
# Only the first 48 chars of a return value are relevant, so we skip the rest.
data_combined = data[0:48] + data2[0:48] + data3[0:48]
# Store the result in the sensor. Each light represents 2 chars in hex format
# It can be 00 (off), 01 (on) or a value from 10 - 90 (in hex)
print (data_combined)
mySocket.close()
I have 51 lights in my house (they are grouped already in the Dobiss). So I’ve created a config generator in Google Sheets to be able to easily generate and update my config. It looks like this:
Hope this helps!