Error in automation while calculating a number

Hi there,

i am trying to create a blueprint which would calculate the forecast for solar production.

blueprint:
  name: Solar Ausblick Blueprint
  author: "EdgarM73"
  description: "Berechnet die Solarerträge für heute, morgen und übermorgen und bewertet diese."
  homeassistant:
    min_version: "2024.6.0"
  domain: automation
  input:
    solar_bewertung:
      name: Solar Bewertung
      description: >
        `Solar Bewertung`

        Hier wird die Bewertung des heutigen Tages abgespeichert. 

        Erstelle einen passenden Helper [here](https://my.home-assistant.io/redirect/helpers/).
      default:
      selector:
        entity:
          filter:
            - domain:
                - input_number
    solar_ertrag_heute:
      name: Solarertrag heute
      description: "Solarertrag heute"
      default:
      selector:
        entity:
          filter:
            - domain:
                - sensor
              integration: open_meteo_solar_forecast
          multiple: false
    Eingabemin:
      name: Eingabemin
      description: "Minimaler Solarertrag"
      default: 0
      selector:
        number:
          min: 0
          max: 0
          mode: box
          unit_of_measurement: "kWh"
    Eingabemax:
      name: Eingabemax
      description: "Maximaler Solarertrag"
      default: 4
      selector:
        number:
          min: 0
          max: 10
          step: 1
          unit_of_measurement: "kWh"
    Zielmin:
      name: Zielmin
      description: "Minimaler Zielwert. dieser Wert definiert das Minimum für die Bewertung des Ertrages"
      default: -10
      selector:
        number:
          min: -10
          max: 10
          step: 0.5
    Zielmax:
      name: Zielmax
      description: "Minimaler Zielwert. dieser Wert definiert das Maximum für die Bewertung des Ertrages"
      default: 10
      selector:
        number:
          min: -10
          max: 10
          step: 0.5
alias: Solar Ausblick Blueprint
description: ""
triggers:
  - trigger: time
    at: "06:00:00"
  - trigger: time
    at: "07:00:00"
  - trigger: time
    at: "08:00:00"
conditions: []
actions:
  - variables:
      v_solar_ertrag_heute: !input solar_ertrag_heute
      #    v_solar_ertrag_morgen: !input solar_ertrag_morgen
      #    v_solar_ertrag_ubermorgen: !input solar_ertrag_ubermorgen
      v_Eingabemin: !input Eingabemin
      v_Eingabemax: !input Eingabemax
      v_Zielmin: !input Zielmin
      v_Zielmax: !input Zielmax

  - action: input_number.set_value
    data:
      value: >-
        {{ ((v_solar_ertrag_heute - v_Eingabemin) * (v_Zielmax-v_Zielmin) /
        (v_Eingabemax-v_Eingabemin)+v_Zielmin ) | round(1) }}
    target:
      entity_id: !input solar_bewertung

mode: single

I can create an automation but executing it gives following error:
Ausgeführt: 19. März 2025 um 11:13:30

Fehler: Error rendering data template: TypeError: unsupported operand type(s) for -: 'NodeStrClass' and 'int'

could someone help me understand the error?

regards
E

Most likely one or more is string.
You can try and use | int or | float.

Ex: {{ ((v_solar_ertrag_heute | float - ...

hi Hellis,

thanks, but unfortunatly it just gives an eror:

Error rendering data template: ValueError: Template error: float got invalid input 'sensor.energy_production_today_4' when rendering template '{{ ((v_solar_ertrag_heute | float - v_Eingabemin) * (v_Zielmax-v_Zielmin) / (v_Eingabemax-v_Eingabemin)+v_Zielmin ) | round(1) }}' but no default was specified 

the sensor is a number, but still it cant be used.

regards
E

You get that error when it’s not a number…

yes, i understand.

But is there a way to convert an sensor ( numeric value ) into a number?
cant find anything except creating a template.
but than everybody who might use my blueprint hass to create several template.

regards
E

If it is a numeric value then | float will do that.
Are you sure you are getting a numeric value?
Remove the action and add a notify or something where you can see the value it has.

that is weird.

The sensor i am using as input has a real numerical value. ( 2,9 kwh)
but when sending the input to my mobile devie I receive Jetzt (now )

why is the value of the sensor not sent?
regards
E

I have never made a blueprint nor have I ever installed one.
Can’t help you

1 Like

The value of the variable v_solar_ertrag_heute is a sensor’s entity_id. In your case, it’s sensor.energy_production_today_4. Use the states() function get the sensor’s value.

{{ ((states(v_solar_ertrag_heute) | float(0) - v_Eingabemin) * (v_Zielmax-v_Zielmin) / (v_Eingabemax-v_Eingabemin)+v_Zielmin ) | round(1) }}

Hi Taras,

thanks you, this was ( maybe) the only place i didnt try to do that :smiley:
regards
E

1 Like