Can someone tell me why my template sensor attempt is failing with "unavailable"?

Hello everyone…
I am dealing with a mind bender issue…at least for me…
I have 2 sensors, that report electric usage/production…bar breaker 1 and barn breaker 2…it actually a single 220V dual pole breaker…
On this i have small loads, so at night or on cloudy days, it reports positive values…which i want to ignore…and i only want to report/monitor the negative values…
So i went out and found several options to tackle that, and by them alone it works, but when i try to plunge it all into one single line, it becomes unavailable…

state: "{{ (states(-((0, states('sensor.energymonitor1_circuit_10_power_2') |float(0))|min)) | float() + states(-((0, states('sensor.energymonitor1_circuit_11_power_2') |float(0))|min)) | float()) | round(1)  }}"  

Is the string i want to report a negative value if available or 0 if not…
Those 2 alone show a value, without - when there is a negative value and shows 0 when it is 0 or positive…:

-((0, states('sensor.energymonitor1_circuit_10_power_2') |float(0))|min))
-((0, states('sensor.energymonitor1_circuit_11_power_2') |float(0))|min))

But in the construct up top, not so much…i thought when i do an addition of those 2 in an extra set of () it should just work…but where is my mistake?
Thx for any intel

The function states() accepts only an entity ID as its first argument… states(-(... is, therefor, nonsense.

so you are saying my spaghetti code would not work like that? I am trying to squeeze the wrong components together?

I’m saying that your single line template starts with something that will cause it to fail immediately.

Can you explain what the purposes of the minus signs are?
Is the goal to have the final value reported as a negative or positive value?

I think what you were going for is something like:

state: |
  {% set cir_10 = states('sensor.energymonitor1_circuit_10_power_2') |float(0) %}
  {% set cir_11 = states('sensor.energymonitor1_circuit_11_power_2') |float(0) %}
  {{ [cir_10, 0] | min + [cir_11, 0] | min }}

or…

state: |
  {{['sensor.energymonitor1_circuit_10_power_2','sensor.energymonitor1_circuit_11_power_2']
  | map('states') | map('float', 0) | reject('ge', 0) | sum }}

Result is wanted in positive values, even thought that the vales given are negative…

state: |
  {{ ['sensor.energymonitor1_circuit_10_power_2','sensor.energymonitor1_circuit_11_power_2']
  | map('states') | map('float', 0) | reject('ge', 0) | sum | abs }}

Hello and thx for your help on this one…

I got a working result from a different forum…
That looks like this:

  - sensor:
      - name: "Solar Prod 240v"
        unit_of_measurement: "WH"
        device_class: energy
        state_class: total_increasing        
        state: >
          {% set raw1 = states('sensor.energymonitor1_circuit_11_daily_energy') %}
          {% set raw2 = states('sensor.energymonitor1_circuit_10_daily_energy') %}

          {% set v1 = raw1 | float(0) if raw1 not in ['unavailable', 'unknown', 'none', ''] else 0 %}
          {% set v2 = raw2 | float(0) if raw2 not in ['unavailable', 'unknown', 'none', ''] else 0 %}

          {% if v1 < 0 and v2 < 0 %}
            {{ (v1 | abs + v2 | abs) | round(1) }}
          {% elif v1 < 0 and v2 > 0 %}
            {% set diff = (v1 | abs - v2) %}
            {{ diff if diff > 0 else 0.0 }}
          {% elif v2 < 0 and v1 > 0 %}
            {% set diff = (v2 | abs - v1) %}
            {{ diff if diff > 0 else 0.0 }}
          {% else %}
            0.0
          {% endif %}