defaules in substitutions now V1.2

This commit is contained in:
root
2025-08-21 20:01:39 +12:00
parent c76ca83932
commit c73e41496d
3 changed files with 78 additions and 24 deletions

View File

@@ -5,6 +5,7 @@
# https://devices.esphome.io/devices/Sinilink-XY-VFMS
# Repo: https://home.fox.co.nz/gitea/zorruno/zorruno-homeassistant/src/branch/master/esphome/esp-downstairskitchleds.yaml
#
# V1.2 - 2025-08-21 Added some defaults to "Device Specific settings" in substitutions & a PWM % View
# V1.1 - 2025-08-18 Full tidyup as general purpose LED strip controller
# V1.0 - 2025-08-17 First Setup (and replacement of Tasmota)
#
@@ -17,7 +18,7 @@
# GPIO13 Green LED (We'll use this to display fading status)
#
# ------------------------------------------
# OPERATION (as at V1.1)
# OPERATION (as at V1.2)
# ------------------------------------------
# 1. General Purpose LED controller
# 2. Designed for a Sinilink XY-VFMS board that has a mosfet output and supposedly will handle
@@ -45,7 +46,7 @@
# - A fade up/fade down switch
# - Normal on/off switch (quick ramp up/down)
# - Setting for fade up and fade times (0-60 seconds)
# - Output display of % PWM output
# - Output display of % output (before gamma), and the PWM % output (after gamma)
# - Ability to set output to any value (1-100, but respects min/max)
# - Default has a bunch of device diagnostic in the PACKAGE included (Sensors_Common)
#
@@ -65,7 +66,7 @@ substitutions:
# Project Naming
project_name: "Sinilink.XY-WFMS" # Project Details
project_version: "v1.1" # Project V denotes release of yaml file, allowing checking of deployed vs latest version
project_version: "v1.2" # Project V denotes release of yaml file, allowing checking of deployed vs latest version
# Passwords & Secrets
api_key: !secret esp-api_key
@@ -74,10 +75,6 @@ substitutions:
mqtt_local_command_main_topic: !secret mqtt_local_command_main_topic
mqtt_local_status_main_topic: !secret mqtt_local_status_main_topic
# Device Settings
log_level: "INFO" # Define logging level: NONE, ERROR, WARN, INFO, DEBUG (Default), VERBOSE, VERY_VERBOSE
update_interval: "20s" # update time for for general sensors etc
# MQTT LOCAL Controls
mqtt_local_device_name: "downstairskitchen-pantryleds"
mqtt_local_command_topic: "${mqtt_local_command_main_topic}/${mqtt_local_device_name}" # Topic we will use to command this locally without HA
@@ -85,17 +82,13 @@ substitutions:
mqtt_local_device_command_ON: "ON"
mqtt_local_device_command_OFF: "OFF"
# MQTT REMOTE Controls
#mqtt_remote_device_name: "downstairskitchen-pantryleds"
#mqtt_remote_device_command_topic: "${mqtt_local_command_main_topic}/${mqtt_remote_device_name}/light/set"
#mqtt_remote_device_command1: "+"
#mqtt_remote_device_command2: "-"
#mqtt_remote_device_command3: "0"
#mqtt_local_status_topic: "${mqtt_local_status_main_topic}/${mqtt_remote_device_name}/speed/state" # Topic we will use to view status locally without HA
# Device Specific Settings
log_level: "INFO" # Define logging level: NONE, ERROR, WARN, INFO, DEBUG (Default), VERBOSE, VERY_VERBOSE
update_interval: "20s" # update time for for general sensors etc
led_gamma: "1.2" # Gamma from 1.2 - 3 is sensible to normalise the lED fading vs PWM
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 aesthetic
# Button Naming & Icons
# Switch/Relay Naming & Icons
##########################################################################################
# PACKAGES: Included Common Packages
@@ -207,8 +200,8 @@ esp8266:
board: esp01_1m
restore_from_flash: true # restore some values on reboot
preferences:
flash_write_interval: 5min
#preferences:
# flash_write_interval: 5min
mdns:
disabled: false # Disabling will make the build file smaller (and it is still available via static IP)
@@ -222,12 +215,12 @@ globals:
- id: min_brightness_pct
type: int
restore_value: true
initial_value: '3' # start/finish at X%
initial_value: "${minimum_led_output}" # start/finish at X%
# Maximum Brightness % for LEDs (should never go beyond this)
- id: max_brightness_pct
type: int
restore_value: false
initial_value: '90' # hard cap; never exceed this
initial_value: "${maximum_led_output}" # hard cap; never exceed this
# Default Fading Up Time (Selectable and will be retained)
- id: ramp_up_ms # fade-in when turned ON
type: int
@@ -481,6 +474,23 @@ sensor:
id(led_output_set_pct).publish_state(pos_i);
}
}
- platform: template
id: mosfet_output_pwm_pct
name: "${friendly_name} Output PWM (%)"
unit_of_measurement: "%"
icon: mdi:square-wave
accuracy_decimals: 1
update_interval: 100ms
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)
const float gamma = ${led_gamma}; // from substitutions
float pwm = powf(lin, gamma); // approximate PWM duty after gamma
if (pwm < 0.0f) pwm = 0.0f;
if (pwm > 1.0f) pwm = 1.0f;
return pwm * 100.0f;
##########################################################################################
# OUTPUT COMPONENT
@@ -512,7 +522,7 @@ light:
restore_mode: RESTORE_DEFAULT_OFF
default_transition_length: 2s
icon: mdi:led-strip-variant
gamma_correct: 1.2
gamma_correct: "${led_gamma}"
on_turn_on:
- mqtt.publish:
topic: "${mqtt_local_status_topic}/light/state"