diff --git a/esphome/common/sensors_common.yaml b/esphome/common/sensors_common.yaml index ffdb562..534d300 100644 --- a/esphome/common/sensors_common.yaml +++ b/esphome/common/sensors_common.yaml @@ -67,9 +67,29 @@ text_sensor: - platform: template name: "Last Reset Reason" update_interval: 30s - lambda: |- - return { ESP.getResetReason().c_str() }; entity_category: diagnostic + lambda: |- + #if defined(USE_ESP8266) + return { ESP.getResetReason().c_str() }; + #elif defined(USE_ESP32) + auto r = esp_reset_reason(); + switch (r) { + case ESP_RST_POWERON: return { "Power-on" }; + case ESP_RST_EXT: return { "External pin" }; + case ESP_RST_SW: return { "Software reset" }; + case ESP_RST_PANIC: return { "Exception/Panic" }; + case ESP_RST_INT_WDT: return { "Interrupt WDT" }; + case ESP_RST_TASK_WDT: return { "Task WDT" }; + case ESP_RST_WDT: return { "Other WDT" }; + case ESP_RST_DEEPSLEEP: return { "Deep sleep wake" }; + case ESP_RST_BROWNOUT: return { "Brownout" }; + case ESP_RST_SDIO: return { "SDIO" }; + default: return { "Unknown" }; + } + #else + return { "Unknown" }; + #endif + ################################################################################################### # Creates a sensor of the uptime of the device, in formatted days, hours, minutes and seconds diff --git a/esphome/esp-downstairskitchleds.yaml b/esphome/esp-downstairskitchleds.yaml index d641f52..8e6d8b6 100644 --- a/esphome/esp-downstairskitchleds.yaml +++ b/esphome/esp-downstairskitchleds.yaml @@ -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" diff --git a/packages/health_checks.yaml b/packages/health_checks.yaml new file mode 100644 index 0000000..09e2ed3 --- /dev/null +++ b/packages/health_checks.yaml @@ -0,0 +1,24 @@ +binary_sensor: + - platform: rest + name: Node-RED Panda Up + resource: http://192.168.3.200:1880/healthz + method: GET + device_class: connectivity + value_template: "{{ value_json.status == 'ok' }}" + scan_interval: 30 + +mqtt: + binary_sensor: + - name: "Node-RED Panda Up" + unique_id: "nodered_myhost_up" + state_topic: "nodered/panda/status" + payload_on: "online" + payload_off: "offline" + device_class: connectivity + qos: 1 + +healthcheck: + test: ["CMD", "curl", "-f", "http://127.0.0.1:1880/healthz"] + interval: 30s + timeout: 3s + retries: 3