106 lines
2.8 KiB
YAML
106 lines
2.8 KiB
YAML
esphome:
|
|
name: tv2
|
|
friendly_name: tv2
|
|
on_boot:
|
|
- then:
|
|
- delay: 1s
|
|
- output.turn_off: relais
|
|
- lambda: 'ESP_LOGD("main", "----- boot -----> Relais OFF !");'
|
|
- output.turn_on: bouton_vert
|
|
- output.turn_off: bouton_rouge
|
|
- delay: 1s
|
|
- output.turn_on: relais
|
|
- lambda: 'ESP_LOGD("main", "----- boot -----> Relais ON !");'
|
|
- output.turn_on: bouton_rouge
|
|
|
|
esp32:
|
|
board: esp32-c6-devkitc-1
|
|
variant: esp32c6
|
|
framework:
|
|
type: esp-idf
|
|
|
|
# Enable logging
|
|
logger:
|
|
|
|
uart:
|
|
tx_pin: GPIO17 # Il faut les inverser !!!!
|
|
rx_pin: GPIO16
|
|
baud_rate: 9600
|
|
# debug:
|
|
# direction: BOTH
|
|
# dummy_receiver: false
|
|
# after:
|
|
# delimiter: "\n"
|
|
# sequence:
|
|
# - lambda: UARTDebug::log_string(direction, bytes);
|
|
|
|
modbus:
|
|
|
|
output:
|
|
- platform: gpio
|
|
pin: GPIO1
|
|
id: relais
|
|
- platform: gpio
|
|
pin: GPIO22
|
|
id: bouton_vert
|
|
- platform: gpio
|
|
pin: GPIO23
|
|
id: bouton_rouge
|
|
# - platform: gpio
|
|
# pin: GPIO21 # essaie GPIO10 d'abord, si ça ne marche pas, tente GPIO21
|
|
# id: led_builtin
|
|
|
|
globals:
|
|
- id: low_power_count
|
|
type: int
|
|
initial_value: '0'
|
|
- id: from_start_count
|
|
type: int
|
|
initial_value: '0'
|
|
- id: puissance_faible
|
|
type: bool
|
|
initial_value: 'false'
|
|
|
|
sensor:
|
|
- platform: pzemac
|
|
address: 4
|
|
power:
|
|
name: "PZEM-004T V3 Power"
|
|
on_value:
|
|
then:
|
|
- lambda: |-
|
|
if (id(from_start_count) < 10) {
|
|
id(from_start_count)++;
|
|
id(bouton_rouge).turn_on();
|
|
id(relais).turn_on();
|
|
ESP_LOGD("main", "--> Relais ON !");
|
|
ESP_LOGD("main", "--> Démarrage... (%d / 10)", id(from_start_count));
|
|
} else {
|
|
if (id(puissance_faible)) {
|
|
id(low_power_count)++;
|
|
ESP_LOGD("main", "--> Puissance faible (%d / 5)", id(low_power_count));
|
|
}
|
|
if (id(low_power_count) >= 5) {
|
|
ESP_LOGD("main", "--> TV OFF !");
|
|
id(relais).turn_off();
|
|
ESP_LOGD("main", "--> Relais OFF !");
|
|
}
|
|
}
|
|
on_value_range:
|
|
- below: 40
|
|
then:
|
|
- lambda: |-
|
|
ESP_LOGD("main", "--> Puissance faible !");
|
|
id(puissance_faible) = true;
|
|
id(bouton_vert).turn_off();
|
|
- above: 40
|
|
then:
|
|
- lambda: |-
|
|
ESP_LOGD("main", "--> Puissance normale.");
|
|
id(puissance_faible) = false;
|
|
id(bouton_vert).turn_on();
|
|
id(relais).turn_on();
|
|
ESP_LOGD("main", "--> Relais ON !");
|
|
id(low_power_count) = 0;
|
|
update_interval: 5s
|