ESPHome UART template string

Hi all,

I’m trying make an IR receiver to control an audio-matrix, and I want to be able to control multiple zones from each receiver in the house.

My ‘fixed’ UART commands work, but I want to be able to change zone on the fly, e.g. press cifre 4 to control zone 4. Therefor I’m trying to use globals to to that, which I’m then converting in to a text_sensor.

Now, my problem is that I cannot get the content of the text_sensor to be sent using the uart.write function. Can anyone tell me if it is even possible, or if I’m just doing it wrong? Thanks!

globals:
### this value changes when I press a cifre on my remote
  - id: zone
    type: int
    restore_value: yes
    initial_value: '2'

esphome:
  name: esp8266_ireye_audac_zone
  platform: ESP8266
  board: d1_mini
    
wifi:
  networks:
  - ssid: xxxxxxxx
    password: xxxxxxxx
  
# Enable logging
logger:
  baud_rate: 0

# Enable Home Assistant API
api:

ota:

text_sensor:
### This gives me the entire command string using the global value
  - platform: template
    name: "playstring"
    lambda: !lambda |-
      int a = id(zone);

      std::string beginning ("#|X001|web|SVU0");
      std::string commandvar = to_string(a);   
      std::string end ("|0|U|");
      std::string command;
      
      command = beginning + commandvar + end;
      return command;
    update_interval: 10s
    id: play_str

uart:
  tx_pin: GPIO01
  rx_pin: GPIO03
  baud_rate: 19200

binary_sensor:
  - platform: remote_receiver
    name: "PLAY"
    raw:
      code: [52, -51, 310, -112, 52, -155, 258, -60, 52, -103, 310, -60, 52, -51, 258, -52, 52, -60, 413, -112, 52, -51, 362, -60, 52, -52, 51, -155, 52, -163, 155, -104, 51, -52, 103, -62]
    filters:
      - delayed_off: 50ms 
    on_press:
      then:
        - logger.log: "Play"
        - uart.write: id(play_str)
        - delay: 10ms
        - uart.write: [0x0D, 0x0A]