Publish from ESPHome to HA's input_text?

Is there any way to publish a string value from ESPHome back to a HA input_text entity?

In general any input_text can be updated through its set_value service.
But I can’t find a way to do that from ESPHome.

Not that I know of.

You would have to use a sensor containing the text from ESPHome and an automation to update the input_text when the sensor state changes.

Thanks @tom_l.
But as usual - minutes after you write the question you find the answer. :roll_eyes:
And it seems possible because you can call any HA service from ESPHome:

on_...:
  - homeassistant.service:
      service: input_text.set_value
      data:
        value: "abc"

See Native API Component — ESPHome.

Now I am looking for a way to do that from lambdas. Will report back when I find out.

You could probably get the ESP to publish to an MQTT topic and then use a HA automation to send that value to the input_text entity.

Huh. Well there you go. I’ve used custom service calls from ESPHome before but didn’t know you could use the core ones too.

What do you want to write in the lambda?

Hmmm, using homeassistant.service from lambdas seems to be possible only through undocumented internal methods of ESPHome. The risk that they break in the future is considerable.

@sparkydave: Yes, MQTT would be an option too. It also can be used from within lambdas in ESPHome.

This is an MCU that I placed within the control unit of the ventilation system of our house. It mimics button presses of the control unit. I need to transfer sequences of button presses from HA to the unit. This is what I want to do through the input_text field. After the MCU has received the new text, it shall clear the field automatically. The task of the lambda is to work through the string - command by command in an interval loop - and create simulated button strokes from it.

Anyway - meanwhile I found that the better way to establish this string transfer is probably to create a user defined service in ESPHome and call that service from HA with the string as a parameter.

Sorry to revive this thread.

I need to reset an input_text helper to empty from my esphome code and this looks like the right approach, but I can’t figure out the correct data format on the last line of my code - can anyone help?

  - platform: homeassistant
    name: "command_to_run"
    entity_id: input_text.esphome_serial_command
    id: command2run
    on_value:
          then:

           # write the command to the serial port
            - uart.write: !lambda  
                std::string str = id(command2run).state;
                std::vector<uint8_t> vec(str.begin(), str.end());
                return vec;
            - uart.write: "\r\n"  # return

           # reset the command value in Home Assistant
            - homeassistant.service:
                service: input_text.set_value
                data:
                  **** what is need here to reset the value of esphome_serial_command to "" ***

I have no idea if it will work this way but for input select helper, to show an empty box you use " "

I figured it out:

  - platform: homeassistant
    name: "command_to_run"
    entity_id: input_text.esphome_serial_command
    id: command2run
    on_value:
          then:
            - uart.write: !lambda  
                std::string str = id(command2run).state;
                std::vector<uint8_t> vec(str.begin(), str.end());
                return vec;
            - uart.write: "\r\n"  # return
            - homeassistant.service:
                service: input_text.set_value
                data:
                  entity_id: input_text.esphome_serial_command
                  value: ""
1 Like