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

Price issue #317

Merged
merged 2 commits into from
Nov 4, 2024
Merged

Price issue #317

merged 2 commits into from
Nov 4, 2024

Conversation

Danielhiversen
Copy link
Owner

No description provided.

@Danielhiversen Danielhiversen marked this pull request as ready for review November 4, 2024 19:52
@Danielhiversen Danielhiversen merged commit 3ae59e6 into master Nov 4, 2024
6 checks passed
@Danielhiversen Danielhiversen deleted the price branch November 4, 2024 19:52
@CrallH
Copy link

CrallH commented Nov 7, 2024

Hi! This change should maybe be marked as breaking change as it changes from tibbers "PriceLevel" to "PriceRatingLevel" many automate using the Norms/cheap/expensive/very expensive attributes, now we get low/normal/high.
Screenshot_20241107-210807

@ismarslomic
Copy link

Thanks for making me aware of this @CrallH! I agree that this is a breaking change and it broke my existing automations!

@Danielhiversen
Copy link
Owner Author

Ohh, I did not know it was two different price levels

@CrallH
Copy link

CrallH commented Nov 7, 2024

Glad to be able to contribute with something 😊👍

@TylonHH
Copy link

TylonHH commented Nov 8, 2024

So will this change be forever and I have to review all my automation wich are broken now?
Or will the PriceRating a second attribute next to the common price level?

@Danielhiversen
Copy link
Owner Author

I am not really sure what to do :/

I think we should either keep it or change it back. To have both seems unnecessary.

home-assistant/core#130113 (comment)

@4homeassistant
Copy link

4homeassistant commented Nov 8, 2024

Hi @Danielhiversen , I'd suggest to revert back to PriceLevel in order to make existing automations working again. Else thousands of users have to rewrite their automations or scripts relying on these attributes. Especially since there are five PriceLevels but only three PriceRatingLevels.

@TylonHH
Copy link

TylonHH commented Nov 8, 2024

Especially since there are four PriceLevels

Five price levels 😉

But I totally agree. Please revert to the original price levels instead of price rating

@d99pli
Copy link

d99pli commented Nov 9, 2024

Agree, please revert to 5 levels with EXPENSIVE etc. Thanks for a good service by the way!

@niccolodevries
Copy link

Indeed, I would like to also suggest reverting to the 5 levels with EXPENSIVE etc.

@james-1987
Copy link

Please revert back! I really want to have the 5 level control back.

@mnorrsken
Copy link
Contributor

I had to revert home assistant upgrade and I hope it will work. I lost both price level and the current price when upgrading and my house got a bit cold... Please revert if possible! 😬 However I appreciate your efforts!

@TylonHH
Copy link

TylonHH commented Nov 13, 2024

If you dont wanna be dependet on a 3rd party you can use the API by your own. HA supports Rest API.

Try this:

Go to https://developer.tibber.com/explorer and log in. Load your personal token and paste on the left site this:

{
  viewer {
    homes {
      currentSubscription{
        priceInfo{
          today {
            startsAt
            level
            total
          }
          tomorrow {
            startsAt
            level
            total
          }
        }
      }
    }
  }
}

You should see something like

{
  "data": {
    "viewer": {
      "homes": [
        {
          "currentSubscription": {
            "priceInfo": {
              "today": [
                {
                  "startsAt": "2024-11-14T00:00:00.000+01:00",
                  "level": "CHEAP",
                  "total": 0.3035
                },
                {
                  "startsAt": "2024-11-14T01:00:00.000+01:00",
                  "level": "CHEAP",
                  "total": 0.3012
                },
                {
                  "startsAt": "2024-11-14T02:00:00.000+01:00",
                  "level": "CHEAP",
                  "total": 0.2967
                },
                {
                  "startsAt": "2024-11-14T03:00:00.000+01:00",
                  "level": "CHEAP",
                  "total": 0.2922
                },
                {
                  "startsAt": "2024-11-14T04:00:00.000+01:00",
                  "level": "CHEAP",
                  "total": 0.2912
                },

There are much more data to get there. See the API https://developer.tibber.com/docs

Within HA you use REST to get this by yourself.

in sensors yaml paste this

- platform: rest
  name: TibberPreisREST
  unique_id: "d8a8c541-your-own-generated-id-632e18a5a5d3"
  resource: https://api.tibber.com/v1-beta/gql
  method: POST
  payload: '{ "query": "{ viewer { homes { currentSubscription { priceInfo { today { startsAt level total } tomorrow { startsAt level total } current { total } } } } } }" }'
  json_attributes_path: "$.data.viewer.homes[0].currentSubscription.priceInfo"
  json_attributes:
    - today
    - tomorrow
    - current
  value_template: "{{ value_json.current.total | float }}"
  scan_interval: 3600
  headers:
    Authorization: oooooYOURAPIoooooo
    Content-Type: application/json
    User-Agent: REST
  unit_of_measurement: EUR/kWh

validate the YAML restart and chek for sensor.tibberpreisrest

EDIT: some tweaks are needed, but the concept should work

@Danielhiversen
Copy link
Owner Author

It is also an option to make template sensor if you want the old price level sensor.
Then you tweak the sensor as you want.

template:
  - sensor:
      - name: Electricity Price Level
        unique_id: electricity_price_level
        state: >-
          {%- set price = float(states('sensor.electricity_price_infinity_8'), default=-10000) -%}
          {%- set avg_price = float(state_attr('sensor.electricity_price_infinity_8', 'avg_price'), default=0) -%}
          {% if price > -10000 %}
            {{- 'SUPER_CHEAP' if price <= avg_price*0.4 -}}
            {{- 'VERY_CHEAP' if price <= avg_price*0.5 and price > avg_price*0.4 -}}
            {{- 'CHEAP' if price > avg_price*0.5 and price <= avg_price*0.9 -}}
            {{- 'NORMAL' if price > avg_price*0.9 and price < avg_price*1.15 -}}
            {{- 'EXPENSIVE' if price >= avg_price*1.15 and price < avg_price*1.4 -}}
            {{- 'VERY_EXPENSIVE' if price >= avg_price*1.4 }}
          {%else%}
            unknown
          {%endif%}

home-assistant/core#130113 (comment)

@james-1987
Copy link

What a band aid fix. Why not fix your messed up commit?

@Danielhiversen
Copy link
Owner Author

Danielhiversen commented Nov 14, 2024

Any contribution is welcome.
I spend a lot of my spare time maintaining this. I changed the query to get data easier to work with.
I did not know that two different types of price levels exist. So I am sorry that the breaking change was not comunicated.
You also have two different options to still use the old price levels

@SirHackalot2000
Copy link

Appreciate the work and effort. Just want to add yet another vote for reverting the change. There are many automation's that are now not working.

@TylonHH
Copy link

TylonHH commented Nov 14, 2024

I did not know that two different types of price levels exist.

I see in your code some PriceRating instead of level. Is it more then just replace PriceRating with Level?

3ae59e6

seems you replaced priceInfo with priceRating

@ptz0n
Copy link

ptz0n commented Nov 14, 2024

Time to revert? 👍

@Danielhiversen
Copy link
Owner Author

Danielhiversen commented Nov 14, 2024

I see in your code some PriceRating instead of level. Is it more then just replace PriceRating with Level?

It is a different data format

@imist
Copy link

imist commented Nov 14, 2024

I like the granularity in PriceLevel. PriceRatingLevel is too coarse imho. Plus many of us have automations based on PriceLevel already. Why can’t we just revert the change and make everyone happy? 🤓

@Danielhiversen
Copy link
Owner Author

It is not something I will prioritize.
Any contributions are welcome.
Remember that this commit was part of a bug fix in HA, so we can not just revert it.

@mnorrsken
Copy link
Contributor

mnorrsken commented Nov 14, 2024 via email

@Danielhiversen
Copy link
Owner Author

Danielhiversen commented Nov 14, 2024

I guess it is better to use nordpool data directly instead

Then you have 3 different alternatives to get the price levels.

Rest sensor or template sensor

@imist
Copy link

imist commented Nov 14, 2024

Yeah, let's all of us create custom solutions to overcome this sudden breaking change. Really smart!
What happened to backward compatibility??
I am disappointed :-(

@Danielhiversen
Copy link
Owner Author

Danielhiversen commented Nov 14, 2024

As I have said anyone can contribute, and all contributions are welcome.

As I also have said before, I am sorry that the breaking change was not communicated. If you want to contribute to Home Assistant, helping to test the beta versions before release will be very useful.

I will close this thread now.

Repository owner locked and limited conversation to collaborators Nov 14, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.