Conversation
…nt RGB LED staying on during deep sleep The WS2812 LED was staying slightly on after entering deep sleep despite on_shutdown containing light.turn_off. Root cause: addressable lights schedule their state update for the next main loop iteration, but the loop stops running during shutdown before the RMT signal is transmitted. Explicitly specifying transition_length: 0ms bypasses the loop-based timing mechanism, ensuring the off command is sent synchronously. Fix applied to all 7 YAML variants. Ref: esphome/issues#6800
WalkthroughMultiple ESPHome YAMLs standardize shutdown light calls to an explicit mapping, add an explicit RGB light turn-off plus a 200ms delay before entering deep sleep in various on_boot / OTA / client-connected paths, and add accessory power switch turn-offs in some shutdown sequences. Changes
Sequence Diagram(s)sequenceDiagram
participant Boot as on_boot / flow
participant API as api.on_client_connected
participant Light as RGB Light
participant Switch as Accessory Power
participant Deep as Deep Sleep
Boot->>Light: light.turn_off (id: rgb_light, transition_length: 0ms)
Light-->>Boot: ack
Boot->>Boot: delay 200ms
alt shutdown includes accessory power
Boot->>Switch: switch.turn_off (accessory_power)
Switch-->>Boot: ack
end
Boot->>Deep: deep_sleep.enter
Deep-->>Boot: entering sleep
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
…uring sleep The previous fix (transition_length: 0ms in on_shutdown) did not work because on_shutdown runs after the main loop has stopped, so the RMT peripheral never actually transmits the off signal. This fix adds light.turn_off + 50ms delay immediately before every deep_sleep.enter action call, while the main loop is still running and can complete the RMT transmission before sleep is entered. Affects Core.yaml (primary HA-connected path) and all 7 variant files.
Integrations/ESPHome/TEMP-1B.yaml
Outdated
| - binary_sensor.is_off: ota_mode | ||
| - switch.is_off: prevent_sleep | ||
| then: | ||
| - light.turn_off: rgb_light |
There was a problem hiding this comment.
Is this needed if it is already in the on_shutdown?
There was a problem hiding this comment.
Is this needed if it is already in the on_shutdown?
this is a work in progress i'm submitting the PR then testing - so far neither commit is working.
Attempt 2 used the light.turn_off shorthand which may not respect default_transition_length, leaving a ~1s fade active while only waiting 50ms. This combines explicit transition_length: 0ms with a 200ms delay (ample time for RMT transmission to complete) while the main loop is still running. Also reverts on_shutdown back to simple shorthand since that hook runs after the loop has stopped and cannot reliably transmit the RMT signal regardless of transition settings.
…tdown Test whether cutting accessory power on shutdown prevents the dim LED glow during deep sleep, in addition to forcing zero-length light transition.
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (2)
Integrations/ESPHome/Core.yaml (1)
46-50: Consider extracting this sleep preamble into a shared script.This exact
light.turn_off -> delay -> deep_sleep.entersequence is now duplicated inIntegrations/ESPHome/Core.yamland multiple variants. Centralizing it in one script would make future timing or target-id changes much safer.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@Integrations/ESPHome/Core.yaml` around lines 46 - 50, Extract the repeated sequence (light.turn_off with id: rgb_light, transition_length: 0ms -> delay 200ms -> deep_sleep.enter) into a single reusable script (e.g., script: sleep_preamble) and replace the inline sequence with a single call to that script (e.g., script.execute: sleep_preamble) wherever it appears; centralize the transition_length and delay values inside that script so future timing or target-id changes are made in one place and ensure the script name and target (rgb_light) match the existing usage.Integrations/ESPHome/TEMP-1B_BLE.yaml (1)
73-78: Review the indentation convention under thethen:block.The sequence items (
light.turn_off,delay,deep_sleep.enter) should be indented further than thethen:key to follow YAML and ESPHome conventions. While the file parses, proper indentation improves readability and consistency with the rest of the configuration.Suggested fix
then: - - light.turn_off: - id: rgb_light - transition_length: 0ms - - delay: 200ms - - deep_sleep.enter: - id: deep_sleep_1 + - light.turn_off: + id: rgb_light + transition_length: 0ms + - delay: 200ms + - deep_sleep.enter: + id: deep_sleep_1🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@Integrations/ESPHome/TEMP-1B_BLE.yaml` around lines 73 - 78, The sequence under the then: key is not indented to the same level as other action lists; re-indent the action sequence so each item (light.turn_off with id: rgb_light, delay, deep_sleep.enter with id: deep_sleep_1) is nested one level deeper than then: to follow YAML/ESPHome conventions and match the rest of the file's action lists.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@Integrations/ESPHome/TEMP-1_BLE.yaml`:
- Around line 73-78: The YAML's then: action list uses a different indentation
style than the on_shutdown: block; update the then: block so each list item is
indented two spaces under the parent key to match the file style—adjust the
lines containing the actions light.turn_off (id: rgb_light), delay: 200ms, and
deep_sleep.enter (id: deep_sleep_1) so their leading hyphens and nested keys
follow the same 2-space indentation pattern as the on_shutdown: block.
---
Nitpick comments:
In `@Integrations/ESPHome/Core.yaml`:
- Around line 46-50: Extract the repeated sequence (light.turn_off with id:
rgb_light, transition_length: 0ms -> delay 200ms -> deep_sleep.enter) into a
single reusable script (e.g., script: sleep_preamble) and replace the inline
sequence with a single call to that script (e.g., script.execute:
sleep_preamble) wherever it appears; centralize the transition_length and delay
values inside that script so future timing or target-id changes are made in one
place and ensure the script name and target (rgb_light) match the existing
usage.
In `@Integrations/ESPHome/TEMP-1B_BLE.yaml`:
- Around line 73-78: The sequence under the then: key is not indented to the
same level as other action lists; re-indent the action sequence so each item
(light.turn_off with id: rgb_light, delay, deep_sleep.enter with id:
deep_sleep_1) is nested one level deeper than then: to follow YAML/ESPHome
conventions and match the rest of the file's action lists.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 294d8c1d-c3b1-4c85-bf44-a8e40005d198
📒 Files selected for processing (8)
Integrations/ESPHome/Core.yamlIntegrations/ESPHome/TEMP-1.yamlIntegrations/ESPHome/TEMP-1B.yamlIntegrations/ESPHome/TEMP-1B_BLE.yamlIntegrations/ESPHome/TEMP-1B_Minimal.yamlIntegrations/ESPHome/TEMP-1_BLE.yamlIntegrations/ESPHome/TEMP-1_Beta.yamlIntegrations/ESPHome/TEMP-1_Minimal.yaml
🚧 Files skipped from review as they are similar to previous changes (3)
- Integrations/ESPHome/TEMP-1.yaml
- Integrations/ESPHome/TEMP-1_Beta.yaml
- Integrations/ESPHome/TEMP-1_Minimal.yaml
| - light.turn_off: | ||
| id: rgb_light | ||
| transition_length: 0ms | ||
| - delay: 200ms | ||
| - deep_sleep.enter: | ||
| id: deep_sleep_1 |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
python -c 'import yaml' 2>/dev/null || pip install --quiet pyyaml
python - <<'PY'
from pathlib import Path
import yaml
class Loader(yaml.SafeLoader):
pass
def unknown(loader, tag_suffix, node):
if isinstance(node, yaml.ScalarNode):
return loader.construct_scalar(node)
if isinstance(node, yaml.SequenceNode):
return loader.construct_sequence(node)
return loader.construct_mapping(node)
Loader.add_multi_constructor('!', unknown)
path = Path("Integrations/ESPHome/TEMP-1_BLE.yaml")
with path.open() as f:
yaml.load(f, Loader=Loader)
print(f"{path}: YAML parsed successfully")
PYRepository: ApolloAutomation/TEMP-1
Length of output: 129
🏁 Script executed:
sed -n '70,85p' Integrations/ESPHome/TEMP-1_BLE.yaml | cat -ARepository: ApolloAutomation/TEMP-1
Length of output: 608
🏁 Script executed:
python3 << 'EOF'
from pathlib import Path
path = Path("Integrations/ESPHome/TEMP-1_BLE.yaml")
with path.open() as f:
lines = f.readlines()
# Check lines around 73-78 (0-indexed: 72-77)
for i in range(69, 85):
if i < len(lines):
line = lines[i]
indent = len(line) - len(line.lstrip(' '))
content = line.strip()
print(f"Line {i+1:3d} [indent={indent:2d}]: {content[:60]}")
EOFRepository: ApolloAutomation/TEMP-1
Length of output: 700
Indentation is valid YAML but inconsistent with the file's own style.
The YAML file parses successfully; the current indentation is syntactically correct. However, the then: block uses a different indentation style than the on_shutdown: block below it (lines 80–84), which indents list items by 2 spaces under the parent key for readability. For consistency, the then: block items should be indented to match that pattern.
Suggested style alignment
then:
- - light.turn_off:
- id: rgb_light
- transition_length: 0ms
- - delay: 200ms
- - deep_sleep.enter:
- id: deep_sleep_1
+ - light.turn_off:
+ id: rgb_light
+ transition_length: 0ms
+ - delay: 200ms
+ - deep_sleep.enter:
+ id: deep_sleep_1📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| - light.turn_off: | |
| id: rgb_light | |
| transition_length: 0ms | |
| - delay: 200ms | |
| - deep_sleep.enter: | |
| id: deep_sleep_1 | |
| - light.turn_off: | |
| id: rgb_light | |
| transition_length: 0ms | |
| - delay: 200ms | |
| - deep_sleep.enter: | |
| id: deep_sleep_1 |
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@Integrations/ESPHome/TEMP-1_BLE.yaml` around lines 73 - 78, The YAML's then:
action list uses a different indentation style than the on_shutdown: block;
update the then: block so each list item is indented two spaces under the parent
key to match the file style—adjust the lines containing the actions
light.turn_off (id: rgb_light), delay: 200ms, and deep_sleep.enter (id:
deep_sleep_1) so their leading hyphens and nested keys follow the same 2-space
indentation pattern as the on_shutdown: block.
|
closing as cant fix due to esphome bug. esphome/issues#6800 |
Summary
on_shutdowncontaininglight.turn_off: rgb_lighttransition_length: 0mson alllight.turn_offcalls inon_shutdownhooks — this bypasses the loop-based timing mechanism so the off command is sent immediatelyConfirmed fix per ESPHome issue #6800.
Files changed
All 7 YAML variants updated:
TEMP-1,TEMP-1B,TEMP-1_Minimal,TEMP-1B_Minimal,TEMP-1_BLE,TEMP-1B_BLE,TEMP-1_BetaTest plan
Summary by CodeRabbit
Chores
Bug Fixes