hello everyone, I have a sensor that comes from the battery of an inverter called (battery power) in watts, and it gives me negative values when discharging and positive when charging, and I want to separate it into two sensors for charging one and the other for discharging both with positive values, so you can integrate into the energy panel. Can someone help me?, I’m a beginner in home assistant, I’ve searched on the forums but I didn’t really find/understand. thank you
I think you’re looking for something like this.
# MQTT
# Convert the negative number of battery used to a positive
template:
- sensor:
- name: "Solar_Month_BatteryKWh_Used_Positive"
unit_of_measurement: "kWh"
state_class: total_increasing
device_class: energy
state: >
{% if states('sensor.Solar_Month_BatteryKWh_Used') | float(0) <= 0 %}
{% set gridout = (states('sensor.Solar_Month_BatteryKWh_Used') |float |abs) %}
{% else %}
{% set gridout = 0 %}
{% endif %}
{{ gridout }}
thank you very much, I will try today