Combine duplicate bluetooth temperature sensors into one entity

I have a number of Xiaomi Mijia BLE Sensors which I use to keep track of the temperature in the house. The temperature is broadcasted from each sensor and picked up by an ESP32 running Esphome.

Because of the long distances between some of the sensors and the ESP32, a lot of broadcasts got lost. To mitigate this I added another ESP32 running the same config in the other end of the house. As an added bonus I get readings from most of my sensors even if one of the ESP32 dies.

However, now all the data is of course duplicated, so I have kitchen_temperature, kitchen_temperature_2, hallway_temperature, hallway_temperature_2… etc.
How can I join these into one entity? E.g. sensor updates from kitchen_temperature and kitchen_temperature_2 would both update the same entity?

Esphome configuration looks like this, but I assume this should be solved on HomeAssistant end anyway?

sensor:
  - platform: pvvx_mithermometer
    mac_address: "A4:C1:38:xx:xx:xx"
    temperature:
      name: "Workroom Temperature"
    humidity:
      name: "Workroom Humidity"
    battery_level:
      name: "Workroom Battery Level"
1 Like

Thanks! Seems to work. There seems to be a 1 minute rate limiting, but I can live with that. I tried adding triggers, but it was still only updated once every minute… oh well

- trigger:
    - platform: state
      entity_id:
        - sensor.workroom_temperature
        - sensor.workroom_temperature_2
- sensor:
    - unique_id: workroom_curr_temp
      name: "Workroom Current Temperature"
      unit_of_measurement: "°C"
      state: >
        {% if states.sensor.workroom_temperature.last_changed < states.sensor.workroom_temperature_2.last_changed %}
        {{ states.sensor.workroom_temperature.state }}
        {% else %}
        {{ states.sensor.workroom_temperature_2.state }}
        {% endif %}
      device_class: temperature

The default advertising interval is 60 seconds, you can change using the TeLink/pvvx flasher tool. There isn’t anything you can do from within Home Assistant that will change how often the thermometers update.