Create sensor kw from acumulative data in kwh

Hi,

I’m using an integration to get all data from AC, but it only gets kwh data, I’m interested to analize realtime data ( at least as soon as I can ), I’ve created this script but it doesn’t work, could you help me with that?

      consumo_acumulado:
        value_template: "{{ states('sensor.consum_giatsu') | float }}"
        unit_of_measurement: "kWh"

      instant_power:
        friendly_name: "Potencia Instantánea"
        unit_of_measurement: "kW"
        value_template: >-
          {% set current_consumption = states('sensor.consumo_acumulado') | float %}
          {% set last_consumption = state_attr('sensor.consumo_acumulado', 'last_consumption') | float(default=0) %}
          {% set last_time = state_attr('sensor.consumo_acumulado', 'last_time') | float(default=0) %}
          {% set current_time = now().timestamp() %}
          {% set elapsed_time = current_time - last_time %}
          {% if elapsed_time > 0 %}
            {{ ((current_consumption - last_consumption) / elapsed_time) | round(2) }}
          {% else %}
            0
          {% endif %}       

Take the derivative of energy to get power using this integration:

1 Like