Dobiss lights integration

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!

1 Like

how did you get the dobiss ids? and states?
with Wireshark or based upon max tool?

As is this is more focused on the dobiss integration … I think I have support for toggling lights on/off for SX Evolution as well as Ambiance PRO in dobiss2mqtt. But dimming is not yet available. If toggling on/off works then I will add dimming next.

Can someone test ? But as said in the other thread. Best to add just 1 module and the first output on it in order to test if it works. This way it does not add a bunch of devices as long as we are testing. Also, it’ll be easier to see what’s going wrong if you add the DEBUG=* env variable on your docker container.

Check the example config. Make sure to set the interface to ‘SXEVOLUTION’ as well. And I don’t think it’ll matter if the module type is a relay or a dimmer. Finally, I think this can co-exist with your current dobiss integration. As dobiss2mqtt is no longer hogging the socket.

I used maxtool for it

Ok, I’ll try it out in next week

ok trying out your docker, but i am unable to start it, i receie this error, is it maybe because its not loading the config.js file? i am not 100% familiar with dockers, but i am using portainer for it on my HassOS

my volume binding is as follow
path in container : /data
host volume : /mnt/data/supervisor/homeassistant/dobiss2mqtt (this is my local path, dobiss2mqtt is a folder within my /config folder, yeah, the path string is correct, i know because it also works for another custom container i use in portainer
but i am unsure, to i need to bind a folder? or the file? i have also tried this :

path in container : /data/config.js
host volume : /mnt/data/supervisor/homeassistant/dobiss2mqtt/config.js

but always have error below:

> Error: Cannot find module '/app/dist/index.js'
> 
> 
>     at Function.Module._resolveFilename (internal/modules/cjs/loader.js:980:15)
> 
> 
>     at Function.Module._load (internal/modules/cjs/loader.js:862:27)
> 
> 
>     at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)
> 
> 
>     at internal/main/run_main_module.js:17:47 {
> 
> 
>   code: 'MODULE_NOT_FOUND',
> 
> 
>   requireStack: []
> 
> 
> }
> 
> 
> npm ERR! code ELIFECYCLE
> 
> 
> npm ERR! errno 1
> 
> 
> npm ERR! [email protected] start:prod: `NODE_ENV=production node ./dist/index.js`
> 
> 
> npm ERR! Exit status 1
> 
> 
> 
> 
>  
> 
> 
> npm ERR! Failed at the [email protected] start:prod script.
> 
> 
> npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
> 
> 
> npm ERR! A complete log of this run can be found in:
> 
> 
> npm ERR!     /root/.npm/_logs/2020-03-01T19_20_06_496Z-debug.log

I have the same issue apparently. Odd. I’ll look into it asap.

ow ok :slight_smile:
but is my mapping correct? i just need to map the data folder, not the config.js file right?

just the data folder should be mapped. and a config.js file should be inside it.

ok it’s working again. typescript was outputting the build differently from before.

indeed, for sx evoltuin, my number should be 41 here? instead of 1

            // Either manually set the number of the relay or let dobiss2mqtt set the number automatically
            // depending on the order if the module in the array.
            number: 1,

no it’s 1. just first module. A -> 1. Probably should document it better :slight_smile:
edit: the protocol maps it to the correct number to send to dobiss

ah , because on ambiance pro the relays are starting at address 1
but on evolution, they start on 41 …

Correct. 0x41. It should handle it automatically. But make sure to set ‘SXEVOLUTION’ as the interface in your config. Then this file will be used. https://github.com/SpoBo/dobiss2mqtt/blob/8259008738966b9d13e69c8082c2675e29202635/src/protocols/SX.ts as you can see on line 34 it adds 64. which is 0x40. I don’t think the number should be a problem. But something else might be.

ok, it works! :slight_smile: configured it as number 1

allthough there is a delay on the state of the light, the state only updates like 4-5 sec later, maybe its because of this in log:

(node:18) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 message listeners added to [MqttClient]. Use emitter.setMaxListeners() to increase limit


[Error [TimeoutError]: Timeout has occurred] {


  message: 'Timeout has occurred',


  name: 'TimeoutError'

Hmzzz it’s not working properly I think. Can you set DEBUG=* as an environment variable on the docker container ? And maybe give me a log of what’s going on ?

ok, log is huge, uploaded it here on dropbox

i also renamed a light to test “TESTberging” , somewhere in log you also see i turned on/off that light

ah wait, is it maybe bevause its polling to many outputs? i only have 5 , you have 6 defined here:
it it polling them all ? if you just define number = 1 ?

            "nachthal",
            "office",
            "fitness",
            "traphal",
            "zolder_1",
            "zolder_2",

Yes it polls all outputs defined on every module/relay. But it sends a single message per module.

It’s actually working as intended. It could be that due to the other polling mechanism working at the same time that messages collide and that it sometimes does not respond that quickly. When a single socket messages fails to come back it will wait 5s, crash. wait 5 more seconds and then restart the whole chain.

I’m interested to see if your other modules like your dimmers also turn on / off. If so all I have to do is add brightness controls to it and map it to mqtt.

Also, you can modify the polling interval if the default of 1s is a bit too much.

And if you want to check the logging but have less of it you can disable parts of it. DEBUG=*,-dobiss2mqtt.mqtt,-dobiss2mqtt.socket for example will drop all loglines that start with dobiss2mqtt.mqtt and dobiss2mqtt.socket.

I also notice you have the same behavior as me where it says “error This socket has been ended by the other party,”. I’d like to solve this too. Perhaps this is also part of the delay. For me though it’s quite fast.

ok, gonna play with it, and remove all relays except 1
seems also, after a HA restart when the docker is off, the light entitys still excist? i had to remove them manually, they were all “unavaible” offcourse
why are they retaining?

also, what i dont understand, you have defined those 6 relays , it also creates lights for those? but they are not actually lights? is just a name of the module right?

            "nachthal",
            "office",
            "fitness",
            "traphal",
            "zolder_1",
            "zolder_2",