TCP commands for Ethernet relay

my dimmer was the most difficult part, to also actua read the dimmer state, seems dobiss works HEX , and also fro 00 … 90 , brightness value, and HA uses 0 … 255

sounds great on you do this! I believe we can make the GUI better with HA, touch is limited and the system should be able to do more, the electricity consumtion is the same and computers need to work :slight_smile:
this is mine, where can i download maxtool?

seems your tools is the exact as maxtool, you dont need maxtool :slightly_smiling_face:

you can see the relais and output also, so if you want to change “stopcontact inkom”, send “410000” and “4100001” to turn on/off that one so , 41 s relays 1 , 00 is the first output , 00 / 01 is on/off

i changed my code a lot btw, so all replys above in this thread is changed, i made it now “easier”, still a lot though, but i dont have shell commands anymore for every light/switch … just 1 variable shell command now

1 Like

tricky HEX and DEC - but now we know - thanks for sharing

Always room to improve of course, can i have a copy as example and for review - coz now i don’t have a clue :smiley:
what modules should i install from HA?

when this is done i’m more than happy to share my code, so other can do the same or even improve mine :slight_smile:
what do you do with the ‘component the sun’…?

looking forward!

yeah, read this thread carefull, sometimes you need hex, sometimes you need dec, somtimes it starts with 00 , moods start with 01 :slight_smile:
its trial and error
sun: , well, automations , if sun goes down, i turn on some leds for example, control my screens , if its like windy, i do close my covers … just some cool stuff :slight_smile:
i will post my new config later, maybe also usefull for @freezeke

ok, here is my config, its a lot, probably you need to read it 10 x times :slight_smile:

so the because you can controll lights/switch outside HA? i wanted to know also the state of a light/switch/cover in my HA offcours,
thats why i poll every 10 secs my dobiss, so i can change the value_template

#sensor
  - platform: command_line
    command: shell_command.dobissreceive-
    name: prog
    scan_interval: 15

=>
dobissreceive-: python3 /config/python_scripts/dobissreceive.py

as you can see, i send to messages, the string is limited, so at the end i have 1 sensor, that contains everything in my house
the second string the ffffff… , is not used, but you need to send it, it needs complete bits, also the begin part is also the same : ED63300000000000000000000000AFAF
then it begins like 4205 , 420a , … so 42 is relays B in my case, 05 is the 6th output, as you can see work in hex here!!
so i will receive 00 or 01 if something is on / off
so now you already know states of lights/dimmers/covers/ …

in the .py file:

#!/usr/bin/python3
import socket
import codecs
import binascii

host = '192.168.0.10'
port = 1001
message = binascii.a2b_hex ("ED63300000000000000000000000AFAF4205420a410041014102410341044105410B42024304430A430B4408440943074306440A4500450145024503410A4106")

mySocket = socket.socket()
mySocket.connect((host,port))
mySocket.send(message)

data = mySocket.recv(1024)
data = binascii.hexlify(data).decode()

message2 = binascii.a2b_hex ("ED63300000000000000000000000AFAF42084207420943004206420442034400440144024403440444054406440743084309430243034305FFFFFFFFFFFFFFFF")
mySocket.send(message2)

data2 = mySocket.recv(1024)
data2 = binascii.hexlify(data2).decode()

print (data + '--' + data2)


mySocket.close()

second part, easy part, control a light/switch :


- platform: template
  lights:
         
    keukeneiland:
      friendly_name: "Keuken Eiland"
      value_template: "{{ states.sensor.prog.state[12:14] == '01' }}"
      turn_on:
        - service: shell_command.dobiss
          data_template:
            module: 41
            id: 04
            power: 01
        - service: shell_command.dobiss_state
          data_template:
            power: "on"
            name: "Keuken Eiland"
            icon: "mdi:lightbulb-on"
            api: "light.keukeneiland"
      turn_off:
        - service: shell_command.dobiss
          data_template:
            module: 41
            id: 04
            power: 00
        - service: shell_command.dobiss_state
          data_template:
            power: "off"
            name: "Keuken Eiland"
            icon: "mdi:lightbulb-on"
            api: "light.keukeneiland"

