Template error: float got invalid input when rendering template

Hello all,

I have following blueprint (minimum example):
The faulty/interesting part starts after the section variables.

blueprint:
  name: Outdoor Irrigation
  description: Automate outdoor irrigation based on soil moisture and sunlight.
  domain: automation
  input:
    target_soil_moisture_beet:
      name: Target Soil Moisture (Beet)
      description: The desired soil moisture level for the beet area.
      selector:
        number:
          min: 0
          max: 100
          step: 5
    percentage_per_min_beet:
      name: Percentage increase of soil moisture per minute for the beet area
      description: Number how much the soil moisture value in percentage increases after one minute of watering
      selector:
        number:
          min: 0
          max: 30
          step: 1
    moisture_sensor_beet:
      name: Moisture Sensor (Beet)
      description: The moisture sensor for the beet area.
      selector:
        entity:
          domain: sensor
    valve_beet:
      name: Valve Beet
      description: The valve for irrigaiton for the beet area
      selector:
        entity:
          domain: switch

variables:
  var_target_soil_moisture_beet: !input target_soil_moisture_beet
  var_moisture_sensor_beet: !input moisture_sensor_beet
  var_percentage_per_min_beet: !input percentage_per_min_beet

trigger:
  - platform: sun
    event: sunrise

action:
  - service: switch.turn_on
    metadata: {}
    data: {}
    target:
      entity_id: !input valve_beet
  - delay: >-
      {{ ((var_target_soil_moisture_beet | float(85)  -
      var_moisture_sensor_beet | float(75))  /
      var_percentage_per_min_beet | float(10)) * 60 }}
  - service: switch.turn_off
    metadata: {}
    data: {}
    target:
      entity_id: !input valve_beet
mode: single

The issue here is, that my moisture sensor delivers an invalid input and if I don’t specify a default value, I get following error:

Logger: homeassistant.components.automation.outdoo_irrigation_blueprint
Quelle: helpers/script.py:2002
Integration: Automatisierung (Dokumentation, Probleme)
Erstmals aufgetreten: 21:33:13 (5 Vorkommnisse)
Zuletzt protokolliert: 21:55:47

Outdoo Irrigation - Blueprint: If at step 2: Error rendering Outdoo Irrigation - Blueprint: If at step 2 delay template: ValueError: Template error: float got invalid input 'sensor.tuya_feuchtigkeitssensor_soil_moisture' when rendering template '{{ ((var_target_soil_moisture_beet | float - var_moisture_sensor_beet | float) / var_percentage_per_min_beet | float) * 60 }}' but no default was specified

With a specified default value, the default value will always be used.

If I test the template in the development tools, I get a valid result:

delay: >-
  {{ ((states( 'input_number.target_soil_moisture_beet' ) | float  - states(
  'sensor.tuya_feuchtigkeitssensor_soil_moisture' ) | float)  / states(
  'input_number.percentage_per_min_beet' ) | float) * 60 }}


Maybe it is an issue, that I receive the result of type “string”?

Last, but not least some informations about the entity:

I just want to calculate a delay, depending on the current soil moisture.

What I tried so far:

  1. I’m using variables in the template instead of “!input” method
  2. I added the prefix “var_” for a unique naming of the variables
  3. I specified default values, when parsing

Best regards!

That is saying what you have is not a number. I know you see the number in states, but that is your error.
This is confusing you. When you are putting an entity into a variable like that, it puts the name of the entity into the variable as text. When you do your template the entity is not there, it is words that match the entity name words.
So in your variable statement, do the states template with the float cast up there so the variable contains the number, Do the same for the input_numbers as well. Then it 1, should work, and 2, your automation trace will tell you the number it is using so you can check all is well.

Thanks for the reply.

Could you give me an example?
I tried different things, but don’t get it, e.g.

variables:
  var_target_soil_moisture_beet: '{{ states(target_soil_moisture_beet) | float }}'
  var_moisture_sensor_beet: '{{ states(moisture_sensor_beet) | float }}'
  var_percentage_per_min_beet: '{{ states(percentage_per_min_beet) | float }}'

action:
  - delay: >-
      {{ ((var_target_soil_moisture_beet -
      var_moisture_sensor_beet))  /
      var_percentage_per_min_beet) * 60 }}

But I get following error

Message malformed: offset {{ ((var_target_soil_moisture_beet - var_moisture_sensor_beet)) / var_percentage_per_min_beet) * 60 }} should be format 'HH:MM'

That says you have a number now.
Force it into an | int I think and/or add the seconds: key.
I believe seconds may need to be an integer.
Script Syntax - Home Assistant.