From: David Woodhouse Date: Thu, 3 Oct 2024 18:41:52 +0000 (+0100) Subject: Add climate thermostat X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=2ce1438fcfa33f897db93a5b2d094078fed40989;p=users%2Fdwmw2%2Fesp32-pool.git Add climate thermostat --- diff --git a/bathroomfloor.yaml b/bathroomfloor.yaml index 3de7774..1a015a6 100644 --- a/bathroomfloor.yaml +++ b/bathroomfloor.yaml @@ -74,6 +74,24 @@ globals: time: - platform: sntp + on_time: + - seconds: 0 + minutes: 0 + hours: 6 + then: + climate.control: + id: ntc_climate + mode: HEAT + target_temperature: 21°C + + - seconds: 0 + minutes: 30 + hours: 09 + then: + climate.control: + id: ntc_climate + mode: HEAT + target_temperature: 10°C mqtt: on_connect: @@ -109,6 +127,10 @@ mqtt: case ${domo_thresh}: /* Temperature setpoint */ id(temp_setpoint) = x["svalue1"].as(); + auto call = id(ntc_climate).make_call(); + call.set_mode("HEAT"); + call.set_target_temperature(id(temp_setpoint)); + call.perform(); ESP_LOGD("mqtt", "Got temp_setpoint %f", id(temp_setpoint)); break; } @@ -162,7 +184,7 @@ sensor: # - 12.55 kOhm - > 17.6°C - 12.30 kOhm -> 18.2°C - 9.97 kOhm -> 23.5°C - name: "Bathroom floor temperature" + id: ntc_temperature filters: - clamp: min_value: 5 @@ -174,25 +196,6 @@ sensor: if (!isnan(x)) id(tell_domo_svalue)->execute(${domo_temp}, std::to_string(x)); - bool cur_state = id(ufh_relay).state; - bool want_state; - if (x > id(temp_setpoint)) - want_state = false; - else if (x < id (temp_setpoint)) - want_state = true; - else - return; - - if (want_state != cur_state) { - time_t now = ::time(NULL); - if (now < id(relay_stable_time)) { - ESP_LOGD("UFH", "Too soon to turn %s (%ld seconds)", want_state ? "ON" : "OFF", - now - id(relay_stable_time)); - } else { - id(ufh_relay).toggle(); - } - } - - platform: resistance id: ntc_resistance sensor: ntc_adc @@ -216,6 +219,30 @@ sensor: # 2.52 -> 2.49 # 1.99 -> 1.96 +climate: + - platform: thermostat + id: ntc_climate + name: "Bathroom floor" + sensor: ntc_temperature + min_heating_off_time: 300s + min_heating_run_time: 300s + min_idle_time: 30s + heat_action: + - switch.turn_on: ufh_relay + idle_action: + - switch.turn_off: ufh_relay + on_control: + - lambda: ESP_LOGI("CLIMATE", "on_control"); + on_state: + - lambda: |- + if (id(ntc_climate).target_temperature != id(temp_setpoint)) { + ESP_LOGI("UFH", "Tell domo target changed from %f °C to %f °C", + id(temp_setpoint), id(ntc_climate).target_temperature); + id(temp_setpoint) = id(ntc_climate).target_temperature; + id(tell_domo_nsvalues)->execute(${domo_thresh}, 2, std::to_string(id(temp_setpoint))); + } + + interval: - interval: 60s then: