Skip to content

Conversation

@juame
Copy link

@juame juame commented Nov 11, 2025

Breaking change

Proposed change

This PR adds Ws (watt-second) as a unit of energy.

Architecture Decision: home-assistant/architecture#1307

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New integration (thank you!)
  • New feature (which adds functionality to an existing integration)
  • Deprecation (breaking change to happen in the future)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Additional information

Checklist

  • I understand the code I am submitting and can explain how it works.
  • The code change is tested and works locally.
  • Local tests pass. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the development checklist
  • I have followed the perfect PR recommendations
  • The code has been formatted using Ruff (ruff format homeassistant tests)
  • Tests have been added to verify that the new code works.
  • Any generated code has been carefully reviewed for correctness and compliance with project standards.

If user exposed functionality or configuration variables are added/changed:

If the code communicates with devices, web services, or third-party tools:

  • The manifest file has all fields filled out correctly.
    Updated and included derived files by running: python3 -m script.hassfest.
  • New or updated dependencies have been added to requirements_all.txt.
    Updated by running python3 -m script.gen_requirements_all.
  • For the updated dependencies - a link to the changelog, or at minimum a diff between library versions is added to the PR description.

To help with the load of incoming pull requests:

@home-assistant
Copy link

Hey there @home-assistant/core, mind taking a look at this pull request as it has been labeled with an integration (sensor) you are listed as a code owner for? Thanks!

Code owner commands

Code owners of sensor can trigger bot actions by commenting:

  • @home-assistant close Closes the pull request.
  • @home-assistant rename Awesome new title Renames the pull request.
  • @home-assistant reopen Reopen the pull request.
  • @home-assistant unassign sensor Removes the current integration label and assignees on the pull request, add the integration domain after the command.
  • @home-assistant add-label needs-more-information Add a label (needs-more-information, problem in dependency, problem in custom component) to the pull request.
  • @home-assistant remove-label needs-more-information Remove a label (needs-more-information, problem in dependency, problem in custom component) on the pull request.

@home-assistant
Copy link

Hey there @home-assistant/core, @Shulyaka, mind taking a look at this pull request as it has been labeled with an integration (number) you are listed as a code owner for? Thanks!

Code owner commands

Code owners of number can trigger bot actions by commenting:

  • @home-assistant close Closes the pull request.
  • @home-assistant rename Awesome new title Renames the pull request.
  • @home-assistant reopen Reopen the pull request.
  • @home-assistant unassign number Removes the current integration label and assignees on the pull request, add the integration domain after the command.
  • @home-assistant add-label needs-more-information Add a label (needs-more-information, problem in dependency, problem in custom component) to the pull request.
  • @home-assistant remove-label needs-more-information Remove a label (needs-more-information, problem in dependency, problem in custom component) on the pull request.

@home-assistant
Copy link

Hey there @Petro31, @home-assistant/core, mind taking a look at this pull request as it has been labeled with an integration (template) you are listed as a code owner for? Thanks!

Code owner commands

Code owners of template can trigger bot actions by commenting:

  • @home-assistant close Closes the pull request.
  • @home-assistant rename Awesome new title Renames the pull request.
  • @home-assistant reopen Reopen the pull request.
  • @home-assistant unassign template Removes the current integration label and assignees on the pull request, add the integration domain after the command.
  • @home-assistant add-label needs-more-information Add a label (needs-more-information, problem in dependency, problem in custom component) to the pull request.
  • @home-assistant remove-label needs-more-information Remove a label (needs-more-information, problem in dependency, problem in custom component) on the pull request.

@jamesmyatt
Copy link

jamesmyatt commented Nov 11, 2025

Isn't a "Ws" usually referred to as a Joule ("J")? Are there specific use cases where "Ws" is more common?

UnitOfEnergy.KILO_JOULE: _WH_TO_J,
UnitOfEnergy.MEGA_JOULE: _WH_TO_J / 1e3,
UnitOfEnergy.GIGA_JOULE: _WH_TO_J / 1e6,
UnitOfEnergy.WATT_SECOND: 3.6e6,
Copy link

@jamesmyatt jamesmyatt Nov 11, 2025

Choose a reason for hiding this comment

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

Personally, I'd make this match the "JOULE" conversion implementation. i.e. _WH_TO_J * 1e3.

Copy link
Author

Choose a reason for hiding this comment

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

Thanks for your review! 👍
I added _WH_TO_WS since I thought using the same _WH_TO_J might be confusing.
But please let me know if you’d prefer that I use the same constant instead!

Choose a reason for hiding this comment

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

I'm not a maintainer, but I don't see the need to duplicate the constants.

@juame
Copy link
Author

juame commented Nov 12, 2025

Isn't a "Ws" usually referred to as a Joule ("J")? Are there specific use cases where "Ws" is more common?

It's the same, but probably depends a bit on the context. 😇. From ChatGPT:

⚙️ When to use joules (J):
Use J when you’re talking about energy in general, in physics, chemistry, or engineering.
It’s the standard SI unit for energy.

⚡ When to use watt-seconds (W·s):
Use W·s mainly when you want to emphasize the relationship between power and time, especially in electrical or power system contexts.

I guess that in the context of Wh and kWh, people would be more likely to think of Ws rather than J. Therefore, I believe it makes sense to add Ws as an additional unit of energy.

@juame juame requested a review from jamesmyatt November 12, 2025 19:52
@jamesmyatt
Copy link

Can you find some examples in smart homes where "Ws" is a commonly used unit? Don't believe everything that ChatGPT tells you.

Copy link
Member

@jpbede jpbede left a comment

Choose a reason for hiding this comment

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

This changes our core entity models and thus requires a approved architecture discussion.

Please open a discussion at https://github.com/home-assistant/architecture/discussions. Provide some context and which core integrations would benefit from this unit of energy.

@home-assistant home-assistant bot marked this pull request as draft November 13, 2025 06:21
@home-assistant
Copy link

Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍

Learn more about our pull request process.

@juame
Copy link
Author

juame commented Nov 13, 2025

Can you find some examples in smart homes where "Ws" is a commonly used unit?

Just one example, the MyStrom API returns Ws. #155132 (comment)

My understanding is that the conversion from Ws to a human-readable format should be handled by the unit_conversion, not directly in the integration code. Let me know if I'm wrong.

This changes our core entity models and thus requires a approved architecture discussion.

Thanks @jpbede , will do!

@jamesmyatt
Copy link

I'm just a community member, but I don't think that 1 rare example is enough to add something that's just a duplicate of "J", which already exists. But it's not up to me. But let's transfer this to the architecture discussion.

@Petro31
Copy link
Contributor

Petro31 commented Nov 13, 2025

I'm in agreement here, I don't see the benefit when we have Joules. A 2 second google of watt second returns joules and that should satisfy anyones needs. The graph would be identical to Ws. It would just show J over time instead of Ws over time.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants