Skip to content

Conversation

orrpan
Copy link

@orrpan orrpan commented Aug 22, 2025

Description:

Related issue (if applicable): fixes

Pull request in esphome with YAML changes (if applicable):

  • esphome/esphome#

Checklist:

  • I am merging into next because this is new documentation that has a matching pull-request in esphome as linked above.
    or

  • [ x] I am merging into current because this is a fix, change and/or adjustment in the current documentation and is not for a new component or feature.

  • Link added in /components/index.rst when creating new documents for new components or cookbook.

New Component Images

If you are adding a new component to ESPHome, you can automatically generate a standardized black and white component name image for the documentation.

To generate a component image:

  1. Comment on this pull request with the following command, replacing COMPONENT_NAME with your component name in UPPER_CASE format with underscores (e.g., BME280, SHT3X, DALLAS_TEMP):

    @esphomebot generate image COMPONENT_NAME
    
  2. The ESPHome bot will respond with a downloadable ZIP file containing the SVG image.

  3. Extract the SVG file and place it in the images/ folder of this repository.

  4. Use the image in your component's index table entry in /components/index.rst.

Example: For a component called "DHT22 Temperature Sensor", use:

@esphomebot generate image DHT22

@esphome esphome bot added the current label Aug 22, 2025
Copy link

netlify bot commented Aug 22, 2025

Deploy Preview for esphome ready!

Name Link
🔨 Latest commit 62a8952
🔍 Latest deploy log https://app.netlify.com/projects/esphome/deploys/68a8e2d5b5d9e100086a2206
😎 Deploy Preview https://deploy-preview-5274--esphome.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Copy link
Contributor

coderabbitai bot commented Aug 22, 2025

Walkthrough

Added a “Sensor halting” section to the DHT documentation showing a YAML example that power-cycles a stalled DHT via a GPIO-powered switch when a NaN reading is detected; notes updated about humidity decimals, model selection, pull-up resistor usage, and placement after update_interval details.

Changes

Cohort / File(s) Summary
Docs: DHT sensor guidance
content/components/sensor/dht.md
Added a “Sensor halting” section with a YAML example using a GPIO power switch (example uses pwrsensor on GPIO12 powering DHT on GPIO14) that checks isnan(x) in an on_value trigger to power-cycle (off → delay 5s → on); mirrored halting block in full sensor config; clarified humidity accuracy_decimals (DHT11 defaults to 0, other DHTs recommend 1), model selection guidance, pull-up resistor considerations (note to set pullup: false if using external pull-up), and placed the section after update_interval guidance.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor ESPNode as ESPHome Node
  participant DHT as DHT Sensor
  participant PwrSwitch as GPIO Power Switch

  ESPNode->>DHT: Periodic read (update_interval: 30s)
  DHT-->>ESPNode: Temperature/Humidity value
  alt Reading is NaN
    ESPNode->>PwrSwitch: Turn OFF (pwrsensor -> false)
    Note right of PwrSwitch #DDEBF7: Power-cycle start
    ESPNode->>ESPNode: Wait 5s
    ESPNode->>PwrSwitch: Turn ON (pwrsensor -> true)
    Note right of DHT #F7F3DE: Sensor re-initializes
  else Reading valid
    ESPNode->>ESPNode: No action
  end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Tip

🔌 Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.

✨ Finishing Touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (4)
content/components/sensor/dht.md (4)

63-69: Prefer a safer power switching pattern; avoid sourcing sensor VCC directly from a GPIO.

Driving VCC from a GPIO can be marginal on some boards (current limits, boot strapping, brownout risk). Recommend switching the sensor’s supply via a transistor/P-MOSFET or a dedicated high-side switch, while controlling that switch from the GPIO.

If you keep the example minimal, at least add a cautionary line to set expectations.

Apply this diff to add a brief safety note and slightly clearer naming:

-  - platform: gpio
-    pin: GPIO12
-    id: pwrsensor
-    name: "Power for sensor"
+  - platform: gpio
+    pin: GPIO12
+    id: dht_power
+    name: "DHT power (via transistor/MOSFET preferred)"
     restore_mode: ALWAYS_ON
@@
-                - switch.turn_off: pwrsensor
+                - switch.turn_off: dht_power
                 - delay: 5s
-                - switch.turn_on: pwrsensor
+                - switch.turn_on: dht_power

Optional doc sentence (immediately above the YAML block):

+A note on power switching: powering a DHT directly from a GPIO is only safe if your MCU pin can supply the required current. Prefer a transistor/MOSFET to switch 3.3V.

Also applies to: 82-85


70-90: Ensure NaN actually propagates to on_value; otherwise, the automation won’t fire on stalls.

In some components, failed reads are logged but NaN is not published, so on_value doesn’t trigger. If DHT does publish NaN, this is fine; if not, consider an interval watchdog that checks isnan(id(current_temperature).state) and power-cycles.

If needed, add this alternative watchdog (outside the DHT block):

interval:
  - interval: 2min
    then:
      - if:
          condition:
            lambda: |-
              return isnan(id(current_temperature).state);
          then:
            - switch.turn_off: dht_power
            - delay: 5s
            - switch.turn_on: dht_power

Also consider mirroring the on_value NaN check on the humidity sensor to increase the chance of catching a bad sample.


86-88: Align the example with the guidance on accuracy_decimals.

The note below suggests 1 decimal for non‑DHT11 models; reflect that in the example. Also, id: current_humidity is unused.

Apply this diff:

     humidity:
       name: "Humidity"
-      id: current_humidity
+      accuracy_decimals: 1

94-96: Polish grammar for clarity.

Minor phrasing adjustments for readability.

Apply this diff:

-The default `accuracy_decimals` value of the *humidity* levels is `0`, as the DHT11 for which this was
-originally written does not have a higher resolution. All other DHT sensors have a higher resolution, it's worth
-to configure them with `accuracy_decimals: 1`.
+The default `accuracy_decimals` for humidity is `0`, as the DHT11 (for which this was
+originally written) does not have a higher resolution. All other DHT sensors have a higher resolution; 
+configure them with `accuracy_decimals: 1`.
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 784eb35 and ccc0b84.

📒 Files selected for processing (1)
  • content/components/sensor/dht.md (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**

⚙️ CodeRabbit configuration file

  • Do not generate or add any sequence diagrams

Files:

  • content/components/sensor/dht.md
🪛 GitHub Check: build
content/components/sensor/dht.md

[failure] 92-92:
Multiple consecutive blank lines [Expected: 1; Actual: 2]


[failure] 62-62:
Fenced code blocks should be surrounded by blank lines [Context: "```yaml"]

🪛 GitHub Actions: Lint
content/components/sensor/dht.md

[error] 62-62: MD031: Fenced code blocks should be surrounded by blank lines.

🔇 Additional comments (1)
content/components/sensor/dht.md (1)

59-61: Title and intro of the new section look good.

Clear, actionable placement right after update_interval. Thanks for adding a concrete recovery pattern.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

♻️ Duplicate comments (1)
content/components/sensor/dht.md (1)

63-64: MD031 fenced‑block spacing now looks correct.

Blank lines before/after the fenced YAML are present and only a single blank line follows the block. Previous lint failures appear resolved.

Also applies to: 91-92

🧹 Nitpick comments (6)
content/components/sensor/dht.md (6)

59-62: Tighten phrasing and fix minor grammar in lead-in sentence.

"A GPIO port as power supply" reads awkwardly. Suggest a clearer, more idiomatic sentence.

- A possible solution is to use a GPIO port as power supply and restart the sensor on error.
+ A possible solution is to use a GPIO pin as the power source and power‑cycle the sensor when a read fails.

63-70: Make the power switch internal to avoid exposing it to Home Assistant.

This switch is purely infrastructural. Hiding it prevents accidental toggling from the UI while preserving restore behavior.

 switch:
   - platform: gpio
     pin: GPIO12
     id: pwrsensor
-    name: "Power for sensor"
+    internal: true
     restore_mode: ALWAYS_ON

59-62: Add a hardware safety warning about sourcing VCC directly from a GPIO.

Some boards can’t safely source sensor VCC from a GPIO; recommending a high‑side P‑MOSFET or low‑side NPN/MOSFET controlled by the GPIO reduces risk. A short doc callout helps readers avoid damage.

 ## Sensor halting

 A possible solution is to use a GPIO pin as the power source and power‑cycle the sensor when a read fails.
+
+{{< warning >}}
+Powering a sensor directly from a GPIO pin may exceed the pin’s current limits on some boards. For robust setups, use the GPIO to drive a transistor/MOSFET (or a dedicated load switch/relay) that switches the sensor’s VCC.
+{{< /warning >}}

71-86: Force an immediate read after power‑cycle to reduce recovery time.

Without this, the component waits until the next update_interval. Adding a component update after a short stabilization delay improves UX. Requires giving the DHT component an id.

 sensor:
   - platform: dht
+    id: dht_sensor
     pin: GPIO14
     temperature:
       name: "Temperature"
       id: current_temperature
       on_value:
         then:
           - if:
               condition:
                 - lambda: "return isnan(x);"
               then:
                 - switch.turn_off: pwrsensor
                 - delay: 5s
                 - switch.turn_on: pwrsensor
+                # Allow sensor to stabilize, then force an immediate update.
+                - delay: 2s
+                - component.update: dht_sensor

Note: Please verify that component.update with the DHT platform id is supported in your ESPHome version. If not, we can switch to updating via a script or adjust to the appropriate component id.


86-90: Also monitor humidity NaNs to catch partial stalls.

In practice, one channel can go NaN while the other still reports. Mirroring the automation for humidity closes that gap.

     humidity:
       name: "Humidity"
       id: current_humidity
+      on_value:
+        then:
+          - if:
+              condition:
+                - lambda: "return isnan(x);"
+              then:
+                - switch.turn_off: pwrsensor
+                - delay: 5s
+                - switch.turn_on: pwrsensor
+                - delay: 2s
+                - component.update: dht_sensor

90-91: Nudge readers to pick the right model in the example.

A small inline comment prevents copy‑paste misconfiguration.

-    model: AM2302
+    # Adjust to match your sensor (AUTO_DETECT works for most except SI7021)
+    model: AM2302
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between ccc0b84 and 5ff6499.

📒 Files selected for processing (1)
  • content/components/sensor/dht.md (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**

⚙️ CodeRabbit configuration file

  • Do not generate or add any sequence diagrams

Files:

  • content/components/sensor/dht.md
🪛 LanguageTool
content/components/sensor/dht.md

[grammar] ~61-~61: There might be a mistake here.
Context: ...possible solution is to use a GPIO port as power supply and restart the sensor on ...

(QB_NEW_EN)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants