Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update time and temperature cookbook #4783

Open
wants to merge 4 commits into
base: current
Choose a base branch
from

Conversation

yincrash
Copy link

Description:

Use a temperature that comes with the default Home Assistant setup - weather
Show how to use google fonts so a user doesn't have to setup font files to get something running.

Checklist:

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

  • 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.

Use a temperature that comes with the default Home Assistant setup - weather
Show how to use google fonts so a user doesn't have to setup font files to get something running.
@yincrash
Copy link
Author

I'm a new ESPHome user and definitely really love the cookbooks, but I wanted to get something up and running as fast as possible to see what I could do, and so I thought a few changes to this cookbook would make it simpler for a new user who may not have a temperature sensor set up, but could get something showing up immediately.

Copy link
Contributor

coderabbitai bot commented Mar 31, 2025

Walkthrough

The update modifies the sensor configuration and font definitions in the documentation. It changes the temperature sensor setup to import a single weather forecast (providing both temperature and unit details) instead of two separate sensors, and adds a new text sensor for the temperature unit. Additionally, generic font identifiers have been updated to descriptive names, and new Google font entries have been introduced with specified file paths and sizes. The display output text has also been updated accordingly.

Changes

File(s) Change Summary
cookbook/...display_time_temp_oled.rst (sensors & display) Updated sensor configuration: Changed outside_temperature sensor to use weather.forecast_home with a temperature attribute; added a new outside_temperature_unit text sensor. Modified display output text from "Mitt Smarta Hus" to "Time and Temperature" with updated formatting for inside and outside temperatures.
cookbook/...display_time_temp_oled.rst (fonts) Updated font identifiers from font1, font2, font3 to small, medium, large. Added new Google font entries (gfonts://Silkscreen, gfonts://Roboto) with specified file paths and sizes.

Sequence Diagram(s)

sequenceDiagram
    participant HA as Home Assistant
    participant Sensor as Sensor Module
    participant Display as OLED Display Logic

    HA->>Sensor: Provide weather.forecast_home data
    Sensor->>Display: Relay temperature and unit data
    Display->>Display: Format data using updated fonts ("medium" for inside, descriptive font for outside)
    Display->>User: Render "Time and Temperature" output
Loading

Suggested reviewers

  • clydebarrow
  • jesserockz

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between fc00254 and 0376336.

📒 Files selected for processing (1)
  • cookbook/display_time_temp_oled.rst (6 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • cookbook/display_time_temp_oled.rst

🪧 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.
    • Generate unit testing code for this file.
    • 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. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • 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 src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

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

Documentation and Community

  • 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: 0

🧹 Nitpick comments (1)
cookbook/display_time_temp_oled.rst (1)

98-113: Add Alternative Google Fonts Configuration
A new code block introduces font definitions using the gfonts:// scheme, offering an alternative to local TrueType fonts. It is recommended to clarify within the documentation that this block is optional and should not be active simultaneously with the local font definitions to avoid potential conflicts in id usage.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0f59453 and 78f1064.

📒 Files selected for processing (1)
  • cookbook/display_time_temp_oled.rst (5 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
`**`: - Do not generate or add any sequence diagrams

**: - Do not generate or add any sequence diagrams

  • cookbook/display_time_temp_oled.rst
🔇 Additional comments (7)
cookbook/display_time_temp_oled.rst (7)

48-48: Clarify Temperature Sensor Introduction
The updated sentence now indicates that a single temperature sensor along with the complete weather forecast data will be imported from Home Assistant. This change clearly sets the stage for the configuration that follows.


64-67: Update Outside Temperature Sensor Configuration
The sensor configuration now uses entity_id: weather.forecast_home with the specified attribute: temperature and marks it as internal. This change streamlines the setup by relying on the weather forecast entity instead of a separate sensor. Ensure that the Home Assistant entity weather.forecast_home reliably provides the temperature attribute.


68-72: Introduce Text Sensor for Temperature Unit
A new text sensor has been added to retrieve the temperature unit via the attribute temperature_unit from the same weather entity. This clearly separates the temperature value from its unit, enhancing readability and display precision. Please verify that Home Assistant supports this attribute for the given entity.


87-97: Adopt Descriptive Font Identifiers
The font definitions have been updated from generic identifiers (font1, font2, font3) to descriptive names (small, medium, large). This improves clarity in the documentation and ensures that references in the lambda code are self-explanatory.


138-142: Update Display Header Text in Lambda
The lambda section now prints "Time and" and "Temperature" using the updated small and large fonts respectively. This change aligns the display header with the revised sensor configuration and font naming conventions.


146-151: Refine Sensor Value Display in Lambda
The lambda now prints the inside temperature using the medium font and displays the outside temperature concatenated with its unit by converting the text sensor state with .c_str(). This integration ensures consistency in presentation. Please ensure that the temperature unit value is formatted safely and is non-empty under all conditions.


164-164: Provide Alternative Alarm State Example
The additional example replacing the top display with the Home Assistant alarm state adds valuable flexibility for users. The updated explanatory text is clear, but consider highlighting that this configuration is an alternative to the time and temperature display to avoid confusion.

Copy link

netlify bot commented Mar 31, 2025

Deploy Preview for esphome ready!

Name Link
🔨 Latest commit e7e8945
🔍 Latest deploy log https://app.netlify.com/sites/esphome/deploys/67eb7b227805fe0008fbe616
😎 Deploy Preview https://deploy-preview-4783--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 site configuration.

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

🔭 Outside diff range comments (1)
cookbook/display_time_temp_oled.rst (1)

174-182: 💡 Verification agent

🧩 Analysis chain

Inconsistent Font Identifier in Alarm Display
The lambda for displaying the alarm state still references id(font1) even though the font identifiers have been updated to small, medium, and large. This inconsistency might lead to runtime issues or unintended styling. Consider updating the reference (for example, replacing id(font1) with id(small)) to ensure consistency across the documentation.

Suggested diff:

-          it.printf(64, 0, id(font1), TextAlign::TOP_CENTER, "Alarm State: %s", id(alarm_state).state.c_str());
+          it.printf(64, 0, id(small), TextAlign::TOP_CENTER, "Alarm State: %s", id(alarm_state).state.c_str());

Critical Update Required: Resolve Inconsistent Font Identifier

The lambda for displaying the alarm state in cookbook/display_time_temp_oled.rst (lines 174-182) is still referencing id(font1) instead of one of the updated font identifiers (small, medium, or large). This discrepancy could lead to runtime issues or inconsistent display styling.

  • Action Required: Replace id(font1) with the appropriate updated identifier (e.g., id(small)).

Suggested diff:

-          it.printf(64, 0, id(font1), TextAlign::TOP_CENTER, "Alarm State: %s", id(alarm_state).state.c_str());
+          it.printf(64, 0, id(small), TextAlign::TOP_CENTER, "Alarm State: %s", id(alarm_state).state.c_str());

🏁 Script executed:

#!/bin/bash
# Check for the outdated font reference "id(font1)" in the cookbook file.
rg "id\(font1\)" cookbook/display_time_temp_oled.rst

# Check for updated font identifier usages to validate the expected naming.
rg "id\(small\)" -n .
rg "id\(medium\)" -n .
rg "id\(large\)" -n .

Length of output: 1074


Action Required: Update Inconsistent Font Identifier in OLED Alarm Display

The lambda block in cookbook/display_time_temp_oled.rst (lines 174-182) still uses id(font1), which is inconsistent with the updated font identifiers (small, medium, large). The search results confirm that id(small) is used elsewhere in the file, so updating this reference will help avoid potential runtime issues or styling errors.

  • File to update: cookbook/display_time_temp_oled.rst (lines 174-182)
  • Change needed: Replace id(font1) with id(small) (or another appropriate updated font identifier)

Suggested diff:

-          it.printf(64, 0, id(font1), TextAlign::TOP_CENTER, "Alarm State: %s", id(alarm_state).state.c_str());
+          it.printf(64, 0, id(small), TextAlign::TOP_CENTER, "Alarm State: %s", id(alarm_state).state.c_str());
🧹 Nitpick comments (3)
cookbook/display_time_temp_oled.rst (3)

98-113: Enhance Google Fonts Section
The optional Google Fonts section adds value by offering an alternative to including local font files. Ensure that users are aware of any differences in rendering between these fonts and the locally provided ones, especially given the differences in font sizes.


129-130: YAML Comment Style Suggestion
The comments in the i2c configuration use //, which is not standard for YAML (typically using #). If these are meant to be active comments, consider updating them to the YAML comment style to avoid any parsing issues.


149-152: Outside Temperature Display with Unit
The lambda prints the outside temperature along with its unit using the medium font. This approach neatly combines two data points. It may be worth considering a fallback or simple error handling in case the outside_temperature_unit state is empty or invalid.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 78f1064 and 7940b36.

📒 Files selected for processing (1)
  • cookbook/display_time_temp_oled.rst (5 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
`**`: - Do not generate or add any sequence diagrams

**: - Do not generate or add any sequence diagrams

  • cookbook/display_time_temp_oled.rst
🔇 Additional comments (9)
cookbook/display_time_temp_oled.rst (9)

48-48: Clarify Temperature Sensor Configuration
The update now explains that a single temperature sensor is obtained from Home Assistant’s weather forecast. For extra clarity, you might consider explicitly noting that both the temperature value and its unit are derived from the same weather.forecast_home entity.


62-67: Update Outside Temperature Sensor
The sensor configuration now correctly references the Home Assistant weather forecast by specifying entity_id: weather.forecast_home along with the attribute: temperature. This aligns well with the PR objectives.


68-73: Add Temperature Unit Text Sensor
Introducing a text sensor to extract the temperature unit from weather.forecast_home is a smart move. Please verify that the chosen weather entity indeed provides the temperature_unit attribute, so the display can render the correct unit.


85-97: Update Font Identifiers for Clarity
The font configuration block has been updated to use descriptive identifiers (small, medium, large) instead of generic names. This improves readability and consistency. The associated file names and sizes appear intentional.


138-139: Updated Display Text for Time and Temperature
The lambda now prints "Time and" and "Temperature" using the updated small font identifier. This change clearly reflects the intended updates. Just verify that the text alignment and font size work optimally on the OLED display.


142-142: Time Formatting Check
Time is rendered using %H:%M with the large font, which is appropriate. Confirm that this format and font size meet the layout requirements for the display.


145-147: Inside Temperature Display
The inside temperature is displayed with the medium font, ensuring legible output. Double-check that the numerical formatting ("%.1f") is consistent with the sensor’s data type and expected display.


164-164: Clear Explanation for Alarm Example
The description introducing the alarm state example is clear and concise. It successfully communicates the transition from the default time and temperature display to an alternative alarm status display.


168-173: Alarm State Text Sensor Configuration
The alarm state text sensor is configured correctly and should integrate seamlessly with the subsequent display configuration.

@yincrash yincrash force-pushed the yincrash/time-and-temp-cookbook branch from fc00254 to 0376336 Compare April 1, 2025 01:32
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.

1 participant