esphome pelmet LEDs, lounge scenes and other fixes

This commit is contained in:
root
2025-10-12 19:54:03 +13:00
parent e96344e3ad
commit bcf514a041
19 changed files with 951 additions and 1542 deletions
+30 -29
View File
@@ -83,13 +83,13 @@ substitutions:
minimum_led_output: "1" # % If at this value or below, we'll switch it completely off
maximum_led_output: "90" # % Maximum output; it is sometimes nice to limit the output for longevity or aesthetics
max_on_default_hours: "24" # The maximum time the LEDs will be on, in case they get left on. 0 = no automatic turn-off
pwm_frequency: "1000hz" # PWM output Frequency. High enough to avoid audible/visible artifacts
pwm_frequency: "1000" # PWM output Frequency in Hz. High enough to avoid audible/visible artifacts
# Device Specific GPIO (so we can easily update for other devices)
device_status_led: GPIO02 # Can't really see if there is an LED
device_status_led: GPIO02
device_mosfet_out: GPIO12
device_usr_button: GPIO04 # this is just a fake/safeish choice so it compiles with my generic yaml
device_fading_led: GPIO13 # this is just a fake/safeish choice so it compiles with my generic yaml
device_usr_button: GPIO04 # if no button, this is just a fake/safeish choice so it compiles with the generic yaml
device_fading_led: GPIO13 # if no LED, this is just a fake/safeish choice so it compiles with the generic yaml
##########################################################################################
# PACKAGES: Included Common Packages
@@ -124,8 +124,8 @@ packages:
#### DIAGNOSTICS Sensors ####
diag_basic: !include common/include_basic_diag_sensors.yaml
#diag_more: !include common/include_more_diag_sensors.yaml
#diag_debug: !include common/include_debug_diag_sensors.yaml
diag_more: !include common/include_more_diag_sensors.yaml
diag_debug: !include common/include_debug_diag_sensors.yaml
#diag_resetcount: !include common/include_resetcount_diag_sensors.yaml
##########################################################################################
@@ -180,7 +180,7 @@ esphome:
- lambda: 'id(booting) = false;'
# NEW: force indicator OFF after boot logic
- output.turn_off: green_led_out
# (Removed: output.turn_off: green_led_out)
# Only if you want to play with build flags...
# platformio_options:
@@ -228,6 +228,11 @@ globals:
type: int
restore_value: true
initial_value: "${max_on_default_hours}"
# Compile time Gamma
- id: led_gamma_f
type: float
restore_value: false
initial_value: ${led_gamma} # <-- numeric at compile time
# Default Fading Up Time (Selectable and will be retained)
- id: ramp_up_ms # fade-in when turned ON
@@ -389,7 +394,6 @@ button:
# Stop any pending scripts (and their delayed actions)
- script.stop: ramp_on_script
- script.stop: ramp_off_script
- output.turn_off: green_led_out
- lambda: |-
// We are no longer ramping (up or down)
id(ramping_for_off) = false;
@@ -485,10 +489,11 @@ sensor:
unit_of_measurement: "%"
icon: mdi:percent
accuracy_decimals: 0
update_interval: 1s # consider 200ms if you want fewer updates
update_interval: 2s # consider 200ms if you want fewer updates
lambda: |-
const auto &cv = id(mosfet_leds).current_values;
return cv.is_on() ? (cv.get_brightness() * 100.0f) : 0.0f;
return cv.is_on() ? (float) (int)(cv.get_brightness() * 100.0f + 0.5f) : 0.0f;
on_value:
then:
- lambda: |-
@@ -515,18 +520,16 @@ sensor:
unit_of_measurement: "%"
icon: mdi:square-wave
accuracy_decimals: 1
update_interval: 1s
update_interval: 2s
lambda: |-
const auto &cv = id(mosfet_leds).current_values;
if (!cv.is_on()) return 0.0f;
const float lin = cv.get_brightness(); // 0..1 linear brightness
const float gamma = atof("${led_gamma}"); // parse substitution string -> float
float pwm = powf(lin, gamma); // approx PWM duty after gamma
const float lin = cv.get_brightness();
float pwm = powf(lin, id(led_gamma_f));
if (pwm < 0.0f) pwm = 0.0f;
if (pwm > 1.0f) pwm = 1.0f;
return pwm * 100.0f;
##########################################################################################
# OUTPUT COMPONENT
# https://esphome.io/components/light/index.html
@@ -561,6 +564,7 @@ light:
# ON: publish state, track intent, arm watchdog if configured
on_turn_on:
- output.turn_on: green_led_out
- mqtt.publish:
topic: "${mqtt_local_status_topic}/light/state"
payload: "${mqtt_local_device_command_ON}"
@@ -580,6 +584,7 @@ light:
# OFF: publish state, track intent, clear watchdog, and persist OFF so Mode 1 will not restore
# Guarded by booting flag so the automatic OFF at boot from ALWAYS_OFF does not zero persistence.
on_turn_off:
- output.turn_off: green_led_out
- if:
condition:
lambda: 'return !id(booting);'
@@ -600,13 +605,15 @@ light:
- lambda: |-
const float cap = id(max_brightness_pct) / 100.0f;
const auto &cv = id(mosfet_leds).current_values;
if (cv.is_on() && cv.get_brightness() > cap + 0.001f) {
auto call = id(mosfet_leds).make_call();
call.set_state(true);
call.set_brightness(cap);
call.set_transition_length(0);
call.perform();
}
if (!cv.is_on()) return;
const float b = cv.get_brightness();
if (b <= cap + 0.001f) return; // no call if already at/under cap
auto call = id(mosfet_leds).make_call();
call.set_state(true);
call.set_brightness(cap);
call.set_transition_length(0);
call.perform();
##########################################################################################
# NUMBER COMPONENT
@@ -768,7 +775,6 @@ script:
then:
- lambda: 'id(is_ramping) = true;'
- script.stop: ramp_off_script
- output.turn_on: green_led_out
# Ensure we start at at least the floor without a visible "pop".
- if:
condition:
@@ -805,7 +811,6 @@ script:
id(last_ramp_ms) = (int) (id(ramp_up_ms) * frac);
return (uint32_t) id(last_ramp_ms);
- delay: !lambda 'return (uint32_t) id(last_ramp_ms);'
- output.turn_off: green_led_out
- lambda: |-
id(is_ramping) = false;
const auto &cv = id(mosfet_leds).current_values;
@@ -820,7 +825,6 @@ script:
then:
- lambda: 'id(is_ramping) = true;'
- script.stop: ramp_off_script
- output.turn_on: green_led_out
# Ensure we start at the floor cleanly.
- if:
condition:
@@ -863,7 +867,6 @@ script:
id(last_ramp_ms) = (int) (id(ramp_up_ms) * frac);
return (uint32_t) id(last_ramp_ms);
- delay: !lambda 'return (uint32_t) id(last_ramp_ms);'
- output.turn_off: green_led_out
- lambda: |-
id(is_ramping) = false;
const auto &cv = id(mosfet_leds).current_values;
@@ -881,7 +884,6 @@ script:
id(is_ramping) = true;
id(ramping_for_off) = true;
- script.stop: ramp_on_script
- output.turn_on: green_led_out
- light.turn_on:
id: mosfet_leds
brightness: !lambda 'return id(min_brightness_pct) / 100.0f;'
@@ -902,7 +904,6 @@ script:
id: mosfet_leds
transition_length: 150ms
- delay: 150ms
- output.turn_off: green_led_out
- lambda: |-
id(is_ramping) = false;
id(ramping_for_off) = false;
@@ -962,4 +963,4 @@ script:
- light.turn_off:
id: mosfet_leds
transition_length: 0s
- output.turn_off: green_led_out # make sure LED is off if no ramp
# (Removed: output.turn_off: green_led_out) # make sure LED is off if no ramp