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

Make Tibber priceInfo available as attributes of current price #69364

Closed
wants to merge 7 commits into from

Conversation

Knodd
Copy link
Contributor

@Knodd Knodd commented Apr 5, 2022

Added priceInfo for today with timestamp and price level as list in attribute raw_today
Added priceInfo for tomorrow with timestamp and price level as list in attribute raw_tomorrow
Added only prices as list for today and tomorrow as new attributes
Added tomorrow_valid as attribute if array of tomorrows prices are valid
This is the same format as the Nordpool integration, only with Tibber's api keys ("startsAt" and "total")

Adjusted valid update interval by changing hours until last timestamp from 5 to 8 and spread_load_constant from 5000 to 3600 (to reduce refresh window)
This should move update interval from 16:20-18:00 to 13:30-14:30 to make sure tomorrows prices are downloaded a bit earlier in the day

Proposed change

add extra attributes for priceInfo and update them when current price is updated.
The price info is already included in downloaded data

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)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Additional information

  • This PR fixes or closes issue: fixes #
  • This PR is related to issue:
  • Link to documentation pull request:

Checklist

  • 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
  • The code has been formatted using Black (black --fast homeassistant tests)
  • Tests have been added to verify that the new code works.

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.
  • Untested files have been added to .coveragerc.

The integration reached or maintains the following Integration Quality Scale:

  • No score or internal
  • 🥈 Silver
  • 🥇 Gold
  • 🏆 Platinum

To help with the load of incoming pull requests:

Added already downloaded priceInfo for today with timestamp and price level as list in attribute raw_today
Added already downloaded priceInfo for tomorrow with timestamp and price level as list in attribute raw_tomorrow
Added only prices as list for today and tomorrow as new attribute
Added tomorrow_valid as attribute if array of tomorrows prices are valid
This is the same format as the Nordpool integration, only with Tibber's api keys ("startsAt" and "total")

Adjusted valid update interval by changing hours until last timestamp from 5 to 8 and spread_load_constant from 5000 to 3600 (to reduce refresh window)
This should move update interval from 16:20-18:00 to 13:30-14:30 to make sure tomorrows prices are downloaded a bit earlier in the day
@probot-home-assistant
Copy link

Hey there @Danielhiversen, mind taking a look at this pull request as it has been labeled with an integration (tibber) you are listed as a code owner for? Thanks!
(message by CodeOwnersMention)

@Knodd Knodd changed the title Make priceInfo available as attributes Tibber: Make priceInfo available as attributes of current price Apr 5, 2022
Knodd added 2 commits April 5, 2022 20:42
Changed returing [] to None for empty attributes to make it consistent with initial state for sensor
fix check errors
@Danielhiversen
Copy link
Member

I do not think these are allowed as attributes.
See this discussion regarding support for future values home-assistant/architecture#667

@Knodd
Copy link
Contributor Author

Knodd commented Apr 5, 2022

I do not think these are allowed as attributes. See this discussion regarding support for future values home-assistant/architecture#667

Has this been implemented? If not, would it not make sense to add data as attributes now and move it to forecast later when possible?

I made the format exactly like the Nordpool integration (except for the API-keys) to make it clear what data is returned) so it would be an easy swap out for Tibber customers since Nordpool API is deprecated

@Danielhiversen
Copy link
Member

Has this been implemented? If not, would it not make sense to add data as attributes now and move it to forecast later when possible?

No, but independent of that I do not think these are allowed as attributes.

@Knodd
Copy link
Contributor Author

Knodd commented Apr 5, 2022

Since it's the same data being used for current price sensor and it already has attributes for min/max/avg, price_level etc I thought it would be ok.

How should we add them then? Can we reuse the data for a separate sensor entity called price_forecast or something? The way I read the link above that's not the optimal way either

Knodd added 2 commits April 7, 2022 00:12
Always return null/None for empty price data
Check that todays prices is valid array before iterating
@MartinHjelmare MartinHjelmare changed the title Tibber: Make priceInfo available as attributes of current price Make Tibber priceInfo available as attributes of current price Apr 7, 2022
@Knodd
Copy link
Contributor Author

Knodd commented Apr 8, 2022

Who makes the decision if future prices are allowed as attributes of the current price sensor or not?

@MartinHjelmare
Copy link
Member

We should wait for the architecture discussion to be resolved before we expose this information.

Returning None for empty data makes it necessary to check for datatype i Apexcharts etc. Returning empty list keeps graph from crashing if data is not valid list and returns no data points as expected
@Knodd
Copy link
Contributor Author

Knodd commented Apr 12, 2022

OK, guess we'll just have to be patient then. Any estimate on the timeline for this discussion?

There has been no comments for 4 months on the discussion and it focuses mostly on the problem with existing integrations spreading forecast values over separate entities making automations based on forecast cumbersome. This is not the case for listed data in attributes where we easily can use {% if states('sensor.electricity_price') > average(state_attr('sensor.electricity_price', 'today')) %} to check if the current price is above todays average price etc

Weather forecast integrations generally (met.no as an example) also exposes forecast data as lists in attributes so I don't see whats worse with forecasting electricity prices as attributes.

I understand the need to keep it organized and in common form, but my opinion is that it would be a better solution to expose the data as attributes now (seems to be the general way integrations solve forecasting data today) and move it to a forcasted values model for sensor data when (and if) such a function is added at some point later, along with all other integrations providing forecasted data

@github-actions
Copy link

There hasn't been any activity on this pull request recently. This pull request has been automatically marked as stale because of that and will be closed if no further activity occurs within 7 days.
Thank you for your contributions.

@github-actions github-actions bot added stale and removed stale labels Jul 11, 2022
@stafbulp
Copy link

I hope to keep this PR alive. Adding the pricing info would make this integration much more useful for automation purposes.

@MartinHjelmare
Copy link
Member

Let's close here until the architecture discussion is resolved.

@github-actions github-actions bot locked and limited conversation to collaborators Jul 21, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants