This code works for me, removed wifi code for privacy
esphome:
name: "pool"
esp32:
board: esp32dev
framework:
type: esp-idf
version: recommended
# Enable logging
logger:
# Enable Home Assistant API
api:
ota:
wifi:
networks:
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "Esphome-Web-C7Bd00"
password: "IUesaiQycXiE"
#Configuration entry
dallas:
- pin: GPIO32
update_interval: 30s
color:
- id: my_red
red: 100%
green: 0%
blue: 0%
- id: my_yellow
red: 100%
green: 100%
blue: 0%
- id: my_green
red: 0%
green: 100%
blue: 0%
- id: my_blue
red: 0%
green: 0%
blue: 100%
- id: my_gray
red: 50%
green: 50%
blue: 50%
- id: my_white
red: 100%
green: 100%
blue: 100%
- id: my_orange
red: 100%
green: 60%
blue: 0%
- id: my_teal
red: 0%
green: 50%
blue: 45%
# put a ttf font called InterFont.ttf in esphome/fonts/
font:
- file: "fonts/InterFont.ttf"
id: helvetica_48
size: 24
- file: "fonts/InterFont.ttf"
id: helvetica_24
size: 20
- file: "fonts/InterFont.ttf"
id: helvetica_S
size: 16
######################################################
## ##
## To initiate to connection with the BLE device ##
## ##
######################################################
esp32_ble_tracker: #### Stop the active scan ####
scan_parameters:
active: false
ble_client:
- mac_address: C0:00:00:00:35:2B #Use the MAC address of your BLE device
id: ble_yc01
on_connect: #### Actions to perform when connecting to the BLE device ####
then:
#### Wait until characteristic is discovered ####
- wait_until:
lambda: |-
esphome::ble_client::BLEClient* client = id(ble_yc01);
auto service_uuid = 0xFF01;
auto char_uuid = 0xFF02;
//#### When waiting for connection, we extract the available characteristics ####
esphome::ble_client::BLECharacteristic* chr = client->get_characteristic(service_uuid, char_uuid);
return chr != nullptr;
#### Official connection to the BLE device with the desired characteristic ####
- lambda: |-
ESP_LOGD("ble_client_lambda", "Connected to BLE-YC01");
esphome::ble_client::BLEClient* client = id(ble_yc01);
auto service_uuid = 0xFF01;
auto char_uuid = 0xFF02;
esphome::ble_client::BLECharacteristic* chr = client->get_characteristic(service_uuid, char_uuid);
if (chr == nullptr) {
ESP_LOGW("ble_client", "[0xFF01] Characteristic not found. State update can not be written.");
}
on_disconnect:
then:
- lambda: |-
ESP_LOGD("ble_client", "Disconnected from BLE-YC01");
binary_sensor:
- platform: status
name: "Node Status"
id: system_status
- platform: gpio
entity_category: config
pin:
number: GPIO0
inverted: true
mode:
input: true
pullup: true
name: ttgo button_0 push
id: tdisplay_button_input_0
- platform: gpio
entity_category: config
pin:
number: GPIO35
inverted: true
mode:
input: true
id: tdisplay_button_input_1
name: ttgo button_1 push
switch:
- platform: restart
name: "TTGO restart"
id: ttgo_restart
- platform: gpio
pin: GPIO4
name: " TTGO-T-Display Backlight"
id: backlight
- platform: ble_client #### To switch on and off the communication with the BLE device ####
id: ble_switch
ble_client_id: ble_yc01
name: "Enable BLE-YC01"
# replace my entity IDs with your entity IDs below
sensor:
- platform: dallas
address: 0x763cfef64948ba28
name: "Pool"
id: Pool_Temp
filters:
- filter_out: nan
- platform: dallas
address: 0x153c61f649acb628
name: "Frem"
id: Frem_Temp
filters:
- filter_out: nan
- platform: dallas
address: 0xf03cd4f649b42328
name: "Retur"
id: Retur_Temp
filters:
- filter_out: nan
- platform: homeassistant
id: pool_roof_temp
entity_id: sensor.pool_roof_temp
internal: true
- platform: homeassistant
id: pool_tas_temp
entity_id: sensor.tasmota_sn_th16_ds18b20_temperature
internal: true
- platform: wifi_signal
name: "ttgo wifi signal"
update_interval: 600s
- platform: template
id: int_temp
unit_of_measurement: "C"
accuracy_decimals: 1
state_class: measurement
device_class: temperature
#lambda: return temperatureRead();
- platform: template
name: "BLE-YC01 EC"
id: ble_yc01_ec_sensor
unit_of_measurement: "µS/cm"
accuracy_decimals: 0
state_class: measurement
icon: mdi:water-opacity
- platform: template
name: "BLE-YC01 TDS"
id: ble_yc01_tds_sensor
unit_of_measurement: "ppm"
accuracy_decimals: 0
state_class: measurement
icon: mdi:water-opacity
- platform: template
name: "BLE-YC01 Temperature"
id: ble_yc01_temperature_sensor
unit_of_measurement: "C"
accuracy_decimals: 1
state_class: measurement
device_class: temperature
- platform: template
name: "BLE-YC01 ORP"
id: ble_yc01_orp_sensor
unit_of_measurement: "mV"
accuracy_decimals: 0
state_class: measurement
device_class: voltage
- platform: template
name: "BLE-YC01 pH"
id: ble_yc01_ph_sensor
unit_of_measurement: "pH"
accuracy_decimals: 2
state_class: measurement
icon: mdi:ph
- platform: template
name: "BLE-YC01 battery"
id: ble_yc01_battery
unit_of_measurement: "%"
accuracy_decimals: 0
state_class: measurement
device_class: battery
icon: mdi:battery
- platform: template
name: "BLE-YC01 CL"
id: ble_yc01_cloro
unit_of_measurement: "ppm"
accuracy_decimals: 0
state_class: measurement
icon: mdi:water-opacity
- platform: ble_client #### Sensor required to manage values coming from the BLE device ####
ble_client_id: ble_yc01
id: ble_yc01_sensor
internal: true
service_uuid: FF01
type: characteristic
characteristic_uuid: FF02
notify: true
#### Lambda to decode values and push to the associated sensors ####
lambda: |-
if (x.size() == 0) return NAN;
//ESP_LOGD("ble_client.receive", "value received with %d bytes: [%.*s]", x.size(), x.size(), &x[0]); // #### Useful for debugging ####
// ### DECODING ###
uint8_t tmp = 0;
uint8_t hibit = 0;
uint8_t lobit = 0;
uint8_t hibit1 = 0;
uint8_t lobit1 = 0;
auto message = x;
for (int i = x.size() -1 ; i > 0; i--) {
tmp=message[i];
hibit1=(tmp&0x55)<<1;
lobit1=(tmp&0xAA)>>1;
tmp=message[i-1];
hibit=(tmp&0x55)<<1;
lobit=(tmp&0xAA)>>1;
message[i]=~(hibit1|lobit);
message[i-1]=~(hibit|lobit1);
}
//ESP_LOGD("ble_client.receive", "value received with %d bytes: [%.*s]", message.size(), message.size(), &message[0]); // #### For debug ####
// #### Extraction of individual values ####
auto temp = ((message[13]<<8) + message[14]);
auto ph = ((message[3]<<8) + message[4]);
auto orp = ((message[20]<<8) + message[21]);
auto battery = ((message[15]<<8) + message[16]);
auto ec = ((message[5]<<8) + message[6]);
auto tds = ((message[7]<<8) + message[8]);
auto cloro = ((message[11]<<8) + message[12]);
// #### Sensors updated with new values
id(ble_yc01_temperature_sensor).publish_state(temp/10.0);
id(ble_yc01_ph_sensor).publish_state(ph/100.0);
id(ble_yc01_orp_sensor).publish_state(orp);
id(ble_yc01_battery).publish_state(battery/31.51);
id(ble_yc01_ec_sensor).publish_state(ec);
id(ble_yc01_tds_sensor).publish_state(tds);
id(ble_yc01_cloro).publish_state(cloro/10.0);
return 0.0; // this sensor isn't actually used other than to hook into raw value and publish to template sensors
time:
- platform: homeassistant
id: esptime
spi:
clk_pin: GPIO18
mosi_pin: GPIO19
display:
- platform: st7789v
model: TTGO TDisplay 135x240
backlight_pin: GPIO4
cs_pin: GPIO5
dc_pin: GPIO16
reset_pin: GPIO23
update_interval: 5s
rotation: 90°
lambda: |-
it.rectangle(0, 0, it.get_width(), it.get_height(), id(my_blue));
//it.rectangle(0, 20, it.get_width(), it.get_height(), id(my_blue)); // header bar should be line not rectangle
it.line(0, 22, 240, 22, id(my_blue));
it.print(5, 22, id(helvetica_S), id(my_white), TextAlign::LEFT, "Frem.");
it.printf(5, 34, id(helvetica_48), id(my_red), TextAlign::LEFT, "%.0f°", id(Frem_Temp).state);
it.print(235, 22, id(helvetica_S), id(my_white), TextAlign::RIGHT, "Retur.");
it.printf(235, 34, id(helvetica_48), id(my_blue), TextAlign::RIGHT, "%.0f°", id(Retur_Temp).state);
it.print(120, 22, id(helvetica_S), id(my_white), TextAlign::TOP_CENTER, "Pool.");
it.printf(120, 34, id(helvetica_48), id(my_green), TextAlign::TOP_CENTER, "%.0f°", id(Pool_Temp).state);
it.printf(5, 88, id(helvetica_48), id(my_orange), TextAlign::LEFT, "%.1f", id(ble_yc01_ph_sensor).state);
it.printf(235, 88, id(helvetica_48), id(my_teal), TextAlign::RIGHT, "%.0f", id(ble_yc01_cloro).state);
it.print(235, 70, id(helvetica_S), id(my_white), TextAlign::RIGHT, "ppm.");
it.strftime(5, 2, id(helvetica_S), id(my_yellow), TextAlign::TOP_LEFT, "%A %H:%M", id(esptime).now());
it.print(160, 70, id(helvetica_S), id(my_white), TextAlign::RIGHT, "Batt.");
it.print(5, 70, id(helvetica_S), id(my_white), TextAlign::LEFT, "pH");
it.printf(170, 88, id(helvetica_48), id(my_teal), TextAlign::RIGHT, "%.0f%%", id(ble_yc01_battery).state);
it.printf(55, 88, id(helvetica_48), id(my_green), TextAlign::LEFT, "%.0f", id(ble_yc01_orp_sensor).state);
it.print(55, 70, id(helvetica_S), id(my_white), TextAlign::LEFT, "orp");
if (id(system_status).state) {
it.print(235, 2, id(helvetica_S), id(my_green), TextAlign::TOP_RIGHT, "Online");
}
else {
it.print(235, 2, id(helvetica_S), id(my_red), TextAlign::TOP_RIGHT, "Offline");
}