In an automation, set delay in minutes from template value

H, I am a newbie at Home Assistant.
Running home assistant on raspberry pi.

I am trying to set a delay in minutes from a sensor value which essentially is a base value multiplied by a slider value.

The automation refuses to run. I suspect something is wrong with the way I implement the delay.

Any help appreciated.

 alias: DelayTest
 description: "
 trigger:
   - platform: time
     at: "18:41:00"
 condition: []
 action:
   - type: turn_on
     device_id: db7a66b320551e43341fa90sdfrb9e95
     entity_id: 01dd0212978c06c1hd8y25636fab4a2e
     domain: switch
   - delay:
       minutes: "{{ states('sensor.DoorCloseDelay')|int }}"
   - type: turn_off
     device_id: db7a66b320551e43341fa90sdfrb9e95
     entity_id: 01dd0212978c06c1hd8y25636fab4a2e
     domain: switch
 mode: single
  1. Go to Developer Tools > States

  2. Find sensor.DoorCloseDelay in the list.

  3. If the sensor exists it will be displayed as sensor.doorclosedelay because an entity_id is always shown in lowercase.

  4. Confirm the sensor’s value is a number. If it’s not then the int filter cannot convert it to a number. The automation will then fail because you overlooked to supply int with a default value. For example, int(0) will return 0 if the supplied string cannot be converted to a number.

  5. If the sensor does not exist then the automation will fail because int was not given a default value.

Let me know what you find after performing the steps in the suggested debugging procedure.

If everything seems normal (sensor exists and has a numeric value) then check the automation’s trace for additional clues.

Thx for the help.

So I get this error in the trace
Error: ValueError: Template error: float got invalid input ‘unknown’ when rendering template ‘{{ ‘00:{:02}:00’.format(states(‘sensor.DoorCloseDelay’) | float()) }}’ but no default was specified

This code I used for my purposes from: https://community.home-assistant.io/t/using-template-in-delay-in-automation/172151/3

It only works when I specify a default, it does not use the value of the sensor.

{{(((states('input_number.seasonaladjustment') | float(0)/ 100 ) * (states('input_number.standarddooropentime')) | float(0))| int)}}

seasonaladjustment : Value = 50
standarddooropentime: Value =2

What am I doing wrong.

This error message:

Error: ValueError: Template error: float got invalid input ‘unknown’ when rendering template ‘{{ ‘00:{:02}:00’.format(states(‘sensor.DoorCloseDelay’) | float()) }}’ but no default was specified

refers to a template that doesn’t exist in the automation you posted above. It makes it more challenging to help you when the information presented to the public doesn’t accurately reflect what you are actually using.

An error is produced because the value of sensor.DoorCloseDelay is not a numeric string. The float filter is designed to convert numeric strings to numbers. If it receives a non-numeric string, it reports its default value if one has been specified. If no default value is specified, an error is reported.

Correct. float will report its default value if it cannot convert a string to a number. The same applies for the int filter.

I deleted all the inputs and template an recreated them. It is working now, but I am honestly not sure why.

Appreciate the help