you see, when i turn on a light, i send 2 services
1 service is a shell_command, this is new, i made variables, here, so every light/switch code looks the same, only the module/id/power values change here…
so the shell_command.dobiss looks like :

=>
dobiss: bash /config/python_scripts/dobiss.sh {{module}} {{id}} {{power}}

my bash script looks like, notice the $1 , $2 , $3 , those are my variables

#!/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.0.10 1001

so this should now turn on a light :slight_smile:
for my second service, you see i do a curl, this is optional, if you dont do it, your light icon will only be changed aftre 10 seconds, base on the state sensorso i do a curl, so i change the icon instantly
also here i work now with variables, before i had for every light a shellcommand
so dobiss_state looks like :

dobiss_state: "curl -k -X POST -H \"Authorization: Bearer YOURBEARERHERE\" -d '{\"state\": \"{{power}}\",\"attributes\": {\"assumed_state\": true,\"friendly_name\": \"{{name}}\",\"icon\": \"{{icon}}\"}}' https://127.0.0.1:8123/api/states/{{api}}"

now, you also see a value template, this is is needed if you control a light outside HA, so when 10 sec scan_interval passes, this will change the light icon also
so if => [12:14] == ‘01’ => means character 12 to 14 , are 2 decimals, in that string you see in the sensor, if its 00 , light s off, if its 01 , light is on

second part, dimmers, not gonna comment here, just look at my code :slight_smile:


    dimmer1:
      friendly_name: "Eethoek Raam"
      value_template: "{{ states.sensor.prog.state[36:38] != '00' }}" 
      level_template: "{{ ( states('sensor.Prog')[36:38] | int(base=16) / 90 * 255 ) | int }}"

      turn_on:
        - service: input_number.set_value
          data:
            entity_id: input_number.dimmer1
            value: 255
        - service: shell_command.dimmer1
        - service: shell_command.state_dimmer1_on
      turn_off:
        - service: input_number.set_value
          data:
            entity_id: input_number.dimmer1
            value: 0
        - service: shell_command.dimmer1
        - service: shell_command.state_dimmer1_off
      set_level:
        - service: input_number.set_value
          data_template:
            entity_id: input_number.dimmer1
            value: "{{ brightness }}"
        - service: shell_command.dimmer1
        - service: shell_command.state_dimmer1_on
