How do I create a thermostat with multiple xiaomi temp sensors with option to select a certain sensor

I’m pretty new to HA ecosystem and I want to create a heating automation for my home. Here is the basic setup I have:
-My home is heated by single boiler and several radiators.

  • I have HA installed on a RPi3 B+, and ESP32S and 4 xiaomi mijia thermometer and humiditiy sensors which I have flashed with costom firmware.

I already integrated the temp sensors into the HA with ESP32 and I have no problem getting the temp values from each sensors. What I intend to do is place each sensor in different rooms (Bedroom, office, living room, and guest bedroom) and turn on the boiler by getting the data from only one sensor (which I select from the lovelace or somewhat). For example, when I sit in the living room I want automation to turn on boiler by the data that is acqiured from only the living room. rest of sensor values sould be ignored by the system. Basicially I need something like 4 buttons in a card. When I press button 1 in lovelace, boiler will controlled by sensor1. If I press button 2, button 1 should be like unpressed and boiler sould be controlled only by the sensor 2 values. By the way, I need a set temperature feature as well.

Well, I need some help from you guys.
Thanks in advance.

Make the target temperature sensor a template sensor that will take the value of the thermometer based on an input select.
If you’d like to use buttons instead of input_select, you’ll have to have automation on pushes of the thermometer buttons. Each thermometer should have an input_boolean meaning button pressed/selected. Once you push one of the thermometer buttons an automation should turn off the other three thermometer input_booleans and set the template sensor value. And this done for all three thermometers.

Thanks for your help. I got the general idea. However, I was not able to create a template sensor since my code writing ablity is like ‘super-beginner’. A piece of example code would be great :slight_smile:
Thanks!

For the button solution, let’s say you have input_boolean’s for room1-4 and temperature sensors for those room1-4. The template for the generic thermostat target temperature would be:

sensor:
  platform: template
  sensors:
    main_temp_template:
      friendly_name: Main temperature
      unit_of_measurement: "°C"
      value_template: >-
        {% if is_state('input_boolean.heat_room1', 'on') %}
          {{ states('sensor.temp_room1') | string }}
        {% elif is_state('input_boolean.heat_room2', 'on') %}
          {{ states('sensor.temp_room2') | string }}
        {% elif is_state('input_boolean.heat_room3', 'on') %}
          {{ states('sensor.temp_room3') | string }}
        {% elif is_state('input_boolean.heat_room4', 'on') %}
          {{ states('sensor.tem_room4') | string }}
        {% endif %}

The automation would be something like this and you’ll have in total four of them, one for each room:

alias: "Heat room1"
initial_state: "on"
trigger:
  platform: state
  entity_id: input_boolean.heat_room1
  to: "on"
action:
  - service: input_boolean.turn_off
    entity_id: input_boolean.heat_room2
  - service: input_boolean.turn_off
    entity_id: input_boolean.heat_room3
  - service: input_boolean.turn_off
    entity_id: input_boolean.heat_room4

the button could be something like:

type: custom:button-card
icon: mdi:thermometer
size: 30px
styles:
  label:
    - font-size: 95%
  card:
    - height: 70px
label: >
   [[[
     var temp = states['sensor.temp_attila'].state;
     return 'attila: ' + (temp ? temp : '0') + '°C';
   ]]]
show_label: true
show_name: false
entity: input_boolean.heat_attila
hold_action:
  action: more-info
  entity: sensor.temp_attila
1 Like

Wow. Thank you so much. This is excatly what I needed.