Create and charge and discharge sensors from a single power sensor

So I have code to read the power output from a battery via MQTT

    - name: "Sofar:Battery power"
      unique_id: "sofar_battery_power"
      state_topic: "sofar/battery_power"
      device_class: "power"
      unit_of_measurement: "W"
      state_class: "measurement"
      icon: "mdi:battery-charging"

When the power output is negative it’s charging and when it is positive it’s discharging. It will update every 30secs when the MQTT feed updates, so is there an easy way to create a condition that when the value is negative it adds to a sensor sofar_battery_charging and when it changes to positive it adds the value to a sensor sofar_battery_discharging?

I ended up finding the registry values for charge and discharge so all good :slight_smile:

I have the same issue. Are you willing to share the registry values?

1 Like