Files
home-assistant/esphome_b4_controller.yaml
2026-05-17 17:08:45 +02:00

354 lines
8.0 KiB
YAML

esphome:
name: esphome-b4-hochbeete
friendly_name: Hochbeete Controller
esp32:
board: esp32-s3-devkitc-1
framework:
type: arduino
logger:
hardware_uart: USB_SERIAL_JTAG
api:
encryption:
key: WwhN4hpN66W9gSvTfkMA6f/Gen98Y8eEmUW08C3z2Xs=
ota:
- platform: esphome
wifi:
ssid: "HZ"
password: "pCI&QA?PNAn'R1Y3h7PQ7Uh4"
ap:
ssid: "Kincony-B4-Fallback"
password: "12345678"
captive_portal:
i2c:
- id: bus_relay
sda: 8
scl: 18
scan: true
frequency: 400kHz
- id: bus_ads
sda: 13
scl: 14
scan: true
frequency: 100kHz
pcf8574:
- id: pcf8574_hub_out_1
i2c_id: bus_relay
address: 0x24
ads1115:
- id: ads1115_hub
i2c_id: bus_ads
address: 0x48
font:
- file: "gfonts://Roboto"
id: font_small
size: 10
- file: "gfonts://Roboto"
id: font_medium
size: 14
globals:
- id: hb1_wet_voltage
type: float
restore_value: yes
initial_value: '1.20'
- id: hb1_dry_voltage
type: float
restore_value: yes
initial_value: '2.70'
- id: hb2_wet_voltage
type: float
restore_value: yes
initial_value: '1.20'
- id: hb2_dry_voltage
type: float
restore_value: yes
initial_value: '2.70'
- id: hb3_wet_voltage
type: float
restore_value: yes
initial_value: '1.20'
- id: hb3_dry_voltage
type: float
restore_value: yes
initial_value: '2.70'
- id: hb4_wet_voltage
type: float
restore_value: yes
initial_value: '1.20'
- id: hb4_dry_voltage
type: float
restore_value: yes
initial_value: '2.70'
switch:
- platform: gpio
name: "Bewässerung Hochbeet 1"
id: b4_relay1
pin:
pcf8574: pcf8574_hub_out_1
number: 4
mode: OUTPUT
inverted: true
restore_mode: ALWAYS_OFF
icon: "mdi:sprinkler-variant"
- platform: gpio
name: "Bewässerung Hochbeet 2"
id: b4_relay2
pin:
pcf8574: pcf8574_hub_out_1
number: 5
mode: OUTPUT
inverted: true
restore_mode: ALWAYS_OFF
icon: "mdi:sprinkler-variant"
- platform: gpio
name: "Bewässerung Hochbeet 3"
id: b4_relay3
pin:
pcf8574: pcf8574_hub_out_1
number: 6
mode: OUTPUT
inverted: true
restore_mode: ALWAYS_OFF
icon: "mdi:sprinkler-variant"
- platform: gpio
name: "Bewässerung Hochbeet 4"
id: b4_relay4
pin:
pcf8574: pcf8574_hub_out_1
number: 7
mode: OUTPUT
inverted: true
restore_mode: ALWAYS_OFF
icon: "mdi:sprinkler-variant"
binary_sensor:
- platform: gpio
name: "Feucht Hochbeet 1"
id: b4_input1
pin:
pcf8574: pcf8574_hub_out_1
number: 0
mode: INPUT
inverted: true
filters:
- delayed_on: 10ms
icon: "mdi:water-opacity"
- platform: gpio
name: "Feucht Hochbeet 2"
id: b4_input2
pin:
pcf8574: pcf8574_hub_out_1
number: 1
mode: INPUT
inverted: true
filters:
- delayed_on: 10ms
icon: "mdi:water-opacity"
- platform: gpio
name: "Feucht Hochbeet 3"
id: b4_input3
pin:
pcf8574: pcf8574_hub_out_1
number: 2
mode: INPUT
inverted: true
filters:
- delayed_on: 10ms
icon: "mdi:water-opacity"
- platform: gpio
name: "Feucht Hochbeet 4"
id: b4_input4
pin:
pcf8574: pcf8574_hub_out_1
number: 3
mode: INPUT
inverted: true
filters:
- delayed_on: 10ms
icon: "mdi:water-opacity"
sensor:
- platform: ads1115
ads1115_id: ads1115_hub
multiplexer: A0_GND
gain: 4.096
resolution: 16_BITS
name: "Feuchtigkeitsmessung V Hochbeet 1"
id: b4_sensor1
update_interval: 2s
unit_of_measurement: "V"
accuracy_decimals: 3
state_class: measurement
icon: "mdi:flash"
- platform: ads1115
ads1115_id: ads1115_hub
multiplexer: A1_GND
gain: 4.096
resolution: 16_BITS
name: "Feuchtigkeitsmessung V Hochbeet 2"
id: b4_sensor2
update_interval: 2s
unit_of_measurement: "V"
accuracy_decimals: 3
state_class: measurement
icon: "mdi:flash"
- platform: ads1115
ads1115_id: ads1115_hub
multiplexer: A2_GND
gain: 4.096
resolution: 16_BITS
name: "Feuchtigkeitsmessung V Hochbeet 3"
id: b4_sensor3
update_interval: 2s
unit_of_measurement: "V"
accuracy_decimals: 3
state_class: measurement
icon: "mdi:flash"
- platform: ads1115
ads1115_id: ads1115_hub
multiplexer: A3_GND
gain: 4.096
resolution: 16_BITS
name: "Feuchtigkeitsmessung V Hochbeet 4"
id: b4_sensor4
update_interval: 2s
unit_of_measurement: "V"
accuracy_decimals: 3
state_class: measurement
icon: "mdi:flash"
- platform: template
name: "Feuchtigkeit Hochbeet 1"
id: b4_moisture_1
unit_of_measurement: "%"
accuracy_decimals: 0
device_class: humidity
state_class: measurement
update_interval: 2s
icon: "mdi:water-percent"
lambda: |-
float wet_voltage = id(hb1_wet_voltage);
float dry_voltage = id(hb1_dry_voltage);
float v = id(b4_sensor1).state;
if (isnan(v) || dry_voltage <= wet_voltage) return NAN;
float p = (dry_voltage - v) * 100.0f / (dry_voltage - wet_voltage);
if (p < 0) p = 0;
if (p > 100) p = 100;
return p;
- platform: template
name: "Feuchtigkeit Hochbeet 2"
id: b4_moisture_2
unit_of_measurement: "%"
accuracy_decimals: 0
device_class: humidity
state_class: measurement
update_interval: 2s
icon: "mdi:water-percent"
lambda: |-
float wet_voltage = id(hb2_wet_voltage);
float dry_voltage = id(hb2_dry_voltage);
float v = id(b4_sensor2).state;
if (isnan(v) || dry_voltage <= wet_voltage) return NAN;
float p = (dry_voltage - v) * 100.0f / (dry_voltage - wet_voltage);
if (p < 0) p = 0;
if (p > 100) p = 100;
return p;
- platform: template
name: "Feuchtigkeit Hochbeet 3"
id: b4_moisture_3
unit_of_measurement: "%"
accuracy_decimals: 0
device_class: humidity
state_class: measurement
update_interval: 2s
icon: "mdi:water-percent"
lambda: |-
float wet_voltage = id(hb3_wet_voltage);
float dry_voltage = id(hb3_dry_voltage);
float v = id(b4_sensor3).state;
if (isnan(v) || dry_voltage <= wet_voltage) return NAN;
float p = (dry_voltage - v) * 100.0f / (dry_voltage - wet_voltage);
if (p < 0) p = 0;
if (p > 100) p = 100;
return p;
- platform: template
name: "Feuchtigkeit Hochbeet 4"
id: b4_moisture_4
unit_of_measurement: "%"
accuracy_decimals: 0
device_class: humidity
state_class: measurement
update_interval: 2s
icon: "mdi:water-percent"
lambda: |-
float wet_voltage = id(hb4_wet_voltage);
float dry_voltage = id(hb4_dry_voltage);
float v = id(b4_sensor4).state;
if (isnan(v) || dry_voltage <= wet_voltage) return NAN;
float p = (dry_voltage - v) * 100.0f / (dry_voltage - wet_voltage);
if (p < 0) p = 0;
if (p > 100) p = 100;
return p;
display:
- platform: ssd1306_i2c
id: b4_display
i2c_id: bus_relay
model: "SSD1306 128x64"
address: 0x3C
update_interval: 2s
lambda: |-
it.printf(0, 0, id(font_small), "Hochbeete");
if (!isnan(id(b4_moisture_1).state))
it.printf(0, 16, id(font_medium), "1:%3.0f%%", id(b4_moisture_1).state);
else
it.printf(0, 16, id(font_medium), "1:---");
if (!isnan(id(b4_moisture_2).state))
it.printf(64, 16, id(font_medium), "2:%3.0f%%", id(b4_moisture_2).state);
else
it.printf(64, 16, id(font_medium), "2:---");
if (!isnan(id(b4_moisture_3).state))
it.printf(0, 40, id(font_medium), "3:%3.0f%%", id(b4_moisture_3).state);
else
it.printf(0, 40, id(font_medium), "3:---");
if (!isnan(id(b4_moisture_4).state))
it.printf(64, 40, id(font_medium), "4:%3.0f%%", id(b4_moisture_4).state);
else
it.printf(64, 40, id(font_medium), "4:---");
uart:
- id: uart_rs485
tx_pin: GPIO38
rx_pin: GPIO39
baud_rate: 9600