sdesalve / zcsazzurro

ZCSAzzurro by SDeSalve
Other
35 stars 12 forks source link

Strange graph in the energy tab #6

Closed mrwolfjunior closed 2 years ago

mrwolfjunior commented 2 years ago

Hi,

had some issues around the graph produced in the energy tab: Screenshot 2022-05-27 190104

I think the problem is related to the template because when something is going wrong there is a "default(0)". If I understood correctly HA is doing a delta of the values, so:

The graph will have a production of 1kW (delta 0-1) and then 12kw (delta 2-3), that is wrong. So in order to fix that I guess you should not put the value at all. So something like:

##### current
template:
  - sensor:
      - name: "Potenza Istantanea"
        unit_of_measurement: "W"
        state: >
          {{ state_attr('sensor.zcs_inverter','powerGenerating') if is_number(state_attr('sensor.zcs_inverter','powerGenerating')) | float }}
        state_class: measurement
        device_class: power
        icon: mdi:solar-power

      - name: "Batteria"
        unit_of_measurement: "%"
        state: >
          {{ state_attr('sensor.zcs_inverter','batterySoC') if is_number(state_attr('sensor.zcs_inverter','batterySoC')) | int }}
        state_class: measurement
        device_class: power_factor
        icon: mdi:battery-90

      - name: "Consumo Giorno Casa"
        unit_of_measurement: "kWh"
        state: >
          {{ state_attr('sensor.zcs_inverter','energyConsuming') if is_number(state_attr('sensor.zcs_inverter','energyConsuming')) | float }}
        state_class: measurement
        device_class: energy
        icon: mdi:power-socket-it

      - name: "Autoconsum Giorno"
        unit_of_measurement: "kWh"
        state: >
          {{ state_attr('sensor.zcs_inverter','energyAutoconsuming') if is_number(state_attr('sensor.zcs_inverter','energyAutoconsuming')) | float }}
        state_class: measurement
        device_class: energy
        icon: mdi:power-plug-outline

      - name: "Scarica"
        unit_of_measurement: "kWh"
        state: >
          {{ state_attr('sensor.zcs_inverter','energyDischarging') if is_number(state_attr('sensor.zcs_inverter','energyDischarging')) | float }}
        state_class: measurement
        device_class: energy
        icon: mdi:battery-low

      - name: "Carica"
        unit_of_measurement: "kWh"
        state: >
          {{ state_attr('sensor.zcs_inverter','energyCharging') if is_number(state_attr('sensor.zcs_inverter','energyCharging')) | float }}
        state_class: measurement
        device_class: energy
        icon: mdi:battery-high

      - name: "Produzione"
        unit_of_measurement: "kWh"
        state: >
          {{ state_attr('sensor.zcs_inverter','energyGenerating') if is_number(state_attr('sensor.zcs_inverter','energyGenerating')) | float }}
        state_class: measurement
        device_class: energy
        icon: mdi:solar-power

      - name: "Prelievo"
        unit_of_measurement: "kWh"
        state: >
          {{ state_attr('sensor.zcs_inverter','energyImporting') if is_number(state_attr('sensor.zcs_inverter','energyImporting')) | float }}
        state_class: measurement
        device_class: energy
        icon: mdi:transmission-tower

      - name: "Immissione"
        unit_of_measurement: "kWh"
        state: >
          {{ state_attr('sensor.zcs_inverter','energyExporting') if is_number(state_attr('sensor.zcs_inverter','energyExporting')) | float }}
        state_class: measurement
        device_class: energy
        icon: mdi:solar-power

##### total
      - name: "Produzione Totale"
        unit_of_measurement: "kWh"
        state: >
          {{ state_attr('sensor.zcs_inverter','energyGeneratingTotal') if is_number(state_attr('sensor.zcs_inverter','energyGeneratingTotal')) | float }}
        state_class: total_increasing
        device_class: energy
        icon: mdi:weather-sunny

      - name: "Prelievo Totale"
        unit_of_measurement: "kWh"
        state: >
          {{ state_attr('sensor.zcs_inverter','energyImportingTotal') if is_number(state_attr('sensor.zcs_inverter','energyImportingTotal')) | float }}
        state_class: total_increasing
        device_class: energy
        icon: mdi:transmission-tower

      - name: "Immissione Totale"
        unit_of_measurement: "kWh"
        state: >
          {{ state_attr('sensor.zcs_inverter','energyExportingTotal') if is_number(state_attr('sensor.zcs_inverter','energyExportingTotal')) | float }}
        state_class: total_increasing
        device_class: energy
        icon: mdi:flash-circle

      - name: "Autoconsum Totale"
        unit_of_measurement: "kWh"
        state: >
          {{ state_attr('sensor.zcs_inverter','energyAutoconsumingTotal') if is_number(state_attr('sensor.zcs_inverter','energyAutoconsumingTotal')) | float }}
        state_class: total_increasing
        device_class: energy
        icon: mdi:power-plug-outline

      - name: "Scarica Totale"
        unit_of_measurement: "kWh"
        state: >
          {{ state_attr('sensor.zcs_inverter','energyDischargingTotal') if is_number(state_attr('sensor.zcs_inverter','energyDischargingTotal')) | float }}
        state_class: total_increasing
        device_class: energy
        icon: mdi:battery-low

      - name: "Carica Totale"
        unit_of_measurement: "kWh"
        state: >
          {{ state_attr('sensor.zcs_inverter','energyChargingTotal') if is_number(state_attr('sensor.zcs_inverter','energyChargingTotal')) | float }}
        state_class: total_increasing
        device_class: energy
        icon: mdi:battery-high

If you see I'm only checking if the value is a number, if it is not, the value is skipped

sdesalve commented 2 years ago

try to replace in your zcsazzurro/sensor.py file

except: energyGeneratingTotal = 0 

(and all other variables) with

except: energyGeneratingTotal = None

I remeber that was there other issue with HA if I don't return any value... but try!