Configuring TCP stream and a template

I’m new to home automation stuff and am trying to configure a simple relay for reading and setting IOs.

The device is sending data in the form of a string: A-R|1-5:0-2-2-3-2:0:2-0-0-0-0-0-0-0-0-0-0:1/80/30#255. I don’t know what all the values mean. All I’m interested in is the part :0: which is a 4 bit number, that tells which IO is set.

I can also send a string back with RLCTRL|1-3-0, which sets port 3 to 0.

This is all the configuration I have right now:

sensor relay:
  - platform: tcp
    host: 192.168.180.100
    port: 2001
    payload: ""

This works for reading a raw string.

What I want to know now is how to create a template that can parse the input and set the ports on the device (with switches for example).

I may be wrong but I don’t think what you are doing is valid. I couldn’t find anything in the docs about this component. “sensor relay” . What component are you trying to use? Maybe post the link.

Thanks for the reply.

“relay” is supposed to be just a name or id of some sort (as far as I understand). It works if you write just sensor. Important is that the platform is TCP.

I’ve managed to split the value and put it as a separate group.
Can someone help me, how can I put switches in this group and send a value to the sensor regarding the toggled switch?
This is the part of configuration dealing with the sensor:

group:
####GROUPS
  environment:
    name: Relay
    entities:
      - sensor.relay

sensor:
  - platform: tcp
    name: relay
    host: 192.168.180.100
    port: 2001
    payload: ""
    value_template: "{{ value.split(':')[2] }}"