New "virtual" sensor with value calculated from another sensor

Hi,

I’ve a SHELLY EM that monitor my energy consumption and expose its value as a sensor.
I need to create another “virtual” sensor that get the value from the SHELLY EM sensor and convert it as a negative number.

How can I do that?
Than I can use this news virtual sensor in my energy panel to create some statistics.

Thank you in advance.

You can use a template sensor for that:

template:
  - sensor:
    - name: "Inverted sensor"
      state: "{{ (states('sensor.YOUR_CURRENT_SENSOR') | float(0)) * -1 }}"

1 Like

Can I change the timestamp of the new sensor to save it as a yesterday consumption?