Calling different states as values?

Evening All,

I have the following:

input_number:
  washvar:
    name: Slider
    initial: 5760
    min: 0
    max: 6300
    step: 1

timer:
  timer:
    duration: 30
    
counter:
  elapsed:
    name: Progress
    initial: 30
    step: 1
    icon: mdi:timer 

However I want to be able to change the value of thirty based on what is in for the input_number.

What I have tried is this:

input_number:
  washvar:
    name: Slider
    initial: 5760
    min: 0
    max: 6300
    step: 1

timer:
  timer:
    duration: {{ states.input_number.washvar.state }} 
    
counter:
  elapsed:
    name: Progress
    initial: {{ states.input_number.washvar.state }} 
    step: 1
    icon: mdi:timer 

However this causes a non boot of the WebUI as {{ states.input_number.washvar.state }} = none upon boot.

I have tried setting up a automation to set the value upon boot but still same issue.

I have tried “cheating” and changing the value to {{ 0 + (states.input_number.washvar.state) }} in the hopes that is would set as 0 but no joy.

Basically I’m trying to have a visual timer based on the selection of an inpu boolean. These are timers for my main wash loads on my washing machine.

I have an input boolean called 30_wash and 40_wash and automations that set input_number.washvar to the relative times. However as {{ states.input_number.washvar.state }} is not valid upon boot the timer and counter aren’t valid.

Any ideas?

Unfortunately, you can’t use a template that way in a configuration file. You can only use a template in places where Home Assistant is expecting to get a template.

There is a timer service that MIGHT take a data_template as a parameter.
It’s worth a shot.

Thanks, I’ll give that a try.

Odd thing is I can change the value of input_number.washvar with a automation from whatever to whatever it’s just as it has no value when counter and timer are started on boot it’s not valid.

This is how I do something similar…

link removed

Note that I don’t set a duration in the component declaration, it’s set dynamically via automation when the slider is moved. Timer is then cancelled if the slider is dragged to zero.

1 Like

@anon43302295 Wow ! I never knew you could have conditions as a part of an action !!

In what you have there, the timer.cancel service will only be called if the condition above it is met ?

Yeah, so the action is:

  • Set the timer to the value of the input_number

  • Check if that value was zero.

  • If not, do nothing. If so, cancel the timer.

See here for how script syntax works…

1 Like

Thankyou !

This bit of info will help me move more of my automations to scripts.
The one thing I don’t like about automations is that once they’ve been triggered, there’s no stopping them !!

It’s definitely a very powerful part of homeassistant.

Basically treat the action part of the automation as a script and then if you want to fire different things you could action separate scripts from the automation, and then put a condition at the top of each script so only the correct ones are actioned.

Combine it all with templates and you can get some really intelligent routines. Happy coding :+1:

Thanks for this will have a mess and see if my little brain can get it together.

1 Like