[GH-ISSUE #152] [Feature]: Cost Tracking: Set “Electricity cost per kWh” from a Home Assistant entity #92

Closed
opened 2026-05-06 12:25:39 +02:00 by BreizhHardware · 8 comments

Originally created by @fgrfn on GitHub (Jan 25, 2026).
Original GitHub issue: https://github.com/maziggy/bambuddy/issues/152

Originally assigned to: @maziggy on GitHub.

Problem or Use Case

The current “Electricity cost per kWh” in Cost Tracking is a manually configured static value. For users on dynamic electricity tariffs (e.g., Tibber, Octopus Energy), the price changes frequently (hourly or more).
Because the value in Bambuddy is static, cost calculations can be inaccurate unless users constantly update the setting manually. Many users already have the current electricity price available in Home Assistant via sensors/entities provided by their energy provider integration.

Proposed Solution

Allow the current “Electricity cost per kWh” value to be determined automatically from a selectable Home Assistant entity.

Alternatives Considered

no

Feature Category

Monitoring & Stats

Priority

Nice to have

Mockups or Examples

No response

Contribution

  • I would be willing to help implement this feature

Checklist

  • I have searched existing issues to ensure this feature hasn't already been requested
Originally created by @fgrfn on GitHub (Jan 25, 2026). Original GitHub issue: https://github.com/maziggy/bambuddy/issues/152 Originally assigned to: @maziggy on GitHub. ### Problem or Use Case The current “Electricity cost per kWh” in Cost Tracking is a manually configured static value. For users on dynamic electricity tariffs (e.g., Tibber, Octopus Energy), the price changes frequently (hourly or more). Because the value in Bambuddy is static, cost calculations can be inaccurate unless users constantly update the setting manually. Many users already have the current electricity price available in Home Assistant via sensors/entities provided by their energy provider integration. ### Proposed Solution Allow the current “Electricity cost per kWh” value to be determined automatically from a selectable Home Assistant entity. ### Alternatives Considered no ### Feature Category Monitoring & Stats ### Priority Nice to have ### Mockups or Examples _No response_ ### Contribution - [ ] I would be willing to help implement this feature ### Checklist - [x] I have searched existing issues to ensure this feature hasn't already been requested
BreizhHardware 2026-05-06 12:25:39 +02:00
Author
Owner

@maziggy commented on GitHub (Jan 25, 2026):

What's about an API endpoint to change the price?

<!-- gh-comment-id:3796057391 --> @maziggy commented on GitHub (Jan 25, 2026): What's about an API endpoint to change the price?
Author
Owner

@fgrfn commented on GitHub (Jan 25, 2026):

What's about an API endpoint to change the price?

Yes, that should work. Home Assistant can push the price to an API endpoint using rest_command and an automation.

<!-- gh-comment-id:3796206931 --> @fgrfn commented on GitHub (Jan 25, 2026): > What's about an API endpoint to change the price? Yes, that should work. Home Assistant can push the price to an API endpoint using rest_command and an automation.
Author
Owner

@maziggy commented on GitHub (Jan 25, 2026):

API endpoint is already there. Added docs -> https://wiki.bambuddy.cool/features/energy/?h=dynamic+electricity+rates#dynamic-electricity-rates

Please let me know if it works for you.

<!-- gh-comment-id:3796441979 --> @maziggy commented on GitHub (Jan 25, 2026): API endpoint is already there. Added docs -> https://wiki.bambuddy.cool/features/energy/?h=dynamic+electricity+rates#dynamic-electricity-rates Please let me know if it works for you.
Author
Owner

@fgrfn commented on GitHub (Jan 25, 2026):

Hi @maziggy , thanks! I tried it, but it doesn’t seem to work.

Home Assistant rest_command call to PATCH http://10.10.10.10:8000/api/settings returns 405 Method Not Allowed.

Error Log:
Error. Url: http://10.10.10.10:8000/api/settings. Status code 405. Payload: b'{"energy_cost_per_kwh": unavailable}'

BamBuddy Container log output:

INFO:     10.10.20.20:57596 - "PATCH /api/settings HTTP/1.1" 405 Method Not Allowed
INFO:     127.0.0.1:48008 - "GET /health HTTP/1.1" 200 OK

curl -i -X OPTIONS http://10.10.10.10:8000/api/settings" shows:

root@Tower:/app# curl -i -X OPTIONS http://10.10.10.10:8000/api/settings
HTTP/1.1 405 Method Not Allowed
date: Sun, 25 Jan 2026 12:28:30 GMT
server: uvicorn
allow: GET
content-length: 31
content-type: application/json

{"detail":"Method Not Allowed"}

It looks like Bambuddy doesn’t expose the PATCH handler for /api/settings ?

<!-- gh-comment-id:3796587930 --> @fgrfn commented on GitHub (Jan 25, 2026): Hi @maziggy , thanks! I tried it, but it doesn’t seem to work. Home Assistant rest_command call to PATCH http://10.10.10.10:8000/api/settings returns 405 Method Not Allowed. Error Log: Error. Url: http://10.10.10.10:8000/api/settings. Status code 405. Payload: b'{"energy_cost_per_kwh": unavailable}' BamBuddy Container log output: ``` INFO: 10.10.20.20:57596 - "PATCH /api/settings HTTP/1.1" 405 Method Not Allowed INFO: 127.0.0.1:48008 - "GET /health HTTP/1.1" 200 OK ``` curl -i -X OPTIONS http://10.10.10.10:8000/api/settings" shows: ``` root@Tower:/app# curl -i -X OPTIONS http://10.10.10.10:8000/api/settings HTTP/1.1 405 Method Not Allowed date: Sun, 25 Jan 2026 12:28:30 GMT server: uvicorn allow: GET content-length: 31 content-type: application/json {"detail":"Method Not Allowed"} ``` It looks like Bambuddy doesn’t expose the PATCH handler for /api/settings ?
Author
Owner

@maziggy commented on GitHub (Jan 25, 2026):

Yup, let me check this....

<!-- gh-comment-id:3796593581 --> @maziggy commented on GitHub (Jan 25, 2026): Yup, let me check this....
Author
Owner

@maziggy commented on GitHub (Jan 25, 2026):

This is now fixed in branch 0.1.6-final. Let me know if it works now.

Please note: endpoint is /api/v1/settings, not /api/settings!!!

Please also note: The error shows b'{"energy_cost_per_kwh": unavailable}' - unavailable is not valid JSON (should be a number or null). You may need to handle unavailable sensor states in your HA automation before sending the request.

<!-- gh-comment-id:3796610426 --> @maziggy commented on GitHub (Jan 25, 2026): This is now fixed in branch 0.1.6-final. Let me know if it works now. Please note: endpoint is /api/v1/settings, not /api/settings!!! Please also note: The error shows b'{"energy_cost_per_kwh": unavailable}' - unavailable is not valid JSON (should be a number or null). You may need to handle unavailable sensor states in your HA automation before sending the request.
Author
Owner

@fgrfn commented on GitHub (Jan 25, 2026):

This is now fixed in branch 0.1.6-final. Let me know if it works now.

Please note: endpoint is /api/v1/settings, not /api/settings!!!

Please also note: The error shows b'{"energy_cost_per_kwh": unavailable}' - unavailable is not valid JSON (should be a number or null). You may need to handle unavailable sensor states in your HA automation before sending the request.

Thanks for the update!

After applying the changes from the 0.1.6-final branch, everything works as expected now 👍

Regarding the endpoint: I already suspected this, but since the docs mentioned /api/settings, I tried that endpoint again before. With the updated version, it’s now clear and working correctly.

The Home Assistant automation example in the docs can’t be used 1:1 in a Home Assistant configuration. The following automation works reliably for me and avoids pushing unknown / unavailable sensor states.

- id: 'bambuddy_push_electricity_price'
  alias: "Update Bambuddy Electricity Price"
  mode: restart
  trigger:
    - platform: state
      entity_id: sensor.electricity_price
      for: "00:00:05"
  condition:
    - condition: template
      value_template: >
        {{ states('sensor.electricity_price')|float(none) is not none }}
  action:
    - delay: "00:00:01"
    - service: rest_command.bambuddy_electricity_price

Thanks again for the quick fix and the great work on Bambuddy!

<!-- gh-comment-id:3796646827 --> @fgrfn commented on GitHub (Jan 25, 2026): > This is now fixed in branch 0.1.6-final. Let me know if it works now. > > Please note: endpoint is /api/v1/settings, not /api/settings!!! > > Please also note: The error shows b'{"energy_cost_per_kwh": unavailable}' - unavailable is not valid JSON (should be a number or null). You may need to handle unavailable sensor states in your HA automation before sending the request. Thanks for the update! After applying the changes from the 0.1.6-final branch, everything works as expected now 👍 Regarding the endpoint: I already suspected this, but since the docs mentioned /api/settings, I tried that endpoint again before. With the updated version, it’s now clear and working correctly. The Home Assistant automation example in the docs can’t be used 1:1 in a Home Assistant configuration. The following automation works reliably for me and avoids pushing `unknown` / `unavailable` sensor states. ``` - id: 'bambuddy_push_electricity_price' alias: "Update Bambuddy Electricity Price" mode: restart trigger: - platform: state entity_id: sensor.electricity_price for: "00:00:05" condition: - condition: template value_template: > {{ states('sensor.electricity_price')|float(none) is not none }} action: - delay: "00:00:01" - service: rest_command.bambuddy_electricity_price ``` Thanks again for the quick fix and the great work on Bambuddy!
Author
Owner

@maziggy commented on GitHub (Jan 25, 2026):

Wiki updated.

<!-- gh-comment-id:3796806072 --> @maziggy commented on GitHub (Jan 25, 2026): Wiki updated.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/bambuddy#92
No description provided.