Watt sensor in which when the energy exported to my home grid is greater than 0

Good afternoon. I would like someone to help me create a watt sensor in which when the energy exported to my home grid is greater than 0, this sensor does not tell me the watts. the aim is to create a kWh sensor from a plug, with the actual energy spent.

Could you maybe rephrase the question differently to make it easier to understand what it is that you are trying to achieve as the title of your post is a bit ambiguous.

Watt is a unit of Power not Energy for which the units are kWh (or the Power integrated over time). An analogy for Power is the instantaneous fuel flow in a car e.g. in Gallons per Minute, and for Energy the analogy would be the fuel volume used in Gallons.

There are DIY solutions for measuring Energy and also off-the-shelf devices like the Shelly EM.

These can be used to measure Energy imported from the grid to the home or exported to the grid from the home e.g. in the case of solar.

I hope that that helps you to reframe the question.

I’m sorry but I have some difficulty with English. I have two de Watt sensors: sensor_A and sensor_B. I want to create a new sensor: sensor_C. I want sensor_C to show the same Watts as sensor_A, but when sensor_B has a Watt value greater than 0, sensor_C goes to zero.

sensor_A is the watts of my computer, sensor_B is the watts exported from the solar panels to the grid. when sensor_B is greater than zero, it means that I am exporting energy, so my pc is not spending money. senor_c will be the watts of the pc only when you are spending money

Im still confused but if you want to convert sensor supplying power (watts) to energy (kwh)

sensor:
  - platform: integration
    source: sensor.mains_power
    name: energy_spent
    unit_prefix: k
    round: 2

I know that. first I want to create a power sensor (sensor_C) that is a clone of sensor_A, but that doesn’t count watts when sensor_b (exported energy) is greater than zero

How about something like this …

- platform: template
  sensors:
    sensor_c:
      friendly_name: Sensor C
      value_template: >-
        {% if states('sensor.sensor_b') | float > 0.0 %} 
          0.0
        {% else %} 
          {{ states('sensor.sensor_a') }}
        {% endif %}

Error in “value_template” :s

There may well be some errors as I did not test this, presumably you can play around with the template in Developer Tools to get it working as you require.