esphome pelmet LEDs, lounge scenes and other fixes
This commit is contained in:
@@ -94,13 +94,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: "1000 hz" # 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
|
||||
device_mosfet_out: GPIO04
|
||||
device_usr_button: GPIO12
|
||||
device_fading_led: GPIO13
|
||||
device_usr_button: GPIO12 # 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
|
||||
@@ -117,8 +117,8 @@ packages:
|
||||
|
||||
#### HOME ASSISTANT API (choose encryption or no encryption options) ####
|
||||
common_api: !include
|
||||
file: common/api_common.yaml
|
||||
#file: common/api_common_noencryption.yaml
|
||||
#file: common/api_common.yaml
|
||||
file: common/api_common_noencryption.yaml
|
||||
vars:
|
||||
local_api_key: "${api_key}"
|
||||
|
||||
@@ -137,7 +137,7 @@ packages:
|
||||
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_resetcount: !include common/include_resetcount_diag_sensors.yaml
|
||||
#diag_resetcount: !include common/include_resetcount_diag_sensors.yaml
|
||||
|
||||
##########################################################################################
|
||||
# ESPHome CORE CONFIGURATION
|
||||
@@ -191,7 +191,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:
|
||||
@@ -239,6 +239,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
|
||||
@@ -400,7 +405,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;
|
||||
@@ -496,10 +500,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: |-
|
||||
@@ -526,18 +531,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
|
||||
@@ -572,6 +575,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}"
|
||||
@@ -591,6 +595,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);'
|
||||
@@ -611,13 +616,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
|
||||
@@ -779,7 +786,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:
|
||||
@@ -816,7 +822,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;
|
||||
@@ -831,7 +836,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:
|
||||
@@ -874,7 +878,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;
|
||||
@@ -892,7 +895,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;'
|
||||
@@ -913,7 +915,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;
|
||||
@@ -973,5 +974,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
|
||||
Reference in New Issue
Block a user