I have a sensor named: sensor.forward_energy_kwh, with the following details: raw_state: 1573.73
unit_of_measurement: kWh
device_class: energy
friendly_name: Forward Energy kWh.
This sensor takes reading for a smart meter. This is actually a sensor that tells the total forward energy/electricity consumed in my house. I want to calculate how much electricity I am consuming right now, so I can make a power card out of it. So I was thinking that if we could make an automaton like New Value - Old Value = active Value, We can get how much the current energy consumption is. Can you help me make this sensor/automation. I have been trying to use ChatGPT and other Ai to write me the code, but it is just not working out. I got this from chatgpt.
sensor:
- platform: template
sensors:
current_energy_consumption:
friendly_name: "Current Energy Consumption"
unit_of_measurement: "kWh"
device_class: energy
value_template: >
{% set previous_value = states('sensor.forward_energy_kwh') | float %}
{% set current_value = state_attr('sensor.forward_energy_kwh', 'raw_state') | float %}
{% set active_power = current_value - previous_value %}
{{ active_power | round(2) }}
automation:
- alias: Update Current Energy Consumption
trigger:
platform: state
entity_id: sensor.forward_energy_kwh
action:
service: homeassistant.update_entity
entity_id: sensor.current_energy_consumption
P.S I am using Home Assistant Supervised running on an OrangePi 3 LTS running armbian.
Any advice or help would be apreciated.
Thanks