ssenart / ha-custom_components

Some custom components for Home Assistant
MIT License
4 stars 1 forks source link

energy integration ? #5

Open Vebryn opened 2 years ago

Vebryn commented 2 years ago

Hello,

Great job using new retrieving method !

Any idea how to integrate data into new Energy functionality ?

I saw that there is missing _stateclass: total and _deviceclass: energy

Think a _lastreset is mandatory in order to understand that energy is reset at midnight.

Any idea where to declare theses infos ? Netatmo integration seems mentioning missing classes, there are too many differences. I didn't manage to find where to put missing lines.

Best regards

ssenart commented 2 years ago

Hi Vebryn,

For gazpar energy integration, i'm using the 2 steps configuration method:

template:
  - sensor:
    - name: gas_volume
      unit_of_measurement: 'm³'
      state: >
        {% set sourceState = state_attr('sensor.gazpar_daily_energy', 'end_index_m3') %}
        {% set targetState = states('sensor.gas_volume') %}
        {% if is_number(sourceState) and sourceState | float(0.0) > targetState | float(0.0) %}
          {{ sourceState }}
        {% else %}
          {{ targetState }}
        {% endif %}  
      icon: mdi:fire
      device_class: gas
      state_class: total_increasing
    - name: gas_energy
      unit_of_measurement: 'kWh'      
      state: >   
        {% set sourceState = states('sensor.gas_volume') %}
        {% set converter_factor = state_attr('sensor.gazpar_daily_energy', 'converter_factor_kwh/m3') | float(11.2) %}
        {% set targetState = states('sensor.gas_energy') %}
        {% if is_number(sourceState) and sourceState | float(0.0) * converter_factor > targetState | float(0.0) %}
          {{ sourceState | float(0.0) * converter_factor }}
        {% else %}
          {{ targetState }}
        {% endif %}  
      icon: mdi:fire
      device_class: energy
      state_class: total_increasing
utility_meter:
  total_gas_volume:
    source: sensor.gas_volume
  daily_gas_volume:
    source: sensor.gas_volume    
    cycle: daily
  weekly_gas_volume:
    source: sensor.gas_volume    
    cycle: weekly 
  monthly_gas_volume:
    source: sensor.gas_volume    
    cycle: monthly
  yearly_gas_volume:
    source: sensor.gas_volume    
    cycle: yearly

  total_gas_energy:
    source: sensor.gas_energy
  daily_gas_energy:
    source: sensor.gas_energy    
    cycle: daily
  weekly_gas_energy:
    source: sensor.gas_energy    
    cycle: weekly 
  monthly_gas_energy:
    source: sensor.gas_energy    
    cycle: monthly
  yearly_gas_energy:
    source: sensor.gas_energy    
    cycle: yearly  

Then, in Home Assistant energy configuration panel, I add the sensor 'sensor.total_gas_energy' in gas consumption section. Adding 'sensor.gas_energy' should be the same.

Step 2 is optional. It only permits to monitor by yourself the consumption by period, without relying on the HA energy module.

I would expect that adding volume sensor being available as well, but it is not for an unknown reason. I did not dig further since I prefer to monitor kWh rather than volume.

Regards, Stephane

ssenart commented 2 years ago

Hi Vebryn,

Actually, what is your netatmo issue ? Do you have error messages ? Which ones ?

The Netatmo integration here is a fork of the native one available in HA. I simply added the ability to stream video (only on Presence model) even if the camera is off. However, it does not seem to always work as expected.

I do not recommend to use this Netatmo integration, prefer using the standard one.

Regards, Stephane

Vebryn commented 2 years ago

Hi Vebryn,

For gazpar energy integration, i'm using the 2 steps configuration method:

  • Step 1 : Create a dedicated meter sensor using template:
template:
  - sensor:
    - name: gas_volume
      unit_of_measurement: 'm³'
      state: >
        {% set sourceState = state_attr('sensor.gazpar_daily_energy', 'end_index_m3') %}
        {% set targetState = states('sensor.gas_volume') %}
        {% if is_number(sourceState) and sourceState | float(0.0) > targetState | float(0.0) %}
          {{ sourceState }}
        {% else %}
          {{ targetState }}
        {% endif %}  
      icon: mdi:fire
      device_class: gas
      state_class: total_increasing
    - name: gas_energy
      unit_of_measurement: 'kWh'      
      state: >   
        {% set sourceState = states('sensor.gas_volume') %}
        {% set converter_factor = state_attr('sensor.gazpar_daily_energy', 'converter_factor_kwh/m3') | float(11.2) %}
        {% set targetState = states('sensor.gas_energy') %}
        {% if is_number(sourceState) and sourceState | float(0.0) * converter_factor > targetState | float(0.0) %}
          {{ sourceState | float(0.0) * converter_factor }}
        {% else %}
          {{ targetState }}
        {% endif %}  
      icon: mdi:fire
      device_class: energy
      state_class: total_increasing
  • Step 2 : Setup utility_meter to get consumptions by period:
utility_meter:
  total_gas_volume:
    source: sensor.gas_volume
  daily_gas_volume:
    source: sensor.gas_volume    
    cycle: daily
  weekly_gas_volume:
    source: sensor.gas_volume    
    cycle: weekly 
  monthly_gas_volume:
    source: sensor.gas_volume    
    cycle: monthly
  yearly_gas_volume:
    source: sensor.gas_volume    
    cycle: yearly

  total_gas_energy:
    source: sensor.gas_energy
  daily_gas_energy:
    source: sensor.gas_energy    
    cycle: daily
  weekly_gas_energy:
    source: sensor.gas_energy    
    cycle: weekly 
  monthly_gas_energy:
    source: sensor.gas_energy    
    cycle: monthly
  yearly_gas_energy:
    source: sensor.gas_energy    
    cycle: yearly  

Then, in Home Assistant energy configuration panel, I add the sensor 'sensor.total_gas_energy' in gas consumption section. Adding 'sensor.gas_energy' should be the same.

Step 2 is optional. It only permits to monitor by yourself the consumption by period, without relying on the HA energy module.

I would expect that adding volume sensor being available as well, but it is not for an unknown reason. I did not dig further since I prefer to monitor kWh rather than volume.

Regards, Stephane

Working, great ! I was looking to add state_class and device_class directly into python code.