IF statements in the configuration: if input_boolean is ON, other 2 are OFF

Hi, folks!

What is the best way to achieve this? I have 3 rooms, each with one temperature sensor and thermostat (practically a relay on an ESPHome device). I want to control which temperature sensor dictates the set temperature for the thermostat.

So I created 3 input booleans to represent the 3 rooms which I will have in a horizontal stack in Lovelace:

input_boolean.room_one
input_boolean.room_two
input_boolean.room_three

And I have the 3 sensors:
sensor.room_one_temp_sensor
sensor.room_two_temp_sensor
sensor.room_three_temp_sensor

And the thermostat for which the code is something like this:
climate:

    • platform: generic_thermostat*
  • name: Entire House*
  • heater: switch.water_heater_thermostat*
  • target_sensor: sensor.room_one_temp*

And the logic would be this:

if input_boolean.room_one in on
*then input_boolean.room_two is off *
input_boolean.room_three is off

climate:

    • platform: generic_thermostat*
  • name: Entire House*
  • heater: switch.water_heater_thermostat*
  • target_sensor: sensor.room_one_temp*

if input_boolean.room_two in on
*then input_boolean.room_one is off *
input_boolean.room_three is off

climate:

    • platform: generic_thermostat*
  • name: Entire House*
  • heater: switch.water_heater_thermostat*
  • target_sensor: sensor.room_two_temp*

And the same for room_three

How do I do this? I tried templating for hours but it is hard.
Thank you so much!

The target sensor option does not support templates.

https://www.home-assistant.io/integrations/generic_thermostat/

Screenshot 2024-01-03 at 10-44-19 Generic thermostat

1 Like

Whaaat? I am stuck with just one sensor? But maybe I can create a sensor that takes its values from another sensor. So in my case, from one sensor and then from another. What do you say?

Yes you can do that.

template:
  - sensor:
      - name: Selected Temperature
        state_class: measurement
        device_class: temperature
        unit_of_measurement: "°C" # or F
        state: >
          {% if is_state('input_boolean.room_one', 'on') %}
            {{ states('sensor.room_one_temp') }}
          {% elif is_state('input_boolean.room_two', 'on') %}
            {{ states('sensor.room_two_temp') }}
          {% else %}
            {{ states('sensor.room_three_temp') }}
          {% endif %}
1 Like

I see. Thank you, Tom! I will try it out.
I will see if I can apply the same logic for the first part. The one where when I select one input boolean, it gets turned on and the other two get turned off. For now I can select two or all and that’s not good.

Screenshot 2024-01-03 111313

How about using an input select with three states instead?

input_select:
  room_sensor:
    name: Room Sensor
    options:
      - One
      - Two
      - Three

Only one option can be selected at a time.

template:
  - sensor:
      - name: Selected Temperature
        state_class: measurement
        device_class: temperature
        unit_of_measurement: "°C" # or F
        state: >
          {% if is_state('input_select.room_sensor', 'One') %}
            {{ states('sensor.room_one_temp') }}
          {% elif is_state('input_select.room_sensor', 'Two') %}
            {{ states('sensor.room_two_temp') }}
          {% else %}
            {{ states('sensor.room_three_temp') }}
          {% endif %}

Hi , Tom. The code you wrote does wonders. Too bad templating is so hard to learn.

I actually did try to use input selector before but I didn’t like the dropdown option. I wanted to have all the 3 options clearly visible. But I guess I will leave it as it is.

Thank you so much!!