Ariston Gas Cylinder Estimations

Hi HA enthusiasts, :slight_smile:

I’m new to this and I’m trying to setup a config so I can estimate the remaining of propane in the cylinder and act accordingly with some automation.

I have tried chatGPT but is seems it lack a deep understanding of this platform.

Can you give me some feedback on this config.
What could work what can be improved?

Thank you!

# =========================
# HELPERS
# =========================
input_number:
  capacitate_butelie_kg:
    name: "Capacitate butelie (kg)"
    min: 5
    max: 67
    step: 0.1
    mode: box
    unit_of_measurement: kg
    icon: mdi:gas-cylinder
    initial: 33.5

# =========================
# TEMPLATE SENSORS
# =========================
template:
  - sensor:
      - name: "Total gaz consumat (kWh)"
        unique_id: gas_cylinder_total_kwh
        unit_of_measurement: "kWh"
        device_class: energy
        state_class: measurement
        state: >
          {{ states('sensor.um_ch_gas_cylinder_kwh')|float(0)
           + states('sensor.um_dhw_gas_cylinder_kwh')|float(0) }}

      # --- Butelie: consum + rămas ---
      - name: "Total gaz consumat (kg)"
        unique_id: gas_cylinder_total_kg
        unit_of_measurement: "kg"
        device_class: weight
        state_class: measurement
        state: >
          {{ (states('sensor.um_total_gas_cylinder_kwh')|float(0) / 12.8) | round(2) }}

      - name: "Gaz rămas (kg)"
        unique_id: gas_cylinder_remaining_kg
        unit_of_measurement: "kg"
        device_class: weight
        state_class: measurement
        state: >
          {% set cap = states('input_number.capacitate_butelie_kg')|float(0) %}
          {% set used = states('sensor.total_gaz_consumat_kg')|float(0) %}
          {% set rem = cap - used %}
          {{ ([rem, 0] | max) | round(2) }}

      # --- Medie 7 zile -> kg/zi ---
      - name: "Consum mediu zilnic gaz (kg/zi)"
        unique_id: gas_cylinder_daily_avg_kg
        unit_of_measurement: "kg/zi"
        state_class: measurement
        state: >
          {{ (states('sensor.gaz_medie_7d_kwh_zi')|float(0) / 12.8) | round(2) }}

      - name: "Zile rămase butelie (estimare)"
        unique_id: gas_cylinder_remaining_days
        unit_of_measurement: "zile"
        state_class: measurement
        state: >
          {% set rem = states('sensor.gaz_ramas_kg')|float(0) %}
          {% set avg = states('sensor.consum_mediu_zilnic_gaz_kg_zi')|float(0) %}
          {{ (rem/avg)|round(1) if avg>0 else 'unknown' }}

      # --- Cost pe zi (LEI) ---
      - name: "Cost gaz pe zi (LEI)"
        unique_id: gas_cylinder_daily_cost_lei
        unit_of_measurement: "LEI"
        state_class: measurement
        icon: mdi:cash
        state: >
          {% set kwh = states('sensor.gaz_medie_7d_kwh_zi')|float(0) %}
          {% set price_lei = states('number.ariston_gas_cost')|float(none) %}
          {{ (kwh * price_lei)|round(2) if price_lei is not none else 0 }}

  - binary_sensor:
      - name: "Ariston are erori"
        unique_id: ariston_errors_problem
        device_class: problem
        state: "{{ states('sensor.ariston_errors_count')|int(0) > 0 }}"

# =========================
# MEAN 7 DAYS (kWh/zi)
# =========================
sensor:
  - platform: statistics
    name: "Gaz medie 7d (kWh/zi)"
    entity_id: sensor.um_daily_gas_kwh
    state_characteristic: mean
    max_age:
      days: 7

# =========================
# UTILITY METERS
# =========================
utility_meter:
  um_ch_gas_cylinder_kwh:
    source: sensor.ariston_central_heating_gas_consumption
    cycle: yearly

  um_dhw_gas_cylinder_kwh:
    source: sensor.ariston_domestic_hot_water_gas_consumption
    cycle: yearly
  
  um_total_gas_cylinder_kwh:
    source: sensor.total_gaz_consumat_kWh
    cycle: yearly

  um_daily_gas_kwh:
    source: sensor.total_gaz_consumat_kWh
    cycle: daily