BottlecapDave / HomeAssistant-OctopusEnergy

Unofficial Home Assistant integration for interacting with Octopus Energy
https://bottlecapdave.github.io/HomeAssistant-OctopusEnergy/
MIT License
564 stars 56 forks source link

Plotting Rates with Apex Charts #145

Closed fboundy closed 1 year ago

fboundy commented 1 year ago

Not exactly a feature request but an example of how to plot up Agile rates in ApexCharts which may be of interest:

  type: custom:apexcharts-card
  header:
    show: true
    show_states: true
    colorize_states: true
    title: Agile Export Rates
  graph_span: 1d
  stacked: false
  span:
    start: day
  yaxis:
    - min: 0
      max: 35
      decimals: 1
  series:
    - entity: >-
        sensor.octopus_energy_electricity_{{METER_SERIAL_NUMBER}}_{{MPAN_NUMBER}}_current_rate
      type: column
      name: ''
      color: yellow
      opacity: 1
      stroke_width: 0
      unit: W
      show:
        in_header: false
        legend_value: false
      data_generator: |
        return entity.attributes.rates.map((entry) => {
           return [new Date(entry.from), entry.rate];
         });
      offset: '-15min'

image

BottlecapDave commented 1 year ago

Added to my to-do list. We already have a community plugin for displaying agile rates in a table, so will add this in a similar location (or new location)

fboundy commented 1 year ago

Great . I also have a couple of template sensors that will extract Eco7 Day and Night rates and times from the attributes if you think these would be generally useful:

  - sensor:
      - name: "Eco7 Day Rate"
        unique_id: eco7_day_rate
        state: >-
          {{state_attr('sensor.octopus_energy_electricity_19m1337498_1610032016836_current_rate', 'rates') | map(attribute='rate') | list | max}}

      - name: "Eco7 Night Rate"
        unique_id: eco7_night_rate
        state: >-
          {{state_attr('sensor.octopus_energy_electricity_19m1337498_1610032016836_current_rate', 'rates') | map(attribute='rate') | list | min}}

      - name: "Next Eco7 Start"
        unique_id: next_eco7_start
        state: >-
          {% set min_rate = state_attr('sensor.octopus_energy_electricity_19m1337498_1610032016836_current_rate', 'rates') | map(attribute='rate') | list | min %}
          {% set x = state_attr('sensor.octopus_energy_electricity_19m1337498_1610032016836_current_rate', 'rates') | selectattr('rate', 'eq', min_rate) | list %}
          {{x | map(attribute='from') | list | min }}        

      - name: "Next Eco7 End"
        unique_id: next_eco7_end
        state: >-
          {% set min_rate = state_attr('sensor.octopus_energy_electricity_19m1337498_1610032016836_current_rate', 'rates') | map(attribute='rate') | list | min %}
          {% set x = state_attr('sensor.octopus_energy_electricity_19m1337498_1610032016836_current_rate', 'rates') | selectattr('rate', 'eq', min_rate) | list %}
          {{x | map(attribute='to') | list | max }}        
plandregan commented 1 year ago

I have this Apex chart cost vs power Happy to share code

Screen Shot 2023-03-19 at 12 21 44

djdarlo commented 1 year ago

I have this Apex chart cost vs power Happy to share code

Screen Shot 2023-03-19 at 12 21 44

yes please :)

plandregan commented 1 year ago

type: custom:apexcharts-card experimental: color_threshold: true header: show: true floating: true title: Cost vs Power graph_span: 24h show: last_updated: true loading: true apex_config: legend: show: false chart: zoom: type: x enabled: true autoScaleYaxis: false toolbar: show: true autoSelected: zoom xaxis.type: datetime fill: type: gradient gradient: shadeIntensity: 0.1 opacityFrom: 0.3 opacityTo: 1 inverseColors: true series:

andrzej-r commented 1 year ago

@BottlecapDave could I please request enabling statistics for these sensors? This is so the rates can be recorded indefinitely and plotted more cheaply than life data. Currently only one entity shows up in the Developer Tools/Statistics section.

Guidelines from HA: https://www.home-assistant.io/more-info/statistics/ https://developers.home-assistant.io/docs/core/entity/sensor/#long-term-statistics

BottlecapDave commented 1 year ago

@BottlecapDave could I please request enabling statistics for these sensors? This is so the rates can be recorded indefinitely and plotted more cheaply than life data. Currently only one entity shows up in the Developer Tools/Statistics section.

Guidelines from HA: https://www.home-assistant.io/more-info/statistics/ https://developers.home-assistant.io/docs/core/entity/sensor/#long-term-statistics

@andrzej-r I've moved your issue to a separate ticket. Please raise a separate ticket in the future if you're having issues instead of hijacking another unrelated issue. It makes it very hard to track what needs fixing otherwise and your issue will be potentially ignored

BottlecapDave commented 1 year ago

After too long, these examples can now be found in the new community contributions document

BottlecapDave commented 1 year ago

@plandregan a user is having issues with the code you provided due to formatting. Is there any chance you could update us on the formatting of the card?

plandregan commented 1 year ago

Load vs cost chart.txt

BottlecapDave commented 1 year ago

Thanks .Another user put in a code review to fix the issue