#shell commands:		
dimmer1: python3 /config/python_scripts/dimmer.py {{ '%02.f'%((((states('input_number.dimmer1') | float / 255 ) * 90) // 10) * 10) }}		
state_dimmer1_on: "curl  -k -X POST -H \"Authorization: Bearer BEARERHERE\" -d '{\"state\": \"on\",\"attributes\": {\"brightness\": {{states('input_number.dimmer1')}}, \"assumed_state\": true,\"friendly_name\": \"Eethoek Raam\",\"icon\": \"mdi:spotlight\", \"supported_features\": 1}}' https://127.0.0.1:8123/api/states/light.dimmer1"
state_dimmer1_off: "curl  -k -X POST -H \"Authorization: Bearer BEARERHERE\" -d '{\"state\": \"off\",\"attributes\": {\"assumed_state\": true,\"friendly_name\": \"Eethoek Raam\",\"icon\": \"mdi:spotlight\", \"supported_features\": 1}}' https://127.0.0.1:8123/api/states/light.dimmer1"
#python file dimmer.py
#!/usr/bin/python3
import socket
import codecs
import binascii
import sys
## python3 dimmer.py 00-03 00-90
host = '192.168.0.10'
port = 1001
message = "ED43310000000000000000000000AFAF4510" + sys.argv[2]
string = binascii.a2b_hex (message)
mySocket = socket.socket()
mySocket.connect((host,port))
mySocket.send(string)
mySocket.close()
#input number
dimmer1:
    name: Eethoek Raam
    initial: 0
    min: 0
    max: 255
    step: 1

now, last part , screens/covers

- platform: template
  covers:
    google_eetkamer:
      friendly_name: Eetkamer
      value_template: "{{ is_state('input_boolean.eetkamer', 'on' ) }}"
      open_cover:
        - service: cover.open_cover
          entity_id: cover.eetkamer
      close_cover:
        - service: cover.close_cover
          entity_id: cover.eetkamer
      stop_cover:
        - service: cover.stop_cover
          entity_id: cover.eetkamer
		  
- platform: command_line
  covers:
    cover1:
      friendly_name: Eetkamer
      command_open: shell_command.screen1_open
      command_close: shell_command.screen1_close
      command_stop: shell_command.screens_stop
	  
#shell command
screen1_open: echo -e "\xED\x43\x31\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xAF\xAF\x53\x13\x01" | nc 192.168.0.10 1001
screen1_close: echo -e "\xED\x43\x31\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xAF\xAF\x53\x14\x01" | nc 192.168.0.10 1001
screen2_open: echo -e "\xED\x43\x31\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xAF\xAF\x53\x15\x01" | nc 192.168.0.10 1001

#input boolean, to remeber the state after a HA restart !!


input_boolean:
  eetkamer:
    name: Eetkamer
1 Like

wauw cool - thanks for sharing keep you posted on the progress!

good luck, its a lot of trial and error, especially with the id’s and stuff

tip, just try some TCP commands directly from SSH terminal , like light on /off
also play with the python file, to get the state of all your lights, then you see in SSH also the output

1 Like

Ow , and if you have ventilation, I control that too, I have like 3 modes, easy, normal, turbo, I just send a tcp mood command

1 Like

Not yet - Belgium was not build in one day :joy:

New house?

Wow Fabio, a completely new approach :smiley:
is this to reduce the load on the dobiss controller?

No , it’s just easier to copy paste lights/switches in the yaml files, only change relay id… No more shell/state commands anymore just 1… Easier to understand :wink:

For covers, that’s indeed new, I had stateless covers, now created statefull covers…

I have everything exposed to Google home assistant, so Google home app know the state of dobiss lights/covers now

Only for dimmers I still have separate shell commands, need to convert them also to 1

OK, cool stuff
Trying to understand here:

I change in my config to

#sensor
  - platform: command_line
    command: shell_command.dobissreceive-
    name: prog
    scan_interval: 15

And replace the dobissreive.py in config/python_scripts?
Rebuild the lights.yaml and for the bash script you lost me :upside_down_face:

yes, that sensors is still a pytjon script i run that stays the same

for the bash script (.sh) file, well, before, i had for every light, 2 shell commands, so 20 lights => 40 shell commands … and even more

now just 1 , i pass the arguments directly from the template light itsell, into the bash script

No I even had 4 shell commands for a light… :wink: 2 for the state and 2 for on/off…
I think I have about 30 lights, I had like 120 shell commands :wink: , now 2 for my whole system

That’s a big reduction of lines :+1:
So the dobissreceive.py can have the same name and is that bash script also in config/python_scripts?
Such as dobiss.sh.yaml or dobiss.sh.py

No, the bash script is bash, it’s not a python file…
I has extension .sh :wink:

Yeah, I placed it in the python folder, doesn’t mather where it is…
But if you enable also python_script: in your config, you can actually call a python script, directly from a service, so no need for a shell command anymore…
So even less code, that’s for next time :wink:
But that’s why I already have that python folder already…

Yes, I already enabled python_script in the main config, I have a date_countdown.py in the python scripts folder. I use it for birthdays and the most important date : our wedding date that I never forget again :smiley: