Coder Social home page Coder Social logo

Comments (5)

T3m3z avatar T3m3z commented on August 23, 2024

Hello!

If you want to add the transmission and other extra fees only to the chart, then maybe this quick hack could work:

type: custom:apexcharts-card
graph_span: 48h
experimental:
  color_threshold: true
show:
  last_updated: true
header:
  title: Electricity price (c/kWh)
  show: true
  show_states: true
  colorize_states: true
span:
  start: day
yaxis:
  - min: 0
    decimals: 2
    apex_config:
      forceNiceScale: true
now:
  show: true
  label: Now
series:
  - entity: sensor.shf_electricity_price
    show:
      in_header: false
      extremas: true
    type: column
    color: lightgray
    float_precision: 2
    data_generator: |
      var extra_fees = [5.46, 5.46, 5.46, 5.46, 5.46, 5.46, 5.46, 7.02, 7.02, 7.02, 7.02, 7.02, 7.02, 7.02, 7.02, 7.02, 7.02, 7.02, 7.02, 7.02, 7.02, 7.02, 5.46, 5.46 ] ;
      return entity.attributes.data.map((d, index) => {
        var tempdate = new Date(d["DateTime"]);
        var hour = tempdate.getHours();
        return [tempdate.getTime(), entity.attributes.data[index]["PriceWithTax"]*100+extra_fees[hour]];
      });
    color_threshold:
      - value: 0
        color: 368f39
      - value: 10
        color: a3b34d
      - value: 20
        color: ffd57e
      - value: 30
        color: f18c56
      - value: 40
        color: de425b
  - entity: sensor.shf_electricity_price
    show:
      in_header: true
      header_color_threshold: true
      in_chart: false
    type: line
    color: lightgray
    float_precision: 2
    stroke_width: 0
    data_generator: |
      var extra_fees = [5.46, 5.46, 5.46, 5.46, 5.46, 5.46, 5.46, 7.02, 7.02, 7.02, 7.02, 7.02, 7.02, 7.02, 7.02, 7.02, 7.02, 7.02, 7.02, 7.02, 7.02, 7.02, 5.46, 5.46 ] ;
      var currentTime = new Date().setMinutes(0, 0, 0);
      let currentPrice = entity.attributes.data.find(d => {
        return new Date(d["DateTime"]).getTime() === currentTime;
      })["PriceWithTax"];
      return entity.attributes.data.map((d, index) => {
        var t = new Date();
        return [new Date(d["DateTime"]).getTime(), currentPrice*100 + extra_fees[t.getHours()]];
      });
    color_threshold:
      - value: 0
        color: 368f39
      - value: 10
        color: a3b34d
      - value: 20
        color: ffd57e
      - value: 30
        color: f18c56
      - value: 40
        color: de425b

Currently implementing transmission fees + other extra fees to the data loader isn't that simple as this package is using Restful sensor included in the HomeAssistant. Modifying the Array of prices isn't right now possible (or at least easy) as Template Sensors always output a String. But I'm going to think about this as I see the value of this. Sometimes day/night transmission fees could change the outcome of some scripts.

from spotprices2ha.

heijjan avatar heijjan commented on August 23, 2024

Great, thank you! This was exaclty what I was looking for.

from spotprices2ha.

T3m3z avatar T3m3z commented on August 23, 2024

Alright, nice to hear! I will close this issue then.

But please note that the code provided affects only the charts and other logic inside this package does not know about your transmission fees. I might add some functionality for this in the future.

from spotprices2ha.

heijjan avatar heijjan commented on August 23, 2024

Yes, this was the target. I have the template sensors controlling automations, which take the margins and transfer prices into account. The only problem I had was the apexchart not showing the total amount of the price, but with this hack it works perfectly.

from spotprices2ha.

T3m3z avatar T3m3z commented on August 23, 2024

I added some functionality around these transmission fees etc. They are not fully tested and therefore they are currently available in a separate branch: https://github.com/T3m3z/spotprices2ha/tree/price_margins

Feel free to test this. Could be useful for automations too and not only for the chart.

image

from spotprices2ha.

Related Issues (20)

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.