How to calculate by month and year, the autonomy of my house on solar?

Hey, maybe I have a little input for you. Hopefully this will help you in some way.
However only on the second part of the question.

In order to count the power consumption there is probably many ways. The way I am doing it is as follows ( example config at the end).

Sensor P1,P2,P3 - shows the current power in W for each of the 3 phases.
Sensor S - Shows the state on/off depending on the heating (if it is on/off)

First I create a template that is P1+P2+P3 only is S is on.

Based off that I have an integration sensor that counts the energy in kWh.

And then as utility meters I have sensors that reset daily/monthly/yearly and count the energy for that interval.

See below my configs. Note however that currently I have some problems with these ( see my topic on that Integration Templates and Utility Templates suddenly "Unavailable" )

This is the power template


- platform: template
    sensors:
      shelly_power_water:
        friendly_name: "Shelly Power Consumption Water"
        unit_of_measurement: 'W'
        value_template: >-
          {% if ( ( (states('sensor.shelly3em_channel_a_power')|float - states('sensor.shelly3em_channel_b_power')|float + states('sensor.shelly3em_channel_c_power')|float) > 0 ) and ( is_state('sensor.wkh_status_water', 'on') ) ) %}
            {{ states('sensor.shelly3em_channel_a_power')|float - states('sensor.shelly3em_channel_b_power')|float + states('sensor.shelly3em_channel_c_power')|float }}
          {% else %}
            {{ 0 }}
          {% endif %}
        availability_template: "{{ 
            [ states('sensor.shelly3em_channel_a_power'),
              states('sensor.shelly3em_channel_b_power'),
              states('sensor.shelly3em_channel_c_power')
            ] | map('is_number') | min 
          }}"

This is the integration (energy counter)


sensor:
  - platform: integration
    source: sensor.shelly_power_water
    name: shelly_energy_water
    round: 2
    unit_prefix: k
    method: left

And these the utility-meters


utility_meter:
  shelly_energy_water_daily:
    source: sensor.shelly_energy_water
    cycle: daily
    
  shelly_energy_water_monthly:
    source: sensor.shelly_energy_water
    cycle: monthly

  shelly_energy_water_yearly:
    source: sensor.shelly_energy_water
    cycle: yearly