ESPhome water heater?

I try to make my home water heater smart

the water heater has 3 heat elements

switch:
  - platform: gpio
    pin: GPIO12
    name: "r1"
    id: "r1"

  - platform: gpio
    pin: GPIO13
    name: "r2"
    id: "r2"

  - platform: gpio
    pin: GPIO14
    name: "r3"
    id: "r3"
sensor:
    
  - platform: dallas
    name: "Temperature"
    id: "Temperature"
    address: 0x483c01f09512d328
    accuracy_decimals: 0

also, I add the select component as a mode

ECO means 1 heat elements = r1
Normal means 2 heat elements = r1 + r2
Boost means 3 heat elements = r1 + r2 + r3

select:
  - platform: template
    name: "$DeviceName Mode"
    id: "Mode"
    optimistic: true
    restore_value: true
    options:
      - ECO
      - Normal
      - Boost

and finally

climate:

  - platform: thermostat
    name: "$DeviceName"
    id: "Heater"
    sensor: "Temperature"
    default_target_temperature_low: 50 °C
    startup_delay: true
    min_heating_off_time: 10s
    min_heating_run_time: 0s
    min_idle_time: 10s
    visual:
      min_temperature: 50 °C
      max_temperature: 85 °C
      temperature_step: 1 °C   
    heat_action:

      - if:
          condition:
              
            -  " I don't know how to set the condition for select as ECO " ?
          then:
              - switch.turn_on: "r1"
      - if:
          condition:
              
            -  " I don't know how to set the condition for select as Normal " ?
          then:
              - switch.turn_on: "r1"
              - switch.turn_on: "r2"
              -  " also  switch.turn_off: "r2" when reache 90%  id(Heater).target_temperature " ?
      - if:
          condition:
              
              -  "  I don't know how to set the condition for select as Boost " ?
                 
          then:
              - switch.turn_on: "r1"
              - switch.turn_on: "r3"
              - switch.turn_on: "r3"
              -  " also  switch.turn_off: "r2" when reache 90%  id(Heater).target_temperature " ?
              -  " also  switch.turn_off: "r3" when reache 80%  id(Heater).target_temperature " ?
    idle_action:
      - switch.turn_off: "r1"   
      - switch.turn_off: "r2"
      - switch.turn_off: "r3"

Thanks for help

What is your question?

1 Like

Hi @nickrout

my question in the climate section

1- how to make select as condition

    heat_action:
      - if:
          condition:
            and:
              - binary_sensor.is_off: "Connected"
              - lambda: "return id(Mode).state = ECO;"

          then:
              - switch.turn_on: "r1"

but I get this error

/config/water-heater.yaml: In lambda function:
/config/water-heater.yaml:187:28: error: 'ECO' was not declared in this scope; did you mean 'EIO'?
  187 |               - lambda: "return id(Mode).state = ECO;"
      |                            ^~~
      |                            EIO
*** [.pioenvs/water-heater/src/main.cpp.o] Error 1
========================== [FAILED] Took 5.53 seconds ==========================

2- switch.turn_off when reache 90% id(Heater).target_temperature

Hello, try with id: mode insteat of Mode

@FVdS tried same thing

I’m not familiar with three-element water heaters, but with two elements, they generally have two temperature sensors.

If the bottom one (where the cold water comes in) gets below a set temperature, that element comes on to keep the whole tank up to temp. The top one only gets below the desired temperature if you’ve used up almost all the hot water, and a quick recovery is needed. Then the top one comes on and the bottom one shuts off. This way the water heater only requires wiring and breakers for one heating element at a time.

I have like this in picture 3 elements with one temperature sensors

Ahh, totally different animal than what I was talking about. Not really sure what the goal is there. Do the three elements have different power levels? Or is the idea you can use one, two or three at a time to recover slower or faster? Of course it takes exactly the same amount of power to heat a given volume of water to a given temperature, so I don’t know where you’d get an energy savings. You might save money if your power is priced based on time of day or demand.

Sorry for the thread drift, I’m just curious.

Is the selected option from the “select” also the same as state?

Maybe you have to add c_str()


From: Select Component — ESPHome

Compiling .pioenvs/water-heater/src/main.cpp.o
/config/water-heater.yaml: In lambda function:
/config/water-heater.yaml:187:36: error: 'ECO' was not declared in this scope; did you mean 'EIO'?
  187 |               - lambda: "return id(Mode).state.c_str() = ECO;"
      |                                    ^~~
      |                                    EIO
*** [.pioenvs/water-heater/src/main.cpp.o] Error 1
========================== [FAILED] Took 5.61 seconds ==========================

same thing

Double equal signs? so → == instead of =

              - lambda: "return id(Mode).state == ECO;"

Compiling .pioenvs/water-heater/src/main.cpp.o
/config/water-heater.yaml: In lambda function:
/config/water-heater.yaml:187:29: error: ‘ECO’ was not declared in this scope; did you mean ‘EIO’?
187 | - lambda: “return id(Mode).state == ECO;”
| ^~~
| EIO
*** [.pioenvs/water-heater/src/main.cpp.o] Error 1
========================== [FAILED] Took 5.38 seconds ==========================

hmm, too bad. You already tried setting the id of the select in lowercase right? So both in the lambda function and the YAML for the select?

Is the name “mode” not allowed maybe? It is kind of generic.

Found this YAML on Github: esphome_boilercontrol/boilercontrol.yaml at db51d51c573883cd72d59cf621556a18a78e2f31 · MrSjodin/esphome_boilercontrol · GitHub

It also uses Select with options and lambda conditions with state. Difference is that here the quotation marks are set around the value and the if is set within the lambda action.

   on_value:
      then:
        lambda: |-
          if ((id(effect_block_level).state == "None")) {
            id(block_relay_a).turn_off();
            id(block_relay_b).turn_off(); }
          else if ((id(effect_block_level).state == "A")) {
            id(block_relay_a).turn_on();
            id(block_relay_b).turn_off(); }
          else if ((id(effect_block_level).state == "B")) {
            id(block_relay_a).turn_off();
            id(block_relay_b).turn_on(); }
          else if ((id(effect_block_level).state == "A+B")) {
            id(block_relay_a).turn_on();
            id(block_relay_b).turn_on(); }

Maybe this will help you out.

already tried “Mode” “mode” “mode_tt” “rrrrr” no one works some things in lambda expression

Also, make Template Text Sensor give me back the state of select (Mode) without any problems

  - platform: template
    name: "Template Text Sensor"
    update_interval: 1s
    lambda: |-
      return id(Mode).state;

Did you see my last reply? ESPhome water heater? - #14 by Johanf

Maybe you missed it bc it was added just before your repy to the one before.

@Johanf now I finish the test it works like that

- lambda: 'return id(Mode).state == "ECO";'

first problem solve
second on now one replay for it

" 2- switch.turn_off when reache 90% id(Heater).target_temperature "

1 Like

ah good.

The page Climate Component — ESPHome describes a id(my_climate).target_temperature and a id(my_climate).current_temperature

Maybe set this automation for the on_value of the sensor component of the thermometer. Sensor Component — ESPHome

Something like:

(doing out the top of my head, so do double check")

sensor:
  - platform: dallas
    name: "Temperature"
    id: "Temperature"
    address: 0x483c01f09512d328
    accuracy_decimals: 0
 on_value:
  if:
    condition:
        lambda: "return id(Heater).target_temperature * 0.9 >=  id(Heater).current_temperature"
    then:
      - switch.turn_off: "r2"
      - switch.turn_off: "r3"

However maybe something for you to think about is that for 85 degrees it might be logic to stop at 90% but for 60 degrees at 70%, because otherwise the temp will go trough.

dear @Johanf I know this method I’m looking for something inside climate because climate its response to a trigger

1 Like

You can also consider setting an automation within Home Assistant. If I am right, you are already setting the waterboiler from within Home Assistant.

Then you can use the conditions and triggers and achieve the result you would like.