Simple math

I have a called “sensor.totalsolarpositive”. That sensor gives the amount of Watt that my solar panels are producing at that moment.

Now, the maximum that the solar panels can deliver is 2400 Watt.

So, when I do sensor.totalsolarpositive/2400 * 100, I get the percentage. But how can I do this simple math? I suppose with a helper?

Define a template sensor. Here is an example for another purpose you can learn from:

  - sensor:
      - name: Dachboden 10KTL Phase A power
        unique_id: unique_id__dachboden_10ktl_phase_a_active_power
        state_class: "measurement"
        device_class: "power"
        unit_of_measurement: "W"
        icon: "mdi:flash"
        state: >-
          {% set voltage = states('sensor.dachboden_10ktl_phase_a_voltage') | float(0) %}
          {% set current = states('sensor.dachboden_10ktl_phase_a_current') | float(0) %}
          {{ (voltage * current) | round(2) }}
        availability: >-
          {{ has_value('sensor.dachboden_10ktl_phase_a_voltage') and has_value('sensor.dachboden_10ktl_phase_a_current') }}

1 Like

Read this:

You want:

{{ (states('sensor.totalsolarpositive')|float(0) / 2400) * 100 }}

That can be the state template for a template sensor which you can set from the UI, under Helpers.

states(entity_id) returns the state of the entity, which is always a string. You need to turn that into a number before doing maths with it, which is what the |float does. The (0) in the float call is the default value, returned if the state cannot be converted to a number (if it’s unknown, for example).

(edit: read the question properly)

{{ ((states('sensor.totalsolarpositive')|float(0) / 2400) * 100) | round(0) }}

Works as a charm!

1 Like

Well another simple math question that I can’t find out…

I want to have a sensor that shows me the power usage of my hown every day.

I believe I need the Energy Import from my P1 meter (sensor.stroommeter_totaal_verbruik) minus the Energy Export from my P1 meter (sensor.stroommeter_totaal_teruglevering).

Using the Utility Meter (Utility Meter - Home Assistant) I can reset that amount every 24h and with that information I can create a graph that shows me the usage every day.

Is this a correct tought?