dbuezas / lovelace-plotly-graph-card

Highly customisable Lovelace card to plot interactive graphs. Brings scrolling, zooming, and much more!
341 stars 15 forks source link

"resample" does not allign traces iwth different initial starting points #360

Open Steph-74 opened 5 months ago

Steph-74 commented 5 months ago

Describe the bug The "resample" function only resamples the data after the first datapoint of the respective trace was provided by the data base - it does not create entries in the array from the beginning of the reporting periode. If different traces are to be combined, the arrays' length do not match

Screenshots image

yaml

type: custom:plotly-graph
  - entity: sensor.total_battery_energy_charged
    internal: true
    statistic: sum
    period: 5minute
    filters:
      - delta
      - fn: |
          ({ys}) => {
            let acc = 0;
            return { ys: ys.map(y => acc += y) }
          }
      - store_var: to_battery
  - entity: sensor.total_battery_energy_discharged
    internal: true
    statistic: sum
    period: 5minute
    filters:
      - delta
      - fn: |
          ({ys}) => {
            let acc = 0;
            return { ys: ys.map(y => acc += y) }
          }
      - store_var: from_battery
  - entity: sensor.smart_meter_ts_65a_3_energy_real_produced
    internal: true
    statistic: sum
    period: 5minute
    filters:
      - delta
      - fn: |
          ({ys}) => {
            let acc = 0;
            return { ys: ys.map(y => acc += y) }
          }
      - store_var: to_grid
  - entity: sensor.smart_meter_ts_65a_3_energy_real_consumed
    internal: true
    statistic: sum
    period: 5minute
    filters:
      - delta
      - fn: |
          ({ys}) => {
            let acc = 0;
            return { ys: ys.map(y => acc += y) }
          }
      - store_var: from_grid
  - entity: sensor.wattpilot_totally_charged
    internal: true
    statistic: sum
    period: 5minute
    filters:
      - delta
      - fn: |
          ({ys}) => {
            let acc = 0;
            return { ys: ys.map(y => acc += y) }
          }
      - store_var: to_car
  - entity: sensor.total_photovoltaics_energy
    internal: true
    name: heute
    statistic: sum
    period: 5minute
    filters:
      - delta
      - fn: |
          ({ys}) => {
            let acc = 0;
            return { ys: ys.map(y => acc += y) }
          }
      - store_var: pv_prod
  - entity: ''
    name: heute
    statistic: sum
    period: 5minute
    filters: 
      - load_var: pv_prod
      - map_y: >-
          parseFloat(vars.pv_prod.ys[i]) - parseFloat(vars.to_grid.ys[i]) -
          parseFloat(vars.to_battery.ys[i]) +
          parseFloat(vars.from_battery.ys[i]) + parseFloat(vars.from_grid.ys[i])
      - multiply: 0.001
    line: 
      color: rgba(255, 0, 0, 1)
      width: 2
      shape: spline
    show_value: true

Additional context See also this discussion

dbuezas commented 5 months ago

This will be a bit tricky to fix, I'll need to add a way to keep track of the requested ranges (analogous to visible_range).