What is the best way for esphome device to receive and controll value of external climate.temperature attribute

I’m designing a wall-mounted controller based on esphome (buttons + LED display), to controll climate, lights, shutter etc.
I’m using “platform: homeassistant” sensor to get and display the climate setpoint temperature and it works OK:

  - platform: homeassistant
    id: setpoint_temperature
    entity_id: ${target_climate_name}
    attribute: temperature
    internal: False

But when I change it in ESPHome and publish new state, it does not change the attribute value in Home Assistant (but it changes it in ESPHome properly)

  - platform: gpio
    name: "${dev_name} DOWN button"
    pin: 
      number: GPIO13
      inverted: true
      mode:
        input: true
        pullup: true        
    filters:
      - delayed_off: 30ms    
    on_press:
      then:
        - lambda: id(setpoint_temperature).publish_state(id(setpoint_temperature).state - 0.5);
        - component.update: my_display              

Is this by design, or am I missing something?

Right now I’m using workarount calling homeassistant.service to change setpoint:

# DOWN button 
  - platform: gpio
    name: "${dev_name} DOWN button"
    pin: 
      number: GPIO13
      inverted: true
      mode:
        input: true
        pullup: true        
    filters:
      - delayed_off: 30ms    
    on_press:
      then:
        - lambda: id(setpoint_temperature).publish_state(id(setpoint_temperature).state - 0.5);
        - homeassistant.service:
            service: climate.set_temperature
            data:
              temperature: !lambda "return id(setpoint_temperature).state;"
              entity_id: ${target_climate_name}
        - component.update: my_display   

It works, but not very comfortable - when button is pressed several times, often it “refreshes” the previous value from homeassistant during the series of press, returning value to the state before few clicks.

So, if there is anyone who have experience with that and can share what is the best method of getting and controlling attribute of entity from Home Assistant, I’ll appreciate that.

I am on the threshold of the limit to my knowledge here, but this is normal. And your workaround is the correct fix.

ESPHome is stand-alone. It works even if Home Assistant is down. I am guessing that you are seeing a scope issue where the variable on ESPHome is local to ESPHome. Because of this you have to deliberately tell Home Assistant of any ESPHome variable changes.

My best guess of what’s happening.

The simplest explanation is that the homeassistant sensor in esphome is just that, a sensor, not a controller.

did you try: Home Assistant Sensor — ESPHome
inside ESPHome this is the connection to HA

Example configuration entry

sensor:

  • platform: homeassistant
    id: current_temperature
    entity_id: climate.living_room
    attribute: current_temperature

Yes, see the code he posted.

Yes, it makes sense. I’m just confused by the note in docs:

The sensors implemented by this component are by default internal, to avoid exporting back them to Home Assistant. Should you still want to do that (eg. because you use ESPHome’s very efficient filters on them) you need to specifically configure internal: false. Also, state_class, unit_of_measurement are not inherited from the imported sensor so you need to set them manually.

So I’ve thought that setting internal: false is intended to auto export changed value to Home Assistant . . .