TCP Sensor setup

Hi there,

I want to configure a TCP sensor that reads from a TCP socket and passes on the response to a handful of template sensors that make sense of the hex value. I’ve got this working in JS, but I’m struggling on how to translate this to a TCP sensor.

The following YAML ends in an error: “UnicodeDecodeError: ‘utf-8’ codec can’t decode byte 0xa3 in position 0: invalid start byte

- platform: tcp
  name: g32
  host: socket.ottowildeapp.com
  port: 4502
  timeout: 5
  payload: "{\"channel\":\"LISTEN_TO_GRILL\",\"data\":{\"grillSerialNumber\":\"xxxxxxx\"}}\n"
  value_template: "{{value | unpack(">I") }}"
- platform: template
  sensors:
    g32_t1:
      friendly_name:  g32_t1
      value_template: "{{ int([states('sensor.g32')[12],states('sensor.g32')[13]]|join,0,16) * 10 + int([states('sensor.g32')[14],states('sensor.g32')[15]]|join,0,16) / 10 }}"
      unit_of_measurement: "°C"
    g32_t2:
      friendly_name:  g32_t2
      value_template: "{{ int([states('sensor.g32')[16],states('sensor.g32')[17]]|join,0,16) * 10 + int([states('sensor.g32')[18],states('sensor.g32')[19]]|join,0,16) / 10 }}"
      unit_of_measurement: "°C"

The error is probably because of {{value | **unpack(">I")** }}. In JS I’m doing this the following way:

var bindata = data.toString('binary');
var hexdata = Buffer.from(bindata, 'ascii').toString('hex');

But I’m not quite sure how to replicate this in HA. Can anybody help with this?

Thanks a ton,
Florian