Calculation with sensor values?

I made a mistake with my availability template. The list elements should be quoted. Like this:

[ 'unknown', 'unavailable', none' ]
1 Like

yes, I know but it was working anyways.

here is your code fixed.

#percentage of enrgy produced 
template:
  - sensor:
      - name: "Percentage of energy produced"
        unit_of_measurement: "%"
        state: >
          {% set daily_yield = states('sensor.daily_yield') | float(0) %}
          {% set Estimated_production_today = states('sensor.energy_production_today') | float(1) %}

          {{ ((daily_yield /Estimated_production_today ) * 100) | round(1, default=0) }}  
        availability: >
          {{ states('sensor.daily_yield') not in [ 'unknown', 'unavailable', 'none' ] and
             states('sensor.energy_production_today') not in [ 'unknown', 'unavailable', 'none') ] }}

but I found another method too

   - name: "Percentage of energy produced"
        unit_of_measurement: "%"
        state: >
          {% set daily_yield = states('sensor.daily_yield') | float %}
          {% set Estimated_production_today = states('sensor.energy_production_today') | float %}

          {{ ((daily_yield /Estimated_production_today ) * 100) | round(1) }}  
        availability: >
          {{ states('sensor.daily_yield') | is_number and states('sensor.energy_production_today') | is_number }}

by @TheFes

Hi, I donā€™t want to open a new topicā€¦ I have a problem wit calculationg of sensor value:

what I will to get:
PF Inv = (sensor.power_factor -10000)/10000

That is my config (not working ;-( ):

template:
  - sensor:
    - name: "PF Inv"
      state: >
        {{ (states('sensor.power_factor') - 10000) / 10000 | float(0) }}
      availability: >
        {{ states('sensor.power_factor') | is_number }} 

You are applying the float conversion to the number 10000 instead of the state string. Try this:

      state: >
        {{ (states('sensor.power_factor')|float(0) - 10000) / 10000 }}

You really should have started a new topic rather than posting on a year old one.

THX!!!