(Note: this text may need some corrections as I still can not add to consumption to energy - I tried units m3 and m³ - there is no longer an error message for the latter in the log, so I hope it will work out)
Possibly, HA should accept kWh for gas directly and do the “total_increase” itself, but here is how I did it for French gazpar.
Set up a counter which will be the sum of all kWh consumption seen up to current day to provide total_increasing
sensor state value later.
counter:
gas_consumption:
initial: 0
restore: true
Energy
wants a sensor
in m³ for gas. I also created a sensor
for kWh
, but I am afraid that this will mess up the graphs so I am not using it. I use a fixed conversion of 11.16 down to m³ as seen in my latest invoice.
- platform: template
sensors:
gas_consumption_kwh:
friendly_name: "Gaz (kWh)"
unit_of_measurement: "kWh"
value_template: "{{ states('counter.gas_consumption') }}"
gas_consumption_m3:
friendly_name: "Gaz (m³)"
unit_of_measurement: "m³"
value_template: "{{ states('counter.gas_consumption') | float / 11.16 }}"
I customize the values in ‘customize.yaml’ to add “total_increasing”, the “unit_of_measurement” are likely not usefull and they stem from a test using the counter directly which “Energy” did not accept as it apparently requires a counter.
sensor.gas_consumption_kwh:
state_class: total_increasing
unit_of_measurement: kWh
sensor.gas_consumption_m3:
state_class: total_increasing
unit_of_measurement: 'm³'
The integration for Gazpar provides daily consumptions, and we need a total_increasing consumption. The following automation makes the sum every morning at 8, supposing that the new daily value is known à at time (with some margin for several trials trying to get it on a bad network). sensor.compteur_gazpar
is the daily value provided by the integration :
alias: Accumuler consommation Gazpar
description: Ajoute la consommation du jour précédent au compteur global
trigger:
- platform: time
at: '08:00:00'
condition: []
action:
- service: counter.configure
target:
entity_id: counter.gas_consumption
data:
value: >-
{{ states('counter.gas_consumption') | float +
states('sensor.compteur_gazpar') | float }}
mode: single
customize.yaml
is not loaded until you add this configuration.yaml
:
homeassistant:
customize: !include customize.yaml
You probably have to restart HA after these configurations.