Coder Social home page Coder Social logo

t3m3z / spotprices2ha Goto Github PK

View Code? Open in Web Editor NEW
100.0 100.0 11.0 394 KB

Simple copy-paste approach to fetch data from api.spot-hinta.fi (see https://spot-hinta.fi) to Home Assistant. Includes simple sensors and UI elements to ease automation work.

License: MIT License

spotprices2ha's People

Contributors

leissson avatar rc-aol avatar t3m3z avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

spotprices2ha's Issues

"sensor.shf_electricity_price_now" not working after HA update to 2023.5.0

After HA update to version 2023.5.0 "sensor.shf_electricity_price_now" is unknown.
I replaced line state: '{{ state_attr("sensor.shf_electricity_price_now", "today_prices")[now().hour] }}'
with line state: '{{ state_attr("sensor.shf_electricity_price", "data")[now().hour]["PriceWithTax"]}}'

Now it works.
Is that fix OK?

shf_electricity_price_now sensor getting price from one hour ahead

Hi,

After the recent HA update and fixes to the yaml, I noticed that the shf_electricity_price_now sensor is getting it's value from one hour ahead.

state_attr("sensor.shf_electricity_price_now", "today_prices")[now().hour] gives the price for next hour instead of the current one. Modifying this with state_attr("sensor.shf_electricity_price_now", "today_prices")[now().hour-1] fixes the issue, but of course isn't the best practice.

I have checked that HA is set at the correct time and now().hour returns the number of current hour.

Visualization card size

Is there a way to change the size of the visualization card? Would be nice to have the possibility to make it a bit wider for example, but i don't see anything in the code that an amateur like me could change... Or is it dependent on how much else you have on the overview screen?

The prices are incorrect

The current electricity price is 5.32 c/kWh but the integration reports 6.86 c/kWh which seems to be the next hours price. Does the integration take in account the winter and summer time correctly?

Average price Selected period

Hi,

Would it be possible to implement, in addition to the already existing "Average price" functionality, an "Average price Selected period" calculation, where you could define the starting time and the ending time or the length of the period yourself.

It would make it much easier to play with solar electricity and water heater controls, when you could compare the next day's average selling price (from the solar production period) with the current day's night electricity price and make decisions based on that.

Template value errors in sensor.shf_control_factor_1, sensor.shf_electricity_price_now

Just updated to 0.1.10.
After restart, found the below in logs:

Logger: homeassistant.helpers.template_entity
Source: helpers/template_entity.py:364
First occurred: 10:30:09 (17 occurrences)
Last logged: 10:30:09

TemplateError('ValueError: Template error: float got invalid input 'unknown' when rendering template '{{ (states("sensor.shf_control_factor_1") | float /2 + 0.5) | default("Unknown") }}' but no default was specified') while processing template 'Template("{{ (states("sensor.shf_control_factor_1") | float /2 + 0.5) | default("Unknown") }}")' for attribute '_attr_native_value' in entity 'sensor.shf_control_factor_0_1'
TemplateError('TypeError: 'NoneType' object is not iterable') while processing template 'Template("{% set output = namespace(value=[]) %} {% for value in state_attr("sensor.shf_control_factor_1", "today_values") %} {% set output.value = output.value + [ value | float /2 + 0.5 ] %} {% endfor %} {{ output.value }}")' for attribute 'today_values' in entity 'sensor.shf_control_factor_0_1'
TemplateError('TypeError: 'NoneType' object is not iterable') while processing template 'Template("{% set output = namespace(value=[]) %} {% for pnow in state_attr("sensor.shf_electricity_price_now", "today_prices") %} {% set pmin = state_attr("sensor.shf_electricity_price_now", "today_min") | float %} {% set pmax = state_attr("sensor.shf_electricity_price_now", "today_max") | float %} {% set value = max(min((2*(pmax - pnow) / (pmax - pmin)-1) * states('input_number.shf_control_function_factor') | float,1),-1) %} {% if states("input_select.shf_control_function" ) == "Linear" %} {% set output.value = output.value + [value | round(2)] %} {% else %} {% set output.value = output.value + [sin(value*pi/2) | round(2)] %} {% endif %} {% endfor %} {{ output.value }}")' for attribute 'today_values' in entity 'sensor.shf_control_factor_1'
TemplateError('ValueError: Template error: int got invalid input 'unavailable' when rendering template '{% set value = state_attr("sensor.shf_electricity_price_now", "data")[states("sensor.shf_idx")|int+now().hour] %} {{ value["Rank"] <= states("input_number.shf_rank_slider") | int }}' but no default was specified') while processing template 'Template("{% set value = state_attr("sensor.shf_electricity_price_now", "data")[states("sensor.shf_idx")|int+now().hour] %} {{ value["Rank"] <= states("input_number.shf_rank_slider") | int }}")' for attribute '_state' in entity 'binary_sensor.shf_rank_acceptable'
TemplateError('UndefinedError: None has no element 10') while processing template 'Template("{% set value = state_attr("sensor.shf_electricity_price_now", "today_prices")[ now().hour ] %} {{ value <= states("input_number.shf_price_slider") | float }}")' for attribute '_state' in entity 'binary_sensor.shf_price_acceptable'

Yield overhead costs (selling electricity)

Is there a way to have different overhead costs for buying and selling electricity? It seems to me that the overhead costs are added directly to the data and therefore there is now way to get the original stock-price if you have added the overhead electricity costs.

Would it be possible to have a sensor for original stock price, new input field for Yield overhead costs and then get the value + overhead costs as a total for Yield price now?

This would help in order to get the energy-dashboard working correctly and to make automations whether to sell your yielded electricity or to try to use it yourself.

One typo found in spot-price.yaml

`

  • sensor:
    • name: SHF Electricity price now
      unique_id: shf_electricity_price_now
      unit_of_measurement: "€/kWh"
      device_class: monetary
      state: '{{ state_attr("sensor.shf_electricity_price", "data")[states("sensor.idx")|int+now().hour]["PriceWithTax"] }}'
      `
      There should be "sensor.shf_idx" instead of "sensor.idx"

Feature request : one more price sensor (price for electricity returned to grid)

Nowadays, quite a lot of people sell solar panels overhead back to the grid. At least here in Finland, the price is VAT 0, and it is deducted with a negative marginal (for example, in my case, -0.3 c/kWh).

Would it be possible to add more configuration values for the SHF so that there could be an option to configure additional sensors for the returned electricity?

That would need to show price with or without VAT (no matter what is configured to the current buying price option), and different (negative) margin price.

With that it would be possible to count the returned electricity price with the SHF script.

"SHF Cheapest period start" entity updated at exactly at start time - automations did not trigger

Hello and thank you for the great work!

I have been using "SHF Cheapest period start" to trigger my house heatings to turn on when cheap hours are starting. So far this has been working fine, but today cheap hours were starting at 00:00 and "SHF Cheapest perior start helper" was updated at excatly the same time. This caused my automations not to trigger. Is there a way to force update of "SHF Cheapest period start" earlier to prevent this or something else that should be changed?

kuva

Ranking the hourly prices is not taking Price1 and Price2 into account

Looks like that the rank value is not working properly together with day/night time tariffs on the days, when the spot prices are very low (well, probably it does not work with the higher prices either, but the bug becomes obvious with low spot prices).

I've set up the day/night time tariffs with Price1 and Price2 like this:
image

This is October 7, 2023, spot prices have been record-breaking low the whole day (shown prices include my day/night time tariffs):
image

When writing this, the time is between 22-23, so the rank should be below all the daytime hours between 7-22, however I get this rank:
image
So, looks like that the ranking is not taking the different day/night time tariffs into account at all, but only the spot prices.

Error loading configuration

New user here so if I miss something, I apologies.

Trying to install this. Checking the configuration via dev tool hits a message about invalid configuration

Error loading /config/configuration.yaml: mapping values are not allowed here
in "/config/spot-price.yaml", line 28, column 66

I'm using the following:
Home Assistant 2023.1.1
Supervisor 2022.12.1
Operating System 9.4
Frontend 20230104.0 - latest

Afternoon rank

The default features are great and I can do most what I want by using/copying price_or_rank binary sensor. However I would like to have a separate rank calculation for a specific time period, that might be useful for others as well.

Use case: I use price_or_rank to heat up the bathroom floor when price is lowest. The floor stays quite warm for few hours, but quite typically the heated hours are in the morning or late evening. For morning showers this is fine, but I would like to have a separate afternoon rank to find the cheapest hours from 2pm to 22pm for example. But would not like to keep the floor heated during the expensive hours of the day.

Breaks a lot on background

I have HA 2023.9.2
After including package automations stops working, cloud base integrations won't load correctly etc. Sonof for example.
Check the system log after restart.. there is a lot.
Spot itself works though.

Negative energy prices + vat

It appears that negative energy prices are not calculated correctly. From a quick look negative VAT is calculated so -0,20 becomes -0,25.

rank-automation.yaml Blueprint fails with "TemplateSyntaxError: unexpected char '\\' at 1930"

Imported the blueprint and based a couple of test automations on it. None will trigger.
If triggered manually, they always go to "else" (i.e. turn off the device), and never choose the "on" option.

When I pasted the blueprint code to the Template checker in HA, I get the error mentioned in the title.

A bit of googling suggests that the \ characters are not escaped correctly in the trigger: section; more specifically at

"- platform: template
value_template: "{% if on_attribute == \ "

(the first backslash there is the character number 1930)

Any ideas?

rank-automation.yaml doesn't work

I'm curious whether I'm doing something wrong, but the rank-automation.yaml doesn't work for me at all.

The automation I've created form that blueprint doesn't ever get triggered automatically and when triggered manually always results in else clause being executed.

Having spent a full day on it, I found the root cause: those input_variables are not accessible inside the value_template of the trigger despite the fact they're defined as trigger_variables (which in theory should work fine). I've tried pretty much all the approaches suggested at https://community.home-assistant.io and I just couldn't find a way to make those variables available.

The only solution I've found was moving all the if-else logic into the action section, subsequently changing the trigger to just rank & price state changes and and also changing trigger_variables to variables. That way all the variables are nicely available and automation works as expected:

variables:
  rank: !input rank
  price: !input price
  on_attribute: !input on_attribute

trigger:
  - platform: state
    entity_id:
      - sensor.shf_rank_now
  - platform: state
    entity_id:
      - sensor.shf_electricity_price_now

action:
  - if:
    - condition: template
      value_template: |-
        {% if on_attribute == "Price OK" %}
          {{ states('sensor.shf_electricity_price_now') | float <= price | float }}
        {% elif on_attribute == "Rank OK" %}
          {{ states('sensor.shf_rank_now')|float <= rank | float }}
        {% elif on_attribute == "Price or Rank OK" %}
          {{ states('sensor.shf_electricity_price_now') | float <= price | float or states('sensor.shf_rank_now')|float <= rank | float }}
        {% elif on_attribute == "Price and Rank OK" %}
          {{ states('sensor.shf_electricity_price_now') | float <= price and states('sensor.shf_rank_now')|float <= rank | float }}
        {% endif %}
    then: !input action_on
    else: !input action_off

Electricity price in cents instead of euros

The one big problem I have with SHF using euros instead of cents is that:
a) 15 Cents per kwh is easier to communicate than 0.15 euros per kwh
b) HA automation fields don't support decimals. Let's say I want to check if the price is below 15 cents to charge my car. Have to make it a custom sensor or use templates. Rather just use the visual automation maker
image

Maybe an option on which unit to use? Or just use cents always?

SHF Control Factor +-1 throws DivisionByZero error

Following code throws a DivisionByZero error when pmin == pmax
https://github.com/T3m3z/spotprices2ha/blob/main/spot-price.yaml#L120

  - sensor:
    - name: SHF Control Factor +-1
     ...
        today_values: >
            {% set output = namespace(value=[]) %}
            {% for pnow in state_attr("sensor.shf_electricity_price_now", "today_prices") %}
              {% set pmin = state_attr("sensor.shf_electricity_price_now", "today_min") | float %}
              {% set pmax = state_attr("sensor.shf_electricity_price_now", "today_max") | 
              {% set value = max(min((2*(pmax - pnow) / (pmax - pmin)-1) * states('input_number.shf_control_function_factor') | float,1),-1) %}
     ...

I believe that it would never be the case in real world, however, for the sake of getting rid of the error message I suggest following fix:

              {% set pmin = state_attr("sensor.shf_electricity_price_now", "today_min") | float %}
              {% set pmax = state_attr("sensor.shf_electricity_price_now", "today_max") | float %}
              {% if pmax == pmin %}
                {% set value = 1 %}
              {% else %}
                {% set value = max(min((2*(pmax - pnow) / (pmax - pmin)-1) * states('input_number.shf_control_function_factor') | float,1),-1) %}
              {% endif %}

Night time price (SHF Price2) not working even though times are set

Hi, and firstly, thank you a great sensor package!

I'm quite new to HA but I've gotten used to the basics and with these sensors I've gotten great tools for different automations. However, it seems like the calculation for night time electricity transfer fees isn't working.

I have set up the variables:
image

But it always just uses the Price1 value, even if time is between 22:00 and 07:00:
image
image
image

I've tried with version 0.11.1 and just updated to 0.2.0 but it still has the same issue.

HA + Apexchart + Tariff prices

Hi,

Thanks for a great and simple solution for the SPOT price analysis. I was wondering if it was possible to implement the tariff prices (nigh/day) to the ApexChart configuration so that the tariff prices would be added on top of the SPOT price for every hour? I just can't figure out how to do it. Another solution would be to implement the tariff to the configuration of the main sensor shf_electricity_price somehow.

Our tariffs are 6.8c/kWh during 7-22 and 5.24c/kWh during 22-07.

I already included these to the sensor config of the current price

  • sensor:
    • name: SHF Electricity price now
      unique_id: shf_electricity_price_now
      unit_of_measurement: "€/kWh"
      device_class: monetary
      state: >
      {%- set siirto_paiva = 0.068 -%}
      {%- set siirto_yo = 0.0524 -%}
      {%- set alv = 1.10 -%}
      {%- set marginaali = 0.002016 -%}
      {{ (state_attr("sensor.shf_electricity_price", "data")[states("sensor.shf_idx")|int+now().hour]["PriceWithTax"] + marginaali * alv + siirto_paiva)|round(3) if 6 < (now().hour) < 22 else (state_attr("sensor.shf_electricity_price", "data")[states("sensor.shf_idx")|int+now().hour]["PriceWithTax"] + marginaali * alv + siirto_yo)|round(3) }}

beginner question

Pardon the stupid question, but after uploading the spot-price.yaml file, exactly where in the configuration.yaml is one supposed to paste in this?

"homeassistant: # Find this row and if it doesn't exists, you can copypaste this whole block to the file.
packages: # NEW AND IMPORTANT ROW, NOTE INDENTATION
pack_1: !include spot-price.yaml # NEW AND IMPORTANT ROW, NOTE INDENTATION

There might be code here. Leave it as is."

On a fresh install mine looks like this:

Loads default set of integrations. Do not remove.

default_config:

Load frontend themes from the themes folder

frontend:
themes: !include_dir_merge_named themes

Text to speech

tts:

  • platform: google_translate

automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml

UI screenshots in README not up to date(?)

Hi,
in the main README, it looks like the screenshots following this text:
"Example of UI elements (grouping is not included in the package):"
are maybe not up to date with the features in the current release.

At least SHF Idx is no longer created by the spot-price.yaml - nor are the Cheapest period start & hours helpers.

Cheapest hours between x and y

Hi,

I’ve been using this for roughly 6 months now and everything works like a charm. The last thing that I’m missing is the possibility to find x pieces of cheapest hours between a set range of time. This is mainly for charging my car and heating up the water.

The ideal solution would be having an input field for required amount of hours, range start and range end for the hours so I could for example set it to charge my car between 22-07 during using the x pieces of cheapest hours.

Creating the additional sensors / helpers is not the problem, but to find the code for the lookup. Any idea how to get this done?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.