Skip to content

[co2signal] Update to Electricity Maps API & Add Ring Gauges#398

Open
harper wants to merge 1 commit intotronbyt:mainfrom
harper:co2signal-electricity-maps-api
Open

[co2signal] Update to Electricity Maps API & Add Ring Gauges#398
harper wants to merge 1 commit intotronbyt:mainfrom
harper:co2signal-electricity-maps-api

Conversation

@harper
Copy link

@harper harper commented Mar 7, 2026

Summary

The CO2Signal API (api.co2signal.com) has been shut down. This updates the app to use the Electricity Maps API v3, which is its successor and requires the same API key. It also adds new ring gauge visualizations.

  • Switch API from api.co2signal.com/v1 to api.electricitymaps.com/v3
  • Two API calls per refresh: carbon-intensity/latest + power-breakdown/latest (power breakdown is a separate endpoint in v3)
  • Three-frame animation cycling every 3 seconds:
    1. Carbon intensity, grid zone, and fossil fuel percentage (original view)
    2. Ring gauge — renewable energy percentage
    3. Ring gauge — fossil-free energy percentage
  • Ring gauges use color-coded progress dots (green ≥66%, yellow ≥33%, red <33%)
  • Updated schema field label and API key link to electricitymaps.com

Notes

This is a port of a PR I opened against tidbyt/community (#3166), which appears to no longer be actively merging contributions. The secret = True field already present in this repo's version of the app has been preserved.

Test plan

  • App renders without API key (shows "Configure Settings" message)
  • App fetches and displays carbon intensity for configured location
  • Animation cycles through all three frames
  • Ring gauges display correct percentage and color

🤖 Generated with Claude Code

Updates the CO2 Signal app to use the Electricity Maps v3 API (co2signal.com
has shut down). Adds ring gauge animation frames for renewable and fossil-free
energy percentages.

Changes:
- Switch API from api.co2signal.com/v1 to api.electricitymaps.com/v3
- Two API calls: carbon-intensity/latest + power-breakdown/latest
- Three-frame animation (3s delay): carbon intensity, renewable gauge, fossil-free gauge
- Ring gauge visualization with color-coded progress dots (green/yellow/red)
- Update schema text and links to electricitymaps.com

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
@harper harper requested a review from tavdog as a code owner March 7, 2026 18:27
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request modernizes the CO2 Signal application by migrating its data source from the defunct CO2Signal API to the Electricity Maps API v3. The update enhances the user experience with new, dynamic visualizations, including animated ring gauges that provide a clearer understanding of renewable and fossil-free energy contributions. These changes ensure the app remains functional and provides more comprehensive energy data.

Highlights

  • API Migration: The application has been updated to use the Electricity Maps API v3, replacing the deprecated CO2Signal API. This involves changing the base URL and adapting API call logic.
  • Dual API Calls: Data retrieval now involves two separate API calls: one for 'carbon-intensity/latest' and another for 'power-breakdown/latest', as the power breakdown is no longer included in the carbon intensity endpoint.
  • New Visualizations: Introduced two new ring gauge visualizations to display renewable energy percentage and fossil-free energy percentage, in addition to the original carbon intensity view.
  • Animated Display: The app now cycles through three frames every 3 seconds: the original carbon intensity view, the renewable energy gauge, and the fossil-free energy gauge.
  • Color-Coded Gauges: The new ring gauges feature color-coded progress dots (green for >=66%, yellow for >=33%, red for <33%) to visually represent efficiency.
  • Schema and UI Updates: The API key field label and description have been updated to reflect the new Electricity Maps branding and website.
Changelog
  • apps/co2signal/co2_signal.star
    • Updated the app description to reflect the use of the Electricity Maps API.
    • Changed the base URL for API requests from CO2Signal to Electricity Maps v3.
    • Modified the schema to rename the API key field and update its associated link to Electricity Maps.
    • Updated the displayed app name from 'CO2Signal' to 'Electricity Maps CO2'.
    • Refactored data fetching to make separate API calls for carbon intensity and power breakdown.
    • Implemented logic to extract and calculate renewable, fossil-free, and fossil fuel percentages from the new API responses.
    • Introduced a three-frame animation cycle for the display, incorporating new ring gauge visualizations.
    • Added helper functions get_efficiency_color and render_gauge to support the new ring gauge rendering.
  • apps/co2signal/manifest.yaml
    • Updated the application's long description to mention the Electricity Maps API.
Activity
  • No human activity has occurred on this pull request yet.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request updates the app to use the new Electricity Maps API, replacing the deprecated CO2Signal API. It also introduces new animated frames with ring gauges to visualize renewable and fossil-free energy percentages. The changes are mostly correct, but there are a couple of issues. There's a minor typo in a code comment. More importantly, the percentage values from the API are being truncated instead of rounded, which can lead to inaccurate visualizations on the new gauges. I've provided suggestions to fix these issues.

if "fossilFreePercentage" in raw_breakdown and raw_breakdown["fossilFreePercentage"] != None:
# If fossilFreePercentage is available, fossil is 100 - that.
# Ensure it's treated as a number.
fossil_free_percentage = int(raw_breakdown["fossilFreePercentage"])
Copy link
Contributor

Choose a reason for hiding this comment

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

high

Using int() to convert the percentage from the API response truncates the decimal part, which can lead to inaccurate display. For example, a value of 65.9% would become 65%, potentially showing the wrong color on the gauge since the threshold is 66%. It's better to round the value to the nearest integer using math.round().

Suggested change
fossil_free_percentage = int(raw_breakdown["fossilFreePercentage"])
fossil_free_percentage = int(math.round(raw_breakdown["fossilFreePercentage"]))

print("fossilFreePercentage not found in breakdown")

if "renewablePercentage" in raw_breakdown and raw_breakdown["renewablePercentage"] != None:
renewable_percentage = int(raw_breakdown["renewablePercentage"])
Copy link
Contributor

Choose a reason for hiding this comment

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

high

Similar to fossilFreePercentage, using int() here truncates the value, which can lead to inaccuracies. It's better to round the value to the nearest integer.

Suggested change
renewable_percentage = int(raw_breakdown["renewablePercentage"])
renewable_percentage = int(math.round(raw_breakdown["renewablePercentage"]))

return render_data(api_key, location)

# Location and CO2Signal API key are required settings.
# Location and electicity API key are required settings.
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

There is a typo in 'electicity'.

Suggested change
# Location and electicity API key are required settings.
# Location and electricity API key are required settings.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant