Write multiple sensors values to UART

I’d like to get the value of multiple sensors from Home Assistant and write them to the UART in a particular format. Let’s say it’s comma separated text.

I can get the values into ESPHome using homeassistant sensors, but I’m not sure how to write them to the UART. I’ve looked at the UART switch component, the uart.write actions, and the logger.

Would it be best to create a new display device which is just a UART output, similar to the LCD devices? Then the format can be defined with printf in the definition.

Any suggestions most welcome.

Hi,
I’m also looking for the same thing. Did you figure something out? Thanks.

should get you somewhere

so you have a sensor platform home assistant?

sensor:
  - platform: homeassistant
    name: "Temperature Sensor From Home Assistant"
    entity_id: sensor.temperature_sensor
# up to here copy from docs, now we need to send the value to uart, it supports lambdas so...
    on_value:
      then:
        # the values is in x, we need to convert x to some bytes, this depends on valid values of x,
        # remember x is float, the following will work for values from 0 to 255 and will send the raw byte 
        - uart.write: !lambda |-
            auto val = (byte)(int)x;
            return { x };

Sorry for taking so long to reply, but yes I got this working.

I made a custom device

class NixieDisplayComponent : public PollingComponent, public CustomAPIDevice, public UARTDevice { .. }

I subscribe to the state of some other HomeAssistant values (hence the CustomAPIDevice). I keep the values in local variables in my component And in update(), which is called every second due to the PollingComponent, I write the values out to the UART.

It’s not finished yet so I haven’t published the code anywhere. But this part is working fine.

can share you NixieDisplayComponent

I have UsartGPU display, it use like uart.write: DS64(44,40,‘11:11’,15,0) ‘11:11’ is time

thanks.

Sorry I didn’t finish it yet. But maybe I can post it later anyway.