Skip to content

Instantly share code, notes, and snippets.

@tkroo
Last active November 14, 2024 06:58
Show Gist options
  • Save tkroo/c67f3ffca13b6e30c912295a5f450f5b to your computer and use it in GitHub Desktop.
Save tkroo/c67f3ffca13b6e30c912295a5f450f5b to your computer and use it in GitHub Desktop.
substitutions:
name: esphome-web-1dbf28
friendly_name: c3pico-therm-1dbf28
ha_sensor_entity_id: sensor.average_of_temperature_sensors
esphome:
name: ${name}
friendly_name: ${friendly_name}
min_version: 2024.6.0
name_add_mac_suffix: false
project:
name: esphome.web
version: dev
platformio_options:
board_build.flash_mode: dio
esp32:
board: esp32-c3-devkitm-1
framework:
type: esp-idf
logger:
api:
encryption:
key: !secret api_key
ota:
- platform: esphome
improv_serial:
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
output_power: 13 # this is only for some esp32 boards that have wifi issues, not really sure if I need this here.
# To have a "next url" for improv serial
web_server:
dashboard_import:
package_import_url: github://esphome/firmware/esphome-web/esp32c3.yaml@main
import_full_config: true
i2c:
sda: 8
scl: 10
scan: true
id: bus_a
frequency: 400kHz
text_sensor:
- platform: template
id: message
name: "Temperature data source"
lambda: |-
if ( id(connection_status).state && (std::to_string(id(ha_entity).state) != "nan") ) {
return {"HA sensor"};
} else {
return {"onboard sensor"};
}
entity_category: diagnostic
disabled_by_default: true
update_interval: 60s
# the if condition in the lambda above is probably *NOT* a good test if the sensor is connected and returning valid data.
switch:
- platform: gpio
pin:
number: 5
mode:
output: true
pullup: true
name: "relay switch"
id: relay_switch
- platform: template
id: onoff_switch
lambda: |-
if (tcc1->mode != 0) {
return true;
} else {
return false;
}
turn_on_action:
then:
- logger.log: "onoff switch ON"
- climate.control:
id: tcc1
mode: HEAT
turn_off_action:
then:
- logger.log: "onoff switch OFF"
- climate.control:
id: tcc1
mode: "OFF"
binary_sensor:
- platform: status
name: "Connection status"
id: connection_status
disabled_by_default: true
- platform: gpio
pin:
number: 4
mode:
input: true
pullup: true
id: increase_temp
on_press:
then:
- logger.log: "increase temp"
- climate.control:
id: tcc1
target_temperature: !lambda return id(tcc1).target_temperature + 1.0;
- platform: gpio
pin:
number: 0
mode:
input: true
pullup: true
id: decrease_temp
on_press:
then:
- logger.log: "decrease temp"
- climate.control:
id: tcc1
target_temperature: !lambda return id(tcc1).target_temperature - 1.0;
- platform: gpio
pin:
number: 1
inverted: true
mode:
input: true
pullup: true
id: onoff_button
on_press:
- switch.toggle: onoff_switch
- platform: gpio
pin:
number: 2
inverted: true
mode:
input: true
pullup: true
id: cycle_button
on_press:
then:
- climate.control:
id: tcc1
preset: !lambda |-
switch (id(tcc1).preset.value()) {
case CLIMATE_PRESET_HOME:
return CLIMATE_PRESET_SLEEP;
case CLIMATE_PRESET_SLEEP:
return CLIMATE_PRESET_AWAY;
case CLIMATE_PRESET_AWAY:
return CLIMATE_PRESET_ECO;
case CLIMATE_PRESET_ECO:
return CLIMATE_PRESET_HOME;
default:
return CLIMATE_PRESET_HOME;
}
sensor:
- platform: shtcx
id: shtcx_sensor
address: 0x70
temperature:
id: shtcx_temp
name: "shtcx_temp"
humidity:
id: shtcx_hum
name: "shtcx_hum"
update_interval: 30s
- platform: homeassistant
id: ha_entity
unit_of_measurement: "°C"
device_class: "temperature"
state_class: "measurement"
accuracy_decimals: 3
entity_id: ${ha_sensor_entity_id}
- platform: template
id: proxy_sensor
lambda: |-
if( id(connection_status).state && (std::to_string(id(ha_entity).state) != "nan") ) {
return id(ha_entity).state;
} else {
return id(shtcx_temp).state;
}
# the if condition in the lambda above is probably *NOT* a good test if the sensor is connected and returning valid data.
climate:
- platform: thermostat
name: "Thermostat Climate Controller"
id: tcc1
visual:
min_temperature: 4
sensor: proxy_sensor
min_heating_off_time: 30s
min_heating_run_time: 30s
min_idle_time: 10s
heat_action:
- switch.turn_on: relay_switch
idle_action:
- switch.turn_off: relay_switch
default_preset: HOME
on_boot_restore_from: memory
preset:
- name: HOME
default_target_temperature_low: 20
mode: heat
- name: SLEEP
default_target_temperature_low: 17.5
mode: heat
- name: AWAY
default_target_temperature_low: 10
mode: heat
- name: ECO
default_target_temperature_low: 5
mode: heat
font:
- file:
type: gfonts
family: "Roboto"
id: myfont
size: 14
display:
- platform: ssd1306_i2c
model: "SSD1306 128x64"
address: 0x3C
lambda: |-
int l = 14;
std::string mymode = (tcc1->mode == 0) ? "OFF" : "ON";
std::string myaction = "";
if(tcc1->action==0) {myaction="OFF";}
if(tcc1->action==3) {myaction="HEATING";}
if(tcc1->action==4) {myaction="IDLE";}
if(tcc1->mode == 0) {
it.printf(it.get_width()/2, l*0, id(myfont), TextAlign::TOP_CENTER, "%s", mymode.c_str());
} else {
it.printf(it.get_width()/2, l*0, id(myfont), TextAlign::TOP_CENTER, "%s", myaction.c_str());
}
it.printf(0, l*1, id(myfont), "target");
it.printf(it.get_width(), l*1, id(myfont), TextAlign::RIGHT, "%.1f F", id(tcc1).target_temperature * (9.0/5.0) + 32.0);
it.printf(0, l*2, id(myfont), "current");
it.printf(it.get_width(), l*2, id(myfont), TextAlign::RIGHT, "%.1f F", id(tcc1).current_temperature * (9.0/5.0) + 32.0);
it.printf(0, l*3, id(myfont), "preset");
it.printf(it.get_width(), l*3, id(myfont), TextAlign::RIGHT, "%s", esphome::climate::climate_preset_to_string(id(tcc1).preset.value()));
# it.printf(it.get_width(), l*3, id(myfont), TextAlign::RIGHT, "%s", std::to_string(id(ha_entity).state).c_str() );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment