- #21
Tasmota essayé sur un esp32-H2 supermini, ca n'a pas l'air au point pour cette architecture (core dump à gogo).
# Code pour la prise LSC:
substitutions:
voltage_divider: '795'
current_resistor: '0.001'
current_multiply: '0.450'
# Calibrer selon https://esphome.io/components/sensor/hlw8012/
globals:
- id: timer_remaining_seconds
type: int
initial_value: '0'
restore_value: no
button:
- platform: restart
name: Restart
- platform: template
name: "Démarrer Timer"
id: start_timer_btn
icon: mdi:timer-play
on_press:
- script.stop: timer_logic
- script.execute: timer_logic
number:
- platform: template
name: "Durée Timer (min)"
id: timer_duration_input
optimistic: true
min_value: 1
max_value: 240
step: 1
mode: box
initial_value: 30
icon: mdi:timer-cog
sensor:
# Timer Display
- platform: template
name: "Temps Restant"
id: timer_remaining_display
icon: mdi:timer-sand
unit_of_measurement: "min"
accuracy_decimals: 0
lambda: |-
return (id(timer_remaining_seconds) > 0) ? (id(timer_remaining_seconds) / 60.0) : 0;
update_interval: never
# Power Monitoring (BL0937)
- platform: hlw8012
model: BL0937
update_interval: 500ms
change_mode_every: 2
cf_pin:
number: P26
inverted: true
cf1_pin:
number: P24
inverted: true
sel_pin:
number: P11
inverted: true
current:
name: Current
id: current
accuracy_decimals: 3
on_value:
component.update: apparent_power
filters:
- multiply: ${current_multiply}
- sliding_window_moving_average:
window_size: 4
send_every: 2
voltage:
name: Voltage
id: voltage
on_value:
component.update: apparent_power
filters:
- sliding_window_moving_average:
window_size: 4
send_every: 2
power:
name: Power
id: power
on_value:
component.update: power_factor
filters:
- sliding_window_moving_average:
window_size: 4
send_every: 2
energy:
name: Energy
voltage_divider: ${voltage_divider}
current_resistor: ${current_resistor}
# Template Sensors (Calculs)
- platform: template
name: "Apparent power"
id: apparent_power
unit_of_measurement: VA
device_class: apparent_power
lambda: |-
return id(voltage).state * id(current).state;
update_interval: never
on_value:
component.update: power_factor
- platform: template
name: "Power factor"
id: power_factor
unit_of_measurement: ''
device_class: power_factor
lambda: |-
return id(power).state / id(apparent_power).state;
filters:
- clamp:
min_value: 0
max_value: 1
update_interval: never
- platform: uptime
name: Uptime
# --- TEXT SENSORS ---
text_sensor:
- platform: debug
reset_reason:
name: Reset Reason
- platform: libretiny
version:
name: LibreTiny Version
# --- DEBUG ---
debug:
update_interval: 30s
# --- SWITCH & OUTPUTS ---
binary_sensor:
- platform: gpio
id: binary_switch_1
pin:
number: P7
inverted: true
mode: INPUT_PULLUP
filters:
- delayed_on: 10ms
on_press:
then:
- switch.toggle: switch_1
switch:
- platform: gpio
id: switch_1
name: none
pin: P8
restore_mode: ALWAYS_OFF
on_turn_on:
script.execute: set_status_led
on_turn_off:
script.execute: set_status_led
light:
- platform: status_led
id: light_red
name: "Red led"
pin: P6
restore_mode: RESTORE_DEFAULT_OFF
- platform: binary
name: "Status led"
id: blue_led
output: output_blue_led
restore_mode: RESTORE_DEFAULT_OFF
internal: true
output:
- platform: gpio
id: output_blue_led
pin: P10
select:
- platform: template
name: "Status led mode"
id: status_led_mode
optimistic: true
restore_value: True
entity_category: CONFIG
update_interval: never
options:
- "Normal"
- "Invert"
- "Off"
initial_option: "Normal"
on_value:
script.execute: set_status_led
# --- SCRIPTS ---
script:
- id: set_status_led
then:
- if:
condition:
lambda: |-
return strcmp(id(status_led_mode).state.c_str(), "Normal") == 0;
then:
if:
condition:
switch.is_on: switch_1
then:
light.turn_on: blue_led
else:
light.turn_off: blue_led
- if:
condition:
lambda: |-
return strcmp(id(status_led_mode).state.c_str(), "Invert") == 0;
then:
if:
condition:
switch.is_on: switch_1
then:
light.turn_off: blue_led
else:
light.turn_on: blue_led
- if:
condition:
lambda: |-
return strcmp(id(status_led_mode).state.c_str(), "Off") == 0;
then:
light.turn_off: blue_led
- id: timer_logic
then:
- lambda: 'id(timer_remaining_seconds) = id(timer_duration_input).state * 60;'
- component.update: timer_remaining_display
- switch.turn_on: switch_1
- while:
condition:
lambda: 'return id(timer_remaining_seconds) > 0;'
then:
- delay: 1s
- lambda: 'id(timer_remaining_seconds) -= 1;'
- if:
condition:
lambda: 'return (id(timer_remaining_seconds) % 60 == 0) || (id(timer_remaining_seconds) < 60);'
then:
- component.update: timer_remaining_display
- if:
condition:
switch.is_off: switch_1
then:
- lambda: 'id(timer_remaining_seconds) = 0;'
- component.update: timer_remaining_display
- script.stop: timer_logic
- switch.turn_off: switch_1
- lambda: 'id(timer_remaining_seconds) = 0;'
- component.update: timer_remaining_display
ESPhomeJoli, quel firmware utilises tu ?
# Code Prise LSC
substitutions:
voltage_divider: '795'
current_resistor: '0.001'
current_multiply: '0.450'
# Calibrer selon [https://esphome.io/components/sensor/hlw8012/](https://esphome.io/components/sensor/hlw8012/)
globals:
- id: timer_remaining_seconds
type: int
initial_value: '0'
restore_value: no
button:
- platform: restart
name: Restart
- platform: template
name: "Démarrer Timer"
id: start_timer_btn
icon: mdi:timer-play
on_press:
- script.stop: timer_logic
- script.execute: timer_logic
number:
- platform: template
name: "Durée Timer (min)"
id: timer_duration_input
optimistic: true
min_value: 1
max_value: 240
step: 1
mode: box
initial_value: 30
icon: mdi:timer-cog
sensor:
# Timer Display
- platform: template
name: "Temps Restant"
id: timer_remaining_display
icon: mdi:timer-sand
unit_of_measurement: "min"
accuracy_decimals: 0
lambda: |-
return (id(timer_remaining_seconds) > 0) ? (id(timer_remaining_seconds) / 60.0) : 0;
update_interval: never
# Power Monitoring (BL0937)
- platform: hlw8012
model: BL0937
update_interval: 500ms
change_mode_every: 2
cf_pin:
number: P26
inverted: true
cf1_pin:
number: P24
inverted: true
sel_pin:
number: P11
inverted: true
current:
name: Current
id: current
accuracy_decimals: 3
on_value:
component.update: apparent_power
filters:
- multiply: ${current_multiply}
- sliding_window_moving_average:
window_size: 4
send_every: 2
voltage:
name: Voltage
id: voltage
on_value:
component.update: apparent_power
filters:
- sliding_window_moving_average:
window_size: 4
send_every: 2
power:
name: Power
id: power
on_value:
component.update: power_factor
filters:
- sliding_window_moving_average:
window_size: 4
send_every: 2
energy:
name: Energy
voltage_divider: ${voltage_divider}
current_resistor: ${current_resistor}
# Template Sensors (Calculs)
- platform: template
name: "Apparent power"
id: apparent_power
unit_of_measurement: VA
device_class: apparent_power
lambda: |-
return id(voltage).state * id(current).state;
update_interval: never
on_value:
component.update: power_factor
- platform: template
name: "Power factor"
id: power_factor
unit_of_measurement: ''
device_class: power_factor
lambda: |-
if (id(apparent_power).state == 0) return 0;
return id(power).state / id(apparent_power).state;
filters:
- clamp:
min_value: 0
max_value: 1
update_interval: never
- platform: uptime
name: Uptime
# --- TEXT SENSORS ---
text_sensor:
- platform: debug
reset_reason:
name: Reset Reason
- platform: libretiny
version:
name: LibreTiny Version
# --- DEBUG ---
debug:
update_interval: 30s
# --- SWITCH & OUTPUTS ---
binary_sensor:
- platform: gpio
id: binary_switch_1
pin:
number: P7
inverted: true
mode: INPUT_PULLUP
filters:
- delayed_on: 10ms
on_multi_click:
- timing:
- ON for at most 1s
- OFF for at most 1s
- ON for at most 1s
then:
- logger.log: "Double Clic -> Timer !"
- script.stop: timer_logic
- script.execute: timer_logic
- timing:
- ON for at most 1s
- OFF for at least 0.5s
then:
- switch.toggle: switch_1
switch:
- platform: gpio
id: switch_1
name: none
pin: P8
restore_mode: ALWAYS_OFF
on_turn_on:
script.execute: set_status_led
on_turn_off:
script.execute: set_status_led
- platform: template
name: "Mode Fin de Charge Auto"
id: auto_off_mode
optimistic: true
icon: mdi:battery-charging-100
restore_mode: RESTORE_DEFAULT_OFF # Par défaut désactivé au démarrage pour sécurité
light:
- platform: status_led
id: light_red
name: "Red led"
pin: P6
restore_mode: RESTORE_DEFAULT_OFF
- platform: binary
name: "Status led"
id: blue_led
output: output_blue_led
restore_mode: RESTORE_DEFAULT_OFF
internal: true
output:
- platform: gpio
id: output_blue_led
pin: P10
select:
- platform: template
name: "Status led mode"
id: status_led_mode
optimistic: true
restore_value: True
entity_category: CONFIG
update_interval: never
options:
- "Normal"
- "Invert"
- "Off"
initial_option: "Normal"
on_value:
script.execute: set_status_led
# --- INTERVAL CHECK FOR AUTO OFF ---
interval:
- interval: 10s
then:
- if:
condition:
and:
- switch.is_on: auto_off_mode
- switch.is_on: switch_1
# On vérifie si la puissance est < 5W
- lambda: 'return id(power).state < 5.0;'
then:
# Lancement du script de délai (qui s'arrête si condition fausse)
- script.execute: check_low_power_shutdown
else:
# Si la puissance remonte ou mode désactivé, on annule
- script.stop: check_low_power_shutdown
# --- SCRIPTS ---
script:
- id: set_status_led
then:
- if:
condition:
lambda: |-
return strcmp(id(status_led_mode).state.c_str(), "Normal") == 0;
then:
if:
condition:
switch.is_on: switch_1
then:
light.turn_on: blue_led
else:
light.turn_off: blue_led
- if:
condition:
lambda: |-
return strcmp(id(status_led_mode).state.c_str(), "Invert") == 0;
then:
if:
condition:
switch.is_on: switch_1
then:
light.turn_off: blue_led
else:
light.turn_on: blue_led
- if:
condition:
lambda: |-
return strcmp(id(status_led_mode).state.c_str(), "Off") == 0;
then:
light.turn_off: blue_led
- id: timer_logic
then:
- lambda: 'id(timer_remaining_seconds) = id(timer_duration_input).state * 60;'
- component.update: timer_remaining_display
- switch.turn_on: switch_1
- while:
condition:
lambda: 'return id(timer_remaining_seconds) > 0;'
then:
- delay: 1s
- lambda: 'id(timer_remaining_seconds) -= 1;'
- if:
condition:
lambda: 'return (id(timer_remaining_seconds) % 60 == 0) || (id(timer_remaining_seconds) < 60);'
then:
- component.update: timer_remaining_display
- if:
condition:
switch.is_off: switch_1
then:
- lambda: 'id(timer_remaining_seconds) = 0;'
- component.update: timer_remaining_display
- script.stop: timer_logic
- switch.turn_off: switch_1
- lambda: 'id(timer_remaining_seconds) = 0;'
- component.update: timer_remaining_display
- id: check_low_power_shutdown
mode: restart
then:
- delay: 2min
- logger.log: "Charge terminée (<5W). Arrêt automatique."
- switch.turn_off: switch_1
- switch.turn_off: auto_off_mode
Hello, le fichier UF2 est totalement personnel dans mon cas, il contient toutes les données wifi et la clé de chiffrage.le fichier UF2 à disposition