more esphome devices and fixes
This commit is contained in:
+280
-221
@@ -1,83 +1,95 @@
|
||||
##########################################################################################
|
||||
##########################################################################################
|
||||
# Title: LOUNGE - PELMET LEDS (H801, 2x Monochrome PWM)
|
||||
# Repo: (new)
|
||||
#:########################################################################################:#
|
||||
# TITLE: LOUNGE - PELMET LEDS (H801, 2x Monochrome PWM)
|
||||
# zorruno.com layout v1.1 2026
|
||||
#:########################################################################################:#
|
||||
# REPO:
|
||||
# https://home.fox.co.nz/gitea/zorruno/zorruno-homeassistant/src/branch/master/esphome/esp-loungepelmetleds2.yaml
|
||||
#:########################################################################################:#
|
||||
# VERSIONS:
|
||||
# V2.8 2026-03-11 Updated yaml to zorruno layout V1.1
|
||||
# V2.7 2025-09-30 A bunch of fixes for final version
|
||||
# V2.0 2025-09-30 Based on single MOSFET version; adapted to H801 dual-monochrome (A/B)
|
||||
# V1.x History from single-channel base maintained in prior comments
|
||||
#:########################################################################################:#
|
||||
# HARDWARE:
|
||||
# - H801 (ESP8266, 5 MOSFET outputs)
|
||||
# - Used here as 2 independent monochrome PWM channels (A and B)
|
||||
# - Reference hardware:
|
||||
# https://devices.esphome.io/devices/Sinilink-XY-WFMS
|
||||
# - Device GPIO as used here:
|
||||
# - GPIO02 Blue status LED, active-low (ESPHome status)
|
||||
# - GPIO15 MOSFET output A (PWM)
|
||||
# - GPIO13 MOSFET output B (PWM)
|
||||
# - GPIO05 Red LED (used to display status for Channel A)
|
||||
# - GPIO01 Green LED (used to display status for Channel B) [UART TX, logger baud=0]
|
||||
#:########################################################################################:#
|
||||
# OPERATION NOTES:
|
||||
# - General-purpose LED controller using an H801 board.
|
||||
# - Designed for 2 independent monochrome outputs:
|
||||
# - Channel A
|
||||
# - Channel B
|
||||
# - Minimum and maximum output limits are defined in SUBSTITUTIONS per channel.
|
||||
# - Minimum output allows the light to switch fully OFF at or below the threshold to avoid low-PWM flicker.
|
||||
# - PWM frequency is set in SUBSTITUTIONS.
|
||||
# - Restart behaviours:
|
||||
# - Fade up to full
|
||||
# - Restore Brightness
|
||||
# - Remain Off
|
||||
# - Fade timing scales with the configured values.
|
||||
# - Exposed in Home Assistant for both A and B:
|
||||
# - Restart action
|
||||
# - Fade Up-Down switch
|
||||
# - Fade up/down times
|
||||
# - Output percentage
|
||||
# - Output Set slider
|
||||
# - Shared maximum ON time
|
||||
# - Fade Up-Down switch auto-syncs to brightness thresholds and does not itself trigger a ramp during sync.
|
||||
# - This yaml currently uses Home Assistant API and diagnostics packages.
|
||||
# - MQTT and SNTP packages are currently disabled in this file.
|
||||
#:########################################################################################:#
|
||||
# OFFLINE NOTES:
|
||||
# a) Home Assistant offline (network online):
|
||||
# - Device continues to run its local light logic and stored restart behaviour.
|
||||
# - Existing light states, watchdog timers, and fades continue locally.
|
||||
# - No Home Assistant control is available until API connectivity returns.
|
||||
#
|
||||
# v2.7 - a bunch of fixes for final version
|
||||
# v2.0-dual - 2025-09-30 Based on single MOSFET version; adapted to H801 dual-monochrome (A/B).
|
||||
# v1.x (history from single-channel base maintained in comments below)
|
||||
# b) MQTT offline (or HA/MQTT offline):
|
||||
# - MQTT is not enabled in this yaml, so MQTT offline has no direct effect on device logic.
|
||||
# - If Home Assistant/API is also offline, control from HA is unavailable.
|
||||
#
|
||||
# ------------------------------------------
|
||||
# OPERATION (as of v2.x)
|
||||
# ------------------------------------------
|
||||
# 1. General-purpose LED controller.
|
||||
# 2. Designed here for the H801 5-MOSFET board (ESP8266). Using 2 channels as independent
|
||||
# monochrome outputs (A and B). The remaining 3 MOSFETs are ignored.
|
||||
# 3. (In SUBSTITUTIONS) setting for MAX % output to extend LED life (ie can ensure it is only ever 95%)
|
||||
# 4. (In SUBSTITUTIONS) Minimum output setting; switches fully OFF at/below the minimum to avoid low-PWM flicker.
|
||||
# 5. (In SUBSTITUTIONS) PWM frequency is set to 1kHz by default. You can increase it, but higher values caused
|
||||
# resets on some ESP8266 boards. On ESP32 you can run much higher (~40 kHz).
|
||||
# 6. Min/Max output settings are not exposed in Home Assistant/MQTT by default, but could be.
|
||||
# With a 1 MB flash, space is tight and only minimal optimisation has been done so far.
|
||||
# 7. (PACKAGES) include common items: network settings, diagnostic entities, MQTT, and SNTP (optional).
|
||||
# 8. Default behaviours, for recovery from lost power or reset:
|
||||
# - "Fade up to full": fade from floor to max on boot.
|
||||
# - "Restore Brightness": fade from floor to the last non-zero brightness on boot (no on/off blip/flash).
|
||||
# - "Remain Off": stays off on boot.
|
||||
# 9. The board LEDs show output on status. Channel A uses the **RED** LED on GPIO5.
|
||||
# Channel B uses the **GREEN** LED on GPIO1 (UART TX; logger baud=0)
|
||||
# 10. Fade timing scales with the configured values (proportionally when starting mid-brightness).
|
||||
# 11. Exposed in Home Assistant/MQTT (duplicated for A and B):
|
||||
# - Startup action (On,Off,Restore)
|
||||
# - Fade Up/Down toggle switch
|
||||
# - Normal On/Off switch (quick ramp up/down)
|
||||
# - Fade up/down times (0-60s)
|
||||
# - Output % (pre-gamma)
|
||||
# - Output Set (1-100, respects min/max). This also changes with other output so reflects value.
|
||||
# - Many device diagnostics (from the included 'diagnostics' package)
|
||||
# - Maximum 'on' time before automatic fade-down (1-48 h, 0 = no limit)
|
||||
# 12. The Fade Up/Down switch auto-syncs to brightness (no ramp is triggered by the sync itself):
|
||||
# - Stops <33% of cap → switch shows OFF
|
||||
# - Stops >66% of cap → switch shows ON
|
||||
###########################################################################################
|
||||
# Hardware: H801 (ESP8266, 5 MOSFET outputs)
|
||||
# ------------------------------------------
|
||||
# DEVICE GPIO (H801, as used here)
|
||||
# ------------------------------------------
|
||||
# GPIO02 Blue Status LED, active-low (ESPHOME status)
|
||||
# GPIO12 MOSFET output A (PWM)
|
||||
# GPIO13 MOSFET output B (PWM)
|
||||
# GPIO05 Red LED (used to display status for Channel A)
|
||||
# GPIO01 Green LED (used to display status for Channel B) [UART TX, logger baud=0]
|
||||
#
|
||||
##########################################################################################
|
||||
##########################################################################################
|
||||
# c) Entire WiFi/Network offline:
|
||||
# - Device continues to run its local light logic and stored restart behaviour.
|
||||
# - No HA or MQTT control is available.
|
||||
# - Accurate time is not needed; SNTP is not required for operation.
|
||||
#:########################################################################################:#
|
||||
|
||||
##########################################################################################
|
||||
# SPECIFIC DEVICE VARIABLE SUBSTITUTIONS
|
||||
#:########################################################################################:#
|
||||
# SUBSTITUTIONS:
|
||||
# Specific device variable substitutions
|
||||
# If NOT using a secrets file, just replace these with the passwords etc (in quotes)
|
||||
##########################################################################################
|
||||
#:########################################################################################:#
|
||||
substitutions:
|
||||
# Device Naming
|
||||
device_name: "esp-loungepelmetleds2" # yaml file should be device_name.yaml
|
||||
friendly_name: "Lounge Pelmet LEDs"
|
||||
description_comment: "Lounge Pelmet LEDs :: H801 dual-channel monochrome"
|
||||
description_comment: "Lounge Pelmet LEDs :: H801 dual-channel monochrome (Layout V1.1)"
|
||||
device_area: "Lounge" # Allows the ESP device to be automatically linked to an 'Area' in Home Assistant.
|
||||
|
||||
# Project Naming
|
||||
project_name: "H801.5xMOSFET" # Manufacturer before the dot, device after the dot.
|
||||
project_version: "v2.7" # Project version denotes release of the YAML file
|
||||
project_version: "v2.8" # Project version denotes release of the YAML file
|
||||
|
||||
# Passwords & Secrets (Unfortunately, you can't use substitutions inside secret names)
|
||||
# Passwords & Secrets (Unfortunately, you can't use substitutions inside secret names)
|
||||
api_key: !secret esp-api_key
|
||||
ota_pass: !secret esp-ota_pass
|
||||
static_ip_address: !secret esp-loungepelmetleds2_ip # CHANGE THIS
|
||||
|
||||
ota_pass: !secret esp-ota_pass
|
||||
static_ip_address: !secret esp-loungepelmetleds2_ip
|
||||
current_ip_address: ${static_ip_address}
|
||||
|
||||
# Device Specific Settings (shared defaults applied per channel below)
|
||||
log_level: "NONE" # Use INFO while testing; flip back to NONE later
|
||||
update_interval: "60s"
|
||||
led_gamma: "1.6"
|
||||
pwm_frequency: "1000Hz"
|
||||
log_level: "NONE" # Use INFO while testing; flip back to NONE later
|
||||
update_interval: "60s"
|
||||
led_gamma: "1.6"
|
||||
pwm_frequency: "1000Hz"
|
||||
max_on_default_hours: "24"
|
||||
|
||||
# Per-channel output caps (%), internal-only (no HA sliders)
|
||||
@@ -87,49 +99,64 @@ substitutions:
|
||||
maximum_led_output_B: "90"
|
||||
|
||||
# Device Specific GPIO
|
||||
#device_status_led: GPIO05
|
||||
#device_status_led: GPIO5
|
||||
device_mosfet_out_A: GPIO15
|
||||
device_mosfet_out_B: GPIO13
|
||||
device_fading_led_A: GPIO05
|
||||
device_fading_led_B: GPIO01
|
||||
device_fading_led_A: GPIO5
|
||||
device_fading_led_B: GPIO1
|
||||
|
||||
##########################################################################################
|
||||
# PACKAGES
|
||||
##########################################################################################
|
||||
#:########################################################################################:#
|
||||
# PACKAGES:
|
||||
# Included Common Packages
|
||||
# https://esphome.io/components/packages.html
|
||||
#:########################################################################################:#
|
||||
packages:
|
||||
#### WIFI, Network (Static/DHCP/IPV6 etc), Fallback AP, Safemode ####
|
||||
common_wifi: !include
|
||||
file: common/network_common.yaml
|
||||
vars:
|
||||
local_device_name: "${device_name}"
|
||||
local_static_ip_address: "${static_ip_address}"
|
||||
local_current_ip_address: "${current_ip_address}"
|
||||
local_ota_pass: "${ota_pass}"
|
||||
|
||||
#### HOME ASSISTANT API (choose encryption or no encryption options) ####
|
||||
common_api: !include
|
||||
#file: common/api_common.yaml
|
||||
file: common/api_common_noencryption.yaml
|
||||
vars:
|
||||
local_api_key: "${api_key}"
|
||||
|
||||
#### MQTT ####
|
||||
#common_mqtt: !include
|
||||
# file: common/mqtt_common.yaml
|
||||
# vars:
|
||||
# local_device_name: "${device_name}"
|
||||
|
||||
|
||||
#### WEB PORTAL ####
|
||||
#common_webportal: !include common/webportal_common.yaml
|
||||
#common_sntp: !include common/sntp_common.yaml
|
||||
|
||||
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
|
||||
#### SNTP (Only use if you want/need accurate timeclocks) ####
|
||||
#common_sntp: !include common/sntp_common.yaml
|
||||
|
||||
##########################################################################################
|
||||
# ESPHome CORE CONFIGURATION
|
||||
##########################################################################################
|
||||
#### 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_resetcount: !include common/include_resetcount_diag_sensors.yaml
|
||||
|
||||
#:########################################################################################:#
|
||||
# ESPHOME CORE CONFIGURATION:
|
||||
# https://esphome.io/components/esphome.html
|
||||
#:########################################################################################:#
|
||||
esphome:
|
||||
name: "${device_name}"
|
||||
friendly_name: "${friendly_name}"
|
||||
comment: "${description_comment}"
|
||||
area: "${device_area}"
|
||||
project:
|
||||
name: "${project_name}"
|
||||
version: "${project_version}"
|
||||
on_boot:
|
||||
priority: 200
|
||||
then:
|
||||
@@ -171,9 +198,22 @@ esphome:
|
||||
transition_length: 0s
|
||||
- lambda: 'id(booting) = false;'
|
||||
|
||||
##########################################################################################
|
||||
# ESP PLATFORM AND FRAMEWORK
|
||||
##########################################################################################
|
||||
# Only if you want to play with build flags...
|
||||
# platformio_options:
|
||||
# build_unflags:
|
||||
# - -flto
|
||||
# build_flags:
|
||||
# - -fno-lto
|
||||
# - -Wl,--gc-sections
|
||||
# - -ffunction-sections
|
||||
# - -fdata-sections
|
||||
# - -DNDEBUG
|
||||
|
||||
#:########################################################################################:#
|
||||
# ESP PLATFORM AND FRAMEWORK:
|
||||
# https://esphome.io/components/esp8266.html
|
||||
# https://esphome.io/components/esp32.html
|
||||
#:########################################################################################:#
|
||||
esp8266:
|
||||
board: esp01_1m
|
||||
restore_from_flash: true
|
||||
@@ -182,25 +222,29 @@ mdns:
|
||||
disabled: true
|
||||
|
||||
preferences:
|
||||
flash_write_interval: 5min # reduce flash churn while testing
|
||||
flash_write_interval: 5min
|
||||
|
||||
##########################################################################################
|
||||
# GLOBAL VARIABLES
|
||||
##########################################################################################
|
||||
#:########################################################################################:#
|
||||
# GLOBAL VARIABLES:
|
||||
# https://esphome.io/components/globals.html
|
||||
#:########################################################################################:#
|
||||
globals:
|
||||
# Per-channel brightness caps (internal; set via YAML substitutions)
|
||||
- id: min_brightness_pct_A
|
||||
type: int
|
||||
restore_value: true
|
||||
initial_value: "${minimum_led_output_A}"
|
||||
|
||||
- id: max_brightness_pct_A
|
||||
type: int
|
||||
restore_value: false
|
||||
initial_value: "${maximum_led_output_A}"
|
||||
|
||||
- id: min_brightness_pct_B
|
||||
type: int
|
||||
restore_value: true
|
||||
initial_value: "${minimum_led_output_B}"
|
||||
|
||||
- id: max_brightness_pct_B
|
||||
type: int
|
||||
restore_value: false
|
||||
@@ -216,123 +260,146 @@ globals:
|
||||
- id: ramp_up_ms_A
|
||||
type: int
|
||||
restore_value: true
|
||||
initial_value: '5000'
|
||||
initial_value: "5000"
|
||||
|
||||
- id: ramp_down_ms_A
|
||||
type: int
|
||||
restore_value: true
|
||||
initial_value: '10000'
|
||||
initial_value: "10000"
|
||||
|
||||
- id: ramp_up_ms_B
|
||||
type: int
|
||||
restore_value: true
|
||||
initial_value: '5000'
|
||||
initial_value: "5000"
|
||||
|
||||
- id: ramp_down_ms_B
|
||||
type: int
|
||||
restore_value: true
|
||||
initial_value: '10000'
|
||||
initial_value: "10000"
|
||||
|
||||
# Restart Action. (0=Fade full, 1=Restore brightness, 2=Remain off)
|
||||
- id: restart_mode
|
||||
type: int
|
||||
restore_value: true
|
||||
initial_value: '1' # align with select initial_option "Restore Brightness"
|
||||
initial_value: "1" # align with select initial_option "Restore Brightness"
|
||||
|
||||
# Per-channel runtime state (A)
|
||||
- id: ramp_switch_target_on_A
|
||||
type: bool
|
||||
restore_value: true
|
||||
initial_value: 'false'
|
||||
initial_value: "false"
|
||||
|
||||
- id: suppress_slider_sync_A
|
||||
type: bool
|
||||
restore_value: false
|
||||
initial_value: 'false'
|
||||
- id: suppress_quick_on_A # guard to prevent quick-to-cap on slider turn-on
|
||||
initial_value: "false"
|
||||
|
||||
- id: suppress_quick_on_A
|
||||
type: bool
|
||||
restore_value: false
|
||||
initial_value: 'false'
|
||||
initial_value: "false"
|
||||
|
||||
- id: last_brightness_pct_A
|
||||
type: float
|
||||
restore_value: true
|
||||
initial_value: '0.0'
|
||||
initial_value: "0.0"
|
||||
|
||||
- id: last_set_pos_A
|
||||
type: int
|
||||
restore_value: false
|
||||
initial_value: '-1'
|
||||
initial_value: "-1"
|
||||
|
||||
- id: last_ramp_ms_A
|
||||
type: uint32_t
|
||||
restore_value: false
|
||||
initial_value: '0'
|
||||
initial_value: "0"
|
||||
|
||||
- id: last_nonzero_brightness_pct_A
|
||||
type: float
|
||||
restore_value: true
|
||||
initial_value: '0.0'
|
||||
initial_value: "0.0"
|
||||
|
||||
- id: restore_target_pct_A
|
||||
type: float
|
||||
restore_value: false
|
||||
initial_value: '0.0'
|
||||
initial_value: "0.0"
|
||||
|
||||
- id: is_ramping_A
|
||||
type: bool
|
||||
restore_value: false
|
||||
initial_value: 'false'
|
||||
initial_value: "false"
|
||||
|
||||
- id: last_nonzero_tmp_A
|
||||
type: float
|
||||
restore_value: false
|
||||
initial_value: '0.0'
|
||||
initial_value: "0.0"
|
||||
|
||||
- id: ramping_for_off_A
|
||||
type: bool
|
||||
restore_value: false
|
||||
initial_value: 'false'
|
||||
initial_value: "false"
|
||||
|
||||
# Per-channel runtime state (B)
|
||||
- id: ramp_switch_target_on_B
|
||||
type: bool
|
||||
restore_value: true
|
||||
initial_value: 'false'
|
||||
initial_value: "false"
|
||||
|
||||
- id: suppress_slider_sync_B
|
||||
type: bool
|
||||
restore_value: false
|
||||
initial_value: 'false'
|
||||
- id: suppress_quick_on_B # guard to prevent quick-to-cap on slider turn-on
|
||||
initial_value: "false"
|
||||
|
||||
- id: suppress_quick_on_B
|
||||
type: bool
|
||||
restore_value: false
|
||||
initial_value: 'false'
|
||||
initial_value: "false"
|
||||
|
||||
- id: last_brightness_pct_B
|
||||
type: float
|
||||
restore_value: true
|
||||
initial_value: '0.0'
|
||||
initial_value: "0.0"
|
||||
|
||||
- id: last_set_pos_B
|
||||
type: int
|
||||
restore_value: false
|
||||
initial_value: '-1'
|
||||
initial_value: "-1"
|
||||
|
||||
- id: last_ramp_ms_B
|
||||
type: uint32_t
|
||||
restore_value: false
|
||||
initial_value: '0'
|
||||
initial_value: "0"
|
||||
|
||||
- id: last_nonzero_brightness_pct_B
|
||||
type: float
|
||||
restore_value: true
|
||||
initial_value: '0.0'
|
||||
initial_value: "0.0"
|
||||
|
||||
- id: restore_target_pct_B
|
||||
type: float
|
||||
restore_value: false
|
||||
initial_value: '0.0'
|
||||
initial_value: "0.0"
|
||||
|
||||
- id: is_ramping_B
|
||||
type: bool
|
||||
restore_value: false
|
||||
initial_value: 'false'
|
||||
initial_value: "false"
|
||||
|
||||
- id: last_nonzero_tmp_B
|
||||
type: float
|
||||
restore_value: false
|
||||
initial_value: '0.0'
|
||||
initial_value: "0.0"
|
||||
|
||||
- id: ramping_for_off_B
|
||||
type: bool
|
||||
restore_value: false
|
||||
initial_value: 'false'
|
||||
initial_value: "false"
|
||||
|
||||
# Guard for startup behaviour
|
||||
- id: booting
|
||||
type: bool
|
||||
restore_value: false
|
||||
initial_value: 'true'
|
||||
initial_value: "true"
|
||||
|
||||
# Compile time Gamma (cached; currently unused since PWM% sensors were removed)
|
||||
- id: led_gamma_f
|
||||
@@ -340,48 +407,51 @@ globals:
|
||||
restore_value: false
|
||||
initial_value: ${led_gamma}
|
||||
|
||||
##########################################################################################
|
||||
# LOGGER
|
||||
##########################################################################################
|
||||
#:########################################################################################:#
|
||||
# LOGGER:
|
||||
# https://esphome.io/components/logger.html
|
||||
#:########################################################################################:#
|
||||
logger:
|
||||
level: "${log_level}"
|
||||
baud_rate: 0
|
||||
|
||||
#########################################################################################
|
||||
# STATUS LED
|
||||
#########################################################################################
|
||||
#:########################################################################################:#
|
||||
# STATUS LED:
|
||||
# https://esphome.io/components/status_led.html
|
||||
#:########################################################################################:#
|
||||
#status_led:
|
||||
# pin:
|
||||
# number: ${device_status_led}
|
||||
# inverted: true
|
||||
|
||||
##########################################################################################
|
||||
# MQTT COMMANDS
|
||||
##########################################################################################
|
||||
#:########################################################################################:#
|
||||
# MQTT COMMANDS:
|
||||
#:########################################################################################:#
|
||||
#mqtt:
|
||||
# on_message handlers commented for efficiency (S8). Uncomment if you need local MQTT control again.
|
||||
#on_message:
|
||||
# - topic: "${mqtt_local_command_topic_A}/lightA/set"
|
||||
# payload: "${mqtt_local_device_command_ON}"
|
||||
# then:
|
||||
# - switch.turn_on: mosfet_ramp_switch_a
|
||||
# - topic: "${mqtt_local_command_topic_A}/lightA/set"}
|
||||
# payload: "${mqtt_local_device_command_OFF}"
|
||||
# then:
|
||||
# - switch.turn_off: mosfet_ramp_switch_a
|
||||
#
|
||||
# - topic: "${mqtt_local_command_topic_B}/lightB/set"
|
||||
# payload: "${mqtt_local_device_command_ON}"
|
||||
# then:
|
||||
# - switch.turn_on: mosfet_ramp_switch_b
|
||||
# - topic: "${mqtt_local_command_topic_B}/lightB/set"
|
||||
# payload: "${mqtt_local_device_command_OFF}"
|
||||
# then:
|
||||
# - switch.turn_off: mosfet_ramp_switch_b
|
||||
# on_message handlers commented for efficiency. Uncomment if you need local MQTT control again.
|
||||
# on_message:
|
||||
# - topic: "${mqtt_local_command_topic_A}/lightA/set"
|
||||
# payload: "${mqtt_local_device_command_ON}"
|
||||
# then:
|
||||
# - switch.turn_on: mosfet_ramp_switch_a
|
||||
# - topic: "${mqtt_local_command_topic_A}/lightA/set"
|
||||
# payload: "${mqtt_local_device_command_OFF}"
|
||||
# then:
|
||||
# - switch.turn_off: mosfet_ramp_switch_a
|
||||
#
|
||||
# - topic: "${mqtt_local_command_topic_B}/lightB/set"
|
||||
# payload: "${mqtt_local_device_command_ON}"
|
||||
# then:
|
||||
# - switch.turn_on: mosfet_ramp_switch_b
|
||||
# - topic: "${mqtt_local_command_topic_B}/lightB/set"
|
||||
# payload: "${mqtt_local_device_command_OFF}"
|
||||
# then:
|
||||
# - switch.turn_off: mosfet_ramp_switch_b
|
||||
|
||||
##########################################################################################
|
||||
# SWITCHES
|
||||
##########################################################################################
|
||||
#:########################################################################################:#
|
||||
# SWITCH COMPONENT:
|
||||
# https://esphome.io/components/switch/
|
||||
#:########################################################################################:#
|
||||
switch:
|
||||
- platform: template
|
||||
id: mosfet_ramp_switch_a
|
||||
@@ -417,13 +487,15 @@ switch:
|
||||
- script.stop: ramp_on_script_B
|
||||
- script.execute: ramp_off_script_B
|
||||
|
||||
#################################################################################################
|
||||
# BUTTONS (none)
|
||||
#################################################################################################
|
||||
#:########################################################################################:#
|
||||
# BUTTON COMPONENT:
|
||||
# No standalone template button entities in this yaml
|
||||
#:########################################################################################:#
|
||||
|
||||
#########################################################################################
|
||||
# SELECTS
|
||||
#########################################################################################
|
||||
#:########################################################################################:#
|
||||
# SELECT COMPONENT:
|
||||
# https://esphome.io/components/select/index.html
|
||||
#:########################################################################################:#
|
||||
select:
|
||||
- platform: template
|
||||
id: restart_action
|
||||
@@ -445,9 +517,10 @@ select:
|
||||
id(restart_mode) = 2;
|
||||
}
|
||||
|
||||
##########################################################################################
|
||||
# SENSORS
|
||||
##########################################################################################
|
||||
#:########################################################################################:#
|
||||
# SENSOR COMPONENT:
|
||||
# https://esphome.io/components/sensor/
|
||||
#:########################################################################################:#
|
||||
sensor:
|
||||
# Channel A: Output % (pre-gamma)
|
||||
- platform: template
|
||||
@@ -456,7 +529,7 @@ sensor:
|
||||
unit_of_measurement: "%"
|
||||
icon: mdi:percent
|
||||
accuracy_decimals: 0
|
||||
update_interval: 200ms # show real-time ramp
|
||||
update_interval: 200ms
|
||||
disabled_by_default: true
|
||||
lambda: |-
|
||||
const auto &cv = id(mosfet_leds_A).current_values;
|
||||
@@ -488,22 +561,21 @@ sensor:
|
||||
id(led_output_set_pct_A).publish_state(pos_i);
|
||||
}
|
||||
}
|
||||
// Auto-sync fade switch to brightness thresholds (no scripts)
|
||||
if (!id(booting) && !id(is_ramping_A)) {
|
||||
float cap = (float) id(max_brightness_pct_A); // cap in %
|
||||
float low_th = cap * 0.33f;
|
||||
float cap = (float) id(max_brightness_pct_A);
|
||||
float low_th = cap * 0.33f;
|
||||
float high_th = cap * 0.66f;
|
||||
if (cv_now.is_on()) {
|
||||
float b = x; // current brightness in %
|
||||
if (b < low_th - 0.25f) { // hysteresis margin
|
||||
float b = x;
|
||||
if (b < low_th - 0.25f) {
|
||||
if (id(ramp_switch_target_on_A)) {
|
||||
id(ramp_switch_target_on_A) = false;
|
||||
id(mosfet_ramp_switch_a).publish_state(false); // UI-only; no ramp
|
||||
id(mosfet_ramp_switch_a).publish_state(false);
|
||||
}
|
||||
} else if (b > high_th + 0.25f) {
|
||||
if (!id(ramp_switch_target_on_A)) {
|
||||
id(ramp_switch_target_on_A) = true;
|
||||
id(mosfet_ramp_switch_a).publish_state(true); // UI-only; no ramp
|
||||
id(mosfet_ramp_switch_a).publish_state(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -548,10 +620,9 @@ sensor:
|
||||
id(led_output_set_pct_B).publish_state(pos_i);
|
||||
}
|
||||
}
|
||||
// Auto-sync fade switch to brightness thresholds (no scripts)
|
||||
if (!id(booting) && !id(is_ramping_B)) {
|
||||
float cap = (float) id(max_brightness_pct_B);
|
||||
float low_th = cap * 0.33f;
|
||||
float low_th = cap * 0.33f;
|
||||
float high_th = cap * 0.66f;
|
||||
if (cv_now.is_on()) {
|
||||
float b = x;
|
||||
@@ -569,14 +640,16 @@ sensor:
|
||||
}
|
||||
}
|
||||
|
||||
##########################################################################################
|
||||
# OUTPUTS
|
||||
##########################################################################################
|
||||
#:########################################################################################:#
|
||||
# OUTPUT COMPONENT:
|
||||
# https://esphome.io/components/output/
|
||||
#:########################################################################################:#
|
||||
output:
|
||||
- platform: esp8266_pwm
|
||||
id: mosfet_pwm_A
|
||||
pin: ${device_mosfet_out_A}
|
||||
frequency: ${pwm_frequency}
|
||||
|
||||
- platform: esp8266_pwm
|
||||
id: mosfet_pwm_B
|
||||
pin: ${device_mosfet_out_B}
|
||||
@@ -587,27 +660,28 @@ output:
|
||||
pin:
|
||||
number: ${device_fading_led_A}
|
||||
inverted: false
|
||||
|
||||
- platform: gpio
|
||||
id: fading_led_out_B
|
||||
pin:
|
||||
number: ${device_fading_led_B}
|
||||
inverted: false
|
||||
|
||||
##########################################################################################
|
||||
# LIGHTS
|
||||
##########################################################################################
|
||||
#:########################################################################################:#
|
||||
# LIGHT COMPONENT:
|
||||
# https://esphome.io/components/light/
|
||||
#:########################################################################################:#
|
||||
light:
|
||||
- platform: monochromatic
|
||||
id: mosfet_leds_A
|
||||
name: "${friendly_name} A"
|
||||
output: mosfet_pwm_A
|
||||
restore_mode: RESTORE_DEFAULT_OFF
|
||||
default_transition_length: 250ms # quick ramp for normal light toggle
|
||||
default_transition_length: 250ms
|
||||
icon: mdi:led-strip-variant
|
||||
gamma_correct: "${led_gamma}"
|
||||
|
||||
on_turn_on:
|
||||
# Start/refresh Max-On watchdog quietly whenever light turns on
|
||||
- if:
|
||||
condition:
|
||||
lambda: 'return id(max_on_hours) > 0;'
|
||||
@@ -628,13 +702,11 @@ light:
|
||||
|
||||
on_state:
|
||||
- lambda: |-
|
||||
// Mirror board RED LED to this channel's on/off
|
||||
const auto &cv_s = id(mosfet_leds_A).current_values;
|
||||
const bool is_on = cv_s.is_on() && (cv_s.get_brightness() > 0.0005f);
|
||||
if (is_on) id(fading_led_out_A).turn_on();
|
||||
else id(fading_led_out_A).turn_off();
|
||||
- lambda: |-
|
||||
// Enforce cap if anyone tries to exceed it
|
||||
const float cap = id(max_brightness_pct_A) / 100.0f;
|
||||
const auto &cv = id(mosfet_leds_A).current_values;
|
||||
if (!cv.is_on()) return;
|
||||
@@ -651,7 +723,7 @@ light:
|
||||
name: "${friendly_name} B"
|
||||
output: mosfet_pwm_B
|
||||
restore_mode: RESTORE_DEFAULT_OFF
|
||||
default_transition_length: 250ms # quick ramp for normal light toggle
|
||||
default_transition_length: 250ms
|
||||
icon: mdi:led-strip-variant
|
||||
gamma_correct: "${led_gamma}"
|
||||
|
||||
@@ -676,7 +748,6 @@ light:
|
||||
|
||||
on_state:
|
||||
- lambda: |-
|
||||
// Mirror board GREEN LED to this channel's on/off
|
||||
const auto &cv_s = id(mosfet_leds_B).current_values;
|
||||
const bool is_on = cv_s.is_on() && (cv_s.get_brightness() > 0.0005f);
|
||||
if (is_on) id(fading_led_out_B).turn_on();
|
||||
@@ -693,9 +764,10 @@ light:
|
||||
call.set_transition_length(0);
|
||||
call.perform();
|
||||
|
||||
##########################################################################################
|
||||
# NUMBERS
|
||||
##########################################################################################
|
||||
#:########################################################################################:#
|
||||
# NUMBER COMPONENT:
|
||||
# https://esphome.io/components/number/
|
||||
#:########################################################################################:#
|
||||
number:
|
||||
- platform: template
|
||||
id: cfg_ramp_up_s_A
|
||||
@@ -777,7 +849,6 @@ number:
|
||||
id(ramp_down_ms_B) = secs * 1000;
|
||||
id(cfg_ramp_down_s_B).publish_state((float) secs);
|
||||
|
||||
# Per-channel position slider (0..100 mapped into [min..max])
|
||||
- platform: template
|
||||
id: led_output_set_pct_A
|
||||
name: "${friendly_name} A Output Set (0-100)"
|
||||
@@ -788,11 +859,11 @@ number:
|
||||
step: 1
|
||||
lambda: |-
|
||||
const auto &cv = id(mosfet_leds_A).current_values;
|
||||
float actual = cv.is_on() ? (cv.get_brightness() * 100.0f) : 0.0f; // 0..100 actual
|
||||
float actual = cv.is_on() ? (cv.get_brightness() * 100.0f) : 0.0f;
|
||||
float minp = (float) id(min_brightness_pct_A);
|
||||
float maxp = (float) id(max_brightness_pct_A);
|
||||
if (maxp <= minp) maxp = minp + 1.0f; // avoid div/0
|
||||
if (actual <= 0.0f) return 0.0f; // when OFF, show 0
|
||||
if (maxp <= minp) maxp = minp + 1.0f;
|
||||
if (actual <= 0.0f) return 0.0f;
|
||||
float pos = (actual - minp) * 100.0f / (maxp - minp);
|
||||
if (pos < 0.0f) pos = 0.0f;
|
||||
if (pos > 100.0f) pos = 100.0f;
|
||||
@@ -817,22 +888,19 @@ number:
|
||||
else:
|
||||
- lambda: |-
|
||||
id(suppress_slider_sync_A) = true;
|
||||
float pos = x; // 0..100
|
||||
if (pos < 1.0f) pos = 1.0f; // 0 is OFF
|
||||
float pos = x;
|
||||
if (pos < 1.0f) pos = 1.0f;
|
||||
if (pos > 100.0f) pos = 100.0f;
|
||||
id(led_output_set_pct_A).publish_state((int) floorf(pos + 0.5f));
|
||||
|
||||
// Map slider position into absolute % within [min..max]
|
||||
float minp = (float) id(min_brightness_pct_A);
|
||||
float maxp = (float) id(max_brightness_pct_A);
|
||||
if (maxp <= minp) maxp = minp + 1.0f;
|
||||
float out_pct = minp + (pos * (maxp - minp) / 100.0f);
|
||||
if (out_pct > maxp) out_pct = maxp;
|
||||
|
||||
// Stash target for the ramp script
|
||||
id(restore_target_pct_A) = out_pct;
|
||||
|
||||
// Choose duration by direction (up vs down)
|
||||
const auto &cv = id(mosfet_leds_A).current_values;
|
||||
float curr = cv.is_on() ? (cv.get_brightness() * 100.0f) : 0.0f;
|
||||
id(last_ramp_ms_A) = (out_pct > curr) ? id(ramp_up_ms_A) : id(ramp_down_ms_A);
|
||||
@@ -852,11 +920,11 @@ number:
|
||||
step: 1
|
||||
lambda: |-
|
||||
const auto &cv = id(mosfet_leds_B).current_values;
|
||||
float actual = cv.is_on() ? (cv.get_brightness() * 100.0f) : 0.0f; // 0..100 actual
|
||||
float actual = cv.is_on() ? (cv.get_brightness() * 100.0f) : 0.0f;
|
||||
float minp = (float) id(min_brightness_pct_B);
|
||||
float maxp = (float) id(max_brightness_pct_B);
|
||||
if (maxp <= minp) maxp = minp + 1.0f; // avoid div/0
|
||||
if (actual <= 0.0f) return 0.0f; // when OFF, show 0
|
||||
if (maxp <= minp) maxp = minp + 1.0f;
|
||||
if (actual <= 0.0f) return 0.0f;
|
||||
float pos = (actual - minp) * 100.0f / (maxp - minp);
|
||||
if (pos < 0.0f) pos = 0.0f;
|
||||
if (pos > 100.0f) pos = 100.0f;
|
||||
@@ -881,22 +949,19 @@ number:
|
||||
else:
|
||||
- lambda: |-
|
||||
id(suppress_slider_sync_B) = true;
|
||||
float pos = x; // 0..100
|
||||
if (pos < 1.0f) pos = 1.0f; // 0 is OFF
|
||||
float pos = x;
|
||||
if (pos < 1.0f) pos = 1.0f;
|
||||
if (pos > 100.0f) pos = 100.0f;
|
||||
id(led_output_set_pct_B).publish_state((int) floorf(pos + 0.5f));
|
||||
|
||||
// Map slider position into absolute % within [min..max]
|
||||
float minp = (float) id(min_brightness_pct_B);
|
||||
float maxp = (float) id(max_brightness_pct_B);
|
||||
if (maxp <= minp) maxp = minp + 1.0f;
|
||||
float out_pct = minp + (pos * (maxp - minp) / 100.0f);
|
||||
if (out_pct > maxp) out_pct = maxp;
|
||||
|
||||
// Stash target for the ramp script
|
||||
id(restore_target_pct_B) = out_pct;
|
||||
|
||||
// Choose duration by direction (up vs down)
|
||||
const auto &cv = id(mosfet_leds_B).current_values;
|
||||
float curr = cv.is_on() ? (cv.get_brightness() * 100.0f) : 0.0f;
|
||||
id(last_ramp_ms_B) = (out_pct > curr) ? id(ramp_up_ms_B) : id(ramp_down_ms_B);
|
||||
@@ -906,8 +971,6 @@ number:
|
||||
- delay: !lambda 'return (uint32_t) id(last_ramp_ms_B);'
|
||||
- lambda: 'id(suppress_slider_sync_B) = false;'
|
||||
|
||||
|
||||
# Shared "Max On" hours (0=disabled). When light is turned on, watchdog restarts.
|
||||
- platform: template
|
||||
id: cfg_max_on_hours
|
||||
name: "${friendly_name} Max On (h)"
|
||||
@@ -923,11 +986,10 @@ number:
|
||||
set_action:
|
||||
- lambda: |-
|
||||
int hrs = (int) x;
|
||||
if (hrs < 0) hrs = 0;
|
||||
if (hrs < 0) hrs = 0;
|
||||
if (hrs > 48) hrs = 48;
|
||||
id(max_on_hours) = hrs;
|
||||
id(cfg_max_on_hours).publish_state((float) hrs);
|
||||
# Restart/stop watchdogs appropriately for both channels
|
||||
- if:
|
||||
condition:
|
||||
lambda: 'return id(mosfet_leds_A).current_values.is_on();'
|
||||
@@ -949,9 +1011,10 @@ number:
|
||||
then:
|
||||
- script.execute: max_on_watchdog_B
|
||||
|
||||
##########################################################################################
|
||||
# SCRIPTS
|
||||
##########################################################################################
|
||||
#:########################################################################################:#
|
||||
# SCRIPT COMPONENT:
|
||||
# https://esphome.io/components/script.html
|
||||
#:########################################################################################:#
|
||||
script:
|
||||
# Ramps: Channel A
|
||||
- id: ramp_on_script_A
|
||||
@@ -959,7 +1022,6 @@ script:
|
||||
then:
|
||||
- lambda: 'id(is_ramping_A) = true;'
|
||||
- script.stop: ramp_off_script_A
|
||||
# Single transition to CAP for the full configured time
|
||||
- light.turn_on:
|
||||
id: mosfet_leds_A
|
||||
brightness: !lambda 'return id(max_brightness_pct_A) / 100.0f;'
|
||||
@@ -1000,7 +1062,6 @@ script:
|
||||
id(is_ramping_A) = true;
|
||||
id(ramping_for_off_A) = true;
|
||||
- script.stop: ramp_on_script_A
|
||||
# Single transition directly to OFF for the full configured time
|
||||
- light.turn_off:
|
||||
id: mosfet_leds_A
|
||||
transition_length: !lambda 'return (uint32_t) id(ramp_down_ms_A);'
|
||||
@@ -1039,7 +1100,7 @@ script:
|
||||
float minp = (float) id(min_brightness_pct_A);
|
||||
float maxp = (float) id(max_brightness_pct_A);
|
||||
if (target > 0.0f && target < minp) target = minp;
|
||||
if (target > maxp) target = maxp;
|
||||
if (target > maxp) target = maxp;
|
||||
id(restore_target_pct_A) = target;
|
||||
id(last_ramp_ms_A) = id(ramp_up_ms_A);
|
||||
- if:
|
||||
@@ -1048,14 +1109,14 @@ script:
|
||||
then:
|
||||
- lambda: |-
|
||||
id(ramp_switch_target_on_A) = true;
|
||||
id(suppress_slider_sync_A) = true;
|
||||
id(suppress_quick_on_A) = true;
|
||||
id(suppress_slider_sync_A) = true;
|
||||
id(suppress_quick_on_A) = true;
|
||||
- script.stop: ramp_off_script_A
|
||||
- script.execute: ramp_to_target_script_A
|
||||
- delay: !lambda 'return (uint32_t) id(last_ramp_ms_A);'
|
||||
- lambda: |-
|
||||
id(suppress_slider_sync_A) = false;
|
||||
id(suppress_quick_on_A) = false;
|
||||
id(suppress_slider_sync_A) = false;
|
||||
id(suppress_quick_on_A) = false;
|
||||
else:
|
||||
- lambda: 'id(ramp_switch_target_on_A) = false;'
|
||||
- light.turn_off:
|
||||
@@ -1146,7 +1207,7 @@ script:
|
||||
float minp = (float) id(min_brightness_pct_B);
|
||||
float maxp = (float) id(max_brightness_pct_B);
|
||||
if (target > 0.0f && target < minp) target = minp;
|
||||
if (target > maxp) target = maxp;
|
||||
if (target > maxp) target = maxp;
|
||||
id(restore_target_pct_B) = target;
|
||||
id(last_ramp_ms_B) = id(ramp_up_ms_B);
|
||||
- if:
|
||||
@@ -1155,18 +1216,16 @@ script:
|
||||
then:
|
||||
- lambda: |-
|
||||
id(ramp_switch_target_on_B) = true;
|
||||
id(suppress_slider_sync_B) = true;
|
||||
id(suppress_quick_on_B) = true;
|
||||
id(suppress_slider_sync_B) = true;
|
||||
id(suppress_quick_on_B) = true;
|
||||
- script.stop: ramp_off_script_B
|
||||
- script.execute: ramp_to_target_script_B
|
||||
- delay: !lambda 'return (uint32_t) id(last_ramp_ms_B);'
|
||||
- lambda: |-
|
||||
id(suppress_slider_sync_B) = false;
|
||||
id(suppress_quick_on_B) = false;
|
||||
id(suppress_slider_sync_B) = false;
|
||||
id(suppress_quick_on_B) = false;
|
||||
else:
|
||||
- lambda: 'id(ramp_switch_target_on_B) = false;'
|
||||
- light.turn_off:
|
||||
id: mosfet_leds_B
|
||||
transition_length: 0s
|
||||
##########################################################################################
|
||||
##########################################################################################
|
||||
transition_length: 0s
|
||||
Reference in New Issue
Block a user