Use timer based on a calculation

Is there a way to use a calculation as input for a timer in a automation.

E.g. I want something running for 25% of a preset time. So 25% of 8 seconds.

That something are the windows of my greenhouse. 2 seconds is about 25% of opening.

Yes. See here:

Give full details if you want more help: when and how you want to set the input, where does the 25% come from, where does the 8 seconds come from?

Depending how your windows operate, this may help:

The 8 seconds is the time the windows need to open completely. The 25 % in the example comes from a dropdown helper.

What I want to do in the automation:

  • activate close the windows and wait 10 seconds to fully close
  • activate open the windows and wait a time depending on dropdown setting or
  • in case of 100 activate the open windows and wait 10 seconds or
  • in case of 0 close the windows.

The 10 seconds is to be sure they are fully opened or closed.

Is this what you want to know.

You’d probably be better off with a delay than a timer for that.

Are you building the automation in the UI?

If so, it’ll look something like this (I’m using my hall light as a surrogate for your windows):

To use a template in the Delay, you’ll need to hit the three dots and Edit as YAML.

If that’s not enough you want a complete example, I need to know what “activate ope/close the windows” looks like, ideally as YAML; and what the entity ID and contents of the dropdown is.

Thanks, you where a great help.

It ended up like this:

  hours: 0
  minutes: 0
  seconds: "{{ states('input_select.ramen_kasje') | multiply(0.08) | int }}"
  milliseconds: 0

input_select.ramen_kasje is the helper with the openings percentidge. It would be nicer if could devide that by 100, but I’m still strugeling with the templates after 4 or 5 years. The manuals I’ve seen about this aren’t very clear for me.

seconds: "{{ states('input_select.ramen_kasje') | int * 8 / 100 }}"

The state of the input number is, as with all states, a string. You need to convert to int or float before doing arithmetic on it.

multiply also does this conversion for you (and I have an open pull request to document it), but there is no divide.