Edit esp-loungecabinetleds.yaml

This commit is contained in:
ESPHome Device Builder
2026-07-20 19:44:53 +12:00
parent 2b6b91f829
commit dcd43a18c1
+42 -42
View File
@@ -6,6 +6,7 @@
# https://home.fox.co.nz/gitea/zorruno/zorruno-homeassistant/src/branch/master/esphome/esp-loungecabinetleds.yaml
#:########################################################################################:#
# VERSIONS:
# V2.2 2026-07-20 Simplified local MQTT command and status topics to the device root
# V2.1 2026-03-11 Updated yaml to zorruno layout V1.1
# V2.0 2025-09-15 A bunch of fixes, this is now the master for other similar mosfet controllers of mine
# V1.5 2025-09-11 First setup (copied from another template)
@@ -50,10 +51,10 @@
# - Maximum ON time before automatic fade-down (1-48 h, 0 = no limit)
#
# MQTT COMMANDS:
# - ${mqtt_local_command_topic}/light/set = ON
# - ${mqtt_local_command_topic}/light/set = OFF
# - ${mqtt_local_command_topic} = ON
# - ${mqtt_local_command_topic} = OFF
# - State publishes to:
# - ${mqtt_local_status_topic}/light/state
# - ${mqtt_local_status_topic}
#:########################################################################################:#
# OFFLINE NOTES:
# a) Home Assistant offline (network and MQTT online)
@@ -80,7 +81,7 @@ substitutions:
# Project Naming
project_name: "Sinilink.XY-WFMS" # Project details. Manufacturer before the dot, device after the dot.
project_version: "v2.1" # Project version denotes release of the YAML file, allowing checking of deployed vs latest version
project_version: "v2.2" # Project version denotes release of the YAML file, allowing checking of deployed vs latest version
# Passwords & Secrets (Unfortunately, you can't use substitutions inside secret names)
api_key: !secret esp-api_key # If using HA API
@@ -130,8 +131,7 @@ packages:
local_current_ip_address: "${current_ip_address}"
#### HOME ASSISTANT API (choose encryption or no encryption options) ####
common_api: !include
#file: common/api_common.yaml
common_api: !include #file: common/api_common.yaml
file: common/api_common_noencryption.yaml
vars:
local_api_key: "${api_key}"
@@ -181,32 +181,32 @@ esphome:
# Mode 0: Fade up to full (obeys fade settings; no on/off flicker)
- if:
condition:
lambda: 'return id(restart_mode) == 0;'
lambda: "return id(restart_mode) == 0;"
then:
- lambda: 'id(ramp_switch_target_on) = true;'
- lambda: "id(ramp_switch_target_on) = true;"
- script.execute: ramp_on_script
# Mode 1: Restore Brightness (deferred to avoid races)
- if:
condition:
lambda: 'return id(restart_mode) == 1;'
lambda: "return id(restart_mode) == 1;"
then:
- script.execute: deferred_restore_brightness
# Mode 2: Remain Off (no blip; stays off)
- if:
condition:
lambda: 'return id(restart_mode) == 2;'
lambda: "return id(restart_mode) == 2;"
then:
- script.stop: ramp_on_script
- script.stop: ramp_off_script
- lambda: 'id(ramp_switch_target_on) = false;'
- lambda: "id(ramp_switch_target_on) = false;"
- light.turn_off:
id: mosfet_leds
transition_length: 0s
# Boot complete: allow OFF handlers again
- lambda: 'id(booting) = false;'
- lambda: "id(booting) = false;"
# NEW: force indicator OFF after boot logic
# (Removed: output.turn_off: green_led_out)
@@ -365,13 +365,13 @@ status_led:
mqtt:
on_message:
# Light control to ramp up
- topic: "${mqtt_local_command_topic}/light/set"
- topic: "${mqtt_local_command_topic}"
payload: "${mqtt_local_device_command_ON}"
then:
- switch.turn_on: mosfet_ramp_switch
# Light control to ramp down
- topic: "${mqtt_local_command_topic}/light/set"
- topic: "${mqtt_local_command_topic}"
payload: "${mqtt_local_device_command_OFF}"
then:
- switch.turn_off: mosfet_ramp_switch
@@ -503,7 +503,7 @@ binary_sensor:
on_press:
- if:
condition:
lambda: 'return id(ramp_switch_target_on);'
lambda: "return id(ramp_switch_target_on);"
then:
# Target is currently ON -> press should go OFF (start ramp-down)
- lambda: |-
@@ -608,7 +608,7 @@ light:
on_turn_on:
- output.turn_on: green_led_out
- mqtt.publish:
topic: "${mqtt_local_status_topic}/light/state"
topic: "${mqtt_local_status_topic}"
payload: "${mqtt_local_device_command_ON}"
retain: true
- lambda: |-
@@ -619,7 +619,7 @@ light:
- script.stop: max_on_watchdog
- if:
condition:
lambda: 'return id(max_on_hours) > 0;'
lambda: "return id(max_on_hours) > 0;"
then:
- script.execute: max_on_watchdog
@@ -629,13 +629,13 @@ light:
- output.turn_off: green_led_out
- if:
condition:
lambda: 'return !id(booting);'
lambda: "return !id(booting);"
then:
- mqtt.publish:
topic: "${mqtt_local_status_topic}/light/state"
topic: "${mqtt_local_status_topic}"
payload: "${mqtt_local_device_command_OFF}"
retain: true
- lambda: 'id(ramp_switch_target_on) = false;'
- lambda: "id(ramp_switch_target_on) = false;"
- script.stop: max_on_watchdog
- lambda: |-
id(last_brightness_pct) = 0.0f;
@@ -724,10 +724,10 @@ number:
set_action:
- if:
condition:
lambda: 'return x <= 0.0f;'
lambda: "return x <= 0.0f;"
then:
# 0 means OFF
- lambda: 'id(suppress_slider_sync) = true;'
- lambda: "id(suppress_slider_sync) = true;"
- script.stop: ramp_on_script
- script.stop: ramp_off_script
- light.turn_off:
@@ -739,7 +739,7 @@ number:
id(last_brightness_pct) = 0.0f; // persist OFF immediately
id(last_set_pos) = 0;
- delay: 400ms
- lambda: 'id(suppress_slider_sync) = false;'
- lambda: "id(suppress_slider_sync) = false;"
else:
# Map 1..100 - [min..max] and set ON
- lambda: |-
@@ -771,7 +771,7 @@ number:
if (out_pct > maxp) out_pct = maxp;
id(last_brightness_pct) = out_pct; // persist exact target now
- delay: 400ms
- lambda: 'id(suppress_slider_sync) = false;'
- lambda: "id(suppress_slider_sync) = false;"
- platform: template
id: cfg_max_on_hours
@@ -794,12 +794,12 @@ number:
id(cfg_max_on_hours).publish_state((float) hrs);
- if:
condition:
lambda: 'return id(mosfet_leds).current_values.is_on();'
lambda: "return id(mosfet_leds).current_values.is_on();"
then:
- script.stop: max_on_watchdog
- if:
condition:
lambda: 'return id(max_on_hours) > 0;'
lambda: "return id(max_on_hours) > 0;"
then:
- script.execute: max_on_watchdog
@@ -813,7 +813,7 @@ script:
- id: ramp_on_script
mode: restart
then:
- lambda: 'id(is_ramping) = true;'
- lambda: "id(is_ramping) = true;"
- script.stop: ramp_off_script
# Ensure we start at at least the floor without a visible "pop".
- if:
@@ -825,12 +825,12 @@ script:
then:
- light.turn_on:
id: mosfet_leds
brightness: !lambda 'return id(min_brightness_pct) / 100.0f;'
brightness: !lambda "return id(min_brightness_pct) / 100.0f;"
transition_length: 80ms
# Ramp from current (>= floor) to cap over a fraction of ramp_up_ms.
- light.turn_on:
id: mosfet_leds
brightness: !lambda 'return id(max_brightness_pct) / 100.0f;'
brightness: !lambda "return id(max_brightness_pct) / 100.0f;"
transition_length: !lambda |-
const auto &cv = id(mosfet_leds).current_values;
const float floor = id(min_brightness_pct) / 100.0f;
@@ -850,7 +850,7 @@ script:
if (frac > 1.0f) frac = 1.0f;
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);'
- delay: !lambda "return (uint32_t) id(last_ramp_ms);"
- lambda: |-
id(is_ramping) = false;
const auto &cv = id(mosfet_leds).current_values;
@@ -863,7 +863,7 @@ script:
- id: ramp_to_target_script
mode: restart
then:
- lambda: 'id(is_ramping) = true;'
- lambda: "id(is_ramping) = true;"
- script.stop: ramp_off_script
# Ensure we start at the floor cleanly.
- if:
@@ -875,7 +875,7 @@ script:
then:
- light.turn_on:
id: mosfet_leds
brightness: !lambda 'return id(min_brightness_pct) / 100.0f;'
brightness: !lambda "return id(min_brightness_pct) / 100.0f;"
transition_length: 80ms
# Ramp from current (>= floor) to restore_target_pct over a fraction of ramp_up_ms.
- light.turn_on:
@@ -906,7 +906,7 @@ script:
if (frac > 1.0f) frac = 1.0f;
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);'
- delay: !lambda "return (uint32_t) id(last_ramp_ms);"
- lambda: |-
id(is_ramping) = false;
const auto &cv = id(mosfet_leds).current_values;
@@ -925,7 +925,7 @@ script:
- script.stop: ramp_on_script
- light.turn_on:
id: mosfet_leds
brightness: !lambda 'return id(min_brightness_pct) / 100.0f;'
brightness: !lambda "return id(min_brightness_pct) / 100.0f;"
transition_length: !lambda |-
const auto &cv = id(mosfet_leds).current_values;
const float floor = id(min_brightness_pct) / 100.0f;
@@ -938,7 +938,7 @@ script:
if (frac > 1.0f) frac = 1.0f;
id(last_ramp_ms) = (int) (id(ramp_down_ms) * frac);
return (uint32_t) id(last_ramp_ms);
- delay: !lambda 'return (uint32_t) id(last_ramp_ms);'
- delay: !lambda "return (uint32_t) id(last_ramp_ms);"
- light.turn_off:
id: mosfet_leds
transition_length: 150ms
@@ -955,12 +955,12 @@ script:
then:
- if:
condition:
lambda: 'return id(max_on_hours) > 0;'
lambda: "return id(max_on_hours) > 0;"
then:
- delay: !lambda 'return (uint32_t) (id(max_on_hours) * 3600000UL);'
- delay: !lambda "return (uint32_t) (id(max_on_hours) * 3600000UL);"
- if:
condition:
lambda: 'return id(mosfet_leds).current_values.is_on();'
lambda: "return id(mosfet_leds).current_values.is_on();"
then:
- lambda: |-
id(ramp_switch_target_on) = false;
@@ -987,18 +987,18 @@ script:
- if:
condition:
lambda: 'return id(restore_target_pct) > 0.5f;'
lambda: "return id(restore_target_pct) > 0.5f;"
then:
- lambda: |-
id(ramp_switch_target_on) = true; // reflect our intent
id(suppress_slider_sync) = true;
- script.stop: ramp_off_script
- script.execute: ramp_to_target_script
- delay: !lambda 'return (uint32_t) id(last_ramp_ms);'
- lambda: 'id(suppress_slider_sync) = false;'
- delay: !lambda "return (uint32_t) id(last_ramp_ms);"
- lambda: "id(suppress_slider_sync) = false;"
else:
# Exact last was 0 -> remain OFF
- lambda: 'id(ramp_switch_target_on) = false;'
- lambda: "id(ramp_switch_target_on) = false;"
- light.turn_off:
id: mosfet_leds
transition_length: 0s