Generic Thermostat: is this right?

For some reason, one of my Daikin units is not respecting the target temperature, i.e. if I set it to 27C, it will continue to cool down even after reaching 27C, so I decided to setup a Generic Thermostat like this:

# configuration.yaml
- platform: generic_thermostat
    unique_id: climate.sala_ac_thermostat
    name: Sala AC Thermostat
    heater: input_boolean.sala_cool_virtual
    target_sensor: sensor.sensore_temperatura_sala_xiaomi_temperature
    min_temp: 24
    max_temp: 29
    ac_mode: true
    cold_tolerance: 0.5
    hot_tolerance: 0.2
    min_cycle_duration:
      seconds: 60
    initial_hvac_mode: "off"
    home_temp: 26
    away_temp: 28
    sleep_temp: 27
    precision: 0.1
    target_temp_step: 0.5

This has the added bonus of using an external sensor instead of the integrated one which is not very precise in my experience.
I had to create it manually in the yaml because I had to use an input boolean for this automation:

alias: AC Control
description: Adjust the target temperature of Sala based on the virtual switch.
triggers:
  - entity_id:
      - input_boolean.sala_cool_virtual
    trigger: state
conditions: []
actions:
  - choose:
      - conditions:
          - condition: state
            entity_id: input_boolean.sala_cool_virtual
            state: "on"
        sequence:
          - target:
              entity_id: climate.sala
            data:
              temperature: 25
            action: climate.set_temperature
      - conditions:
          - condition: state
            entity_id: input_boolean.sala_cool_virtual
            state: "off"
        sequence:
          - target:
              entity_id: climate.sala
            data:
              temperature: 30
            action: climate.set_temperature
mode: single

I now want to expand on this (i.e. turn on/off the unit automatically - now I have to turn on the unit and then the thermostat itself), but I paused and I’m wondering if this is the right approach.
In the documentation it says to use the unit switch as the heater, but wouldn’t this turn off/on the unit itself instead of the virtual input I created?
I’m fine with my approach, just making sure this is right and I won’t have issues in the future since using an input_boolean isn’t really officially supported and may go away.

Your way is totally fine.
Having the switch from the heater is generally when we are talking about electric heaters.
I get the impression yours is not.

The only thing is that the automation could be simpler.
But it will work fine.

Thank you for your reply. I guess electric heaters are either on/off without a set temperature?
So I just have to hope it won’t be deprecated in the future :slight_smile:
Your comment made me realize I can simplify the automation with an if. Here’s a revised one for anyone who might stumble here.

alias: AC Control
description: Adjust the target temperature of Sala based on the virtual switch.
trigger:
  - platform: state
    entity_id: input_boolean.sala_cool_virtual
action:
  - service: climate.set_temperature
    target:
      entity_id: climate.sala
    data:
      temperature: >
        {{ 25 if is_state('input_boolean.sala_cool_virtual', 'on') else 30 }}
mode: single

Can input_booleans be unknown or unavailable at startup?
Serious question. It could create an issue for you.

I…don’t think they can? They’re virtual helpers.
What are your concerns?

Always assume they can - code for the possibility. Set a default.

Could you explain what could happen and how to fix it?

You’re probably ok here. But lookup the default() filter whenever you put something in a condition always ask yourself if this returns something unexpected what happens (unknown and unavailable are real things) so if your t/f test come back unknown because the whatever that built it broke.

So | default(‘off’) forces the return to be ‘off’ if it’s unknown or unavailable essentially the same thing…

So in this case I should be fine because I’m explicitly checking for on, right? In other states, it would simply set the target temperature without turning on/off anything, so it’s ok.

1 Like

Right so either you check for a state and are OK with whatever happens if it’s Not that

Or you force a default.

I tend to get nuts forcing defaults and defensive code because most of my code is for ai consumption they get very confused on the unexpected…

Its just a good habit whenever you do a condition. Have I covered for what if it’s none of this?

Sorry, I didn’t get your question.

Sorry. Rhetorical. Ask yourself that every time you put in an if or a choose…

Oh! Sure, got it. Thank you, I’ll keep it in mind.