How to create a switch in esphome to send different serial data depending on state

Hi all, sorry, but i’m new to esphome. I have a module which controls a relay by sending one of two distinct serial data byte streams. I cant workout how to create a switch in esp-home and depending on the state of the switch, the esp will send one of two pattern of bytes. Can someone push me in the right direction please

Sounds like this thread might be relevant to you How to control wifi relay by serial port of the ESP8266