My First Automation - now how to add dynamic input?

Hi folks,

I managed to make my first automation yesterday with the help of a few very nice people on this forum. I am hopeing someone can help me improve it today.

Firstly, the automation

    alias: 'Living Room Radiator (1 hour)'
    trigger:
    - platform: state
      entity_id: automation.living_room_radiator_1_hour
      to: 'on'
    action:
    - delay: '0:00:01'
    - service: switch.turn_on
      entity_id: switch.switch_3
    - delay: '1:00:00'
    - service: switch.turn_off
      entity_id: switch.switch_3
    - delay: '0:00:01'
    - service: automation.turn_off
      entity_id: automation.living_room_radiator_1_hour

Frontend
image

Is there anyway to allow me to select the number of hours to switch on the radiator for? If so, how would i implement it into my automation or config yaml file.

Thank you

Unfortunately I don’t remember which post I saw it on, but what you are looking for is called an input slider.

Depending on the value you assign to the steps/notches of the slider, you can define the number of minutes (in your case) to goody will be on or off.

:slight_smile:

This is what you’re looking for;

Yeah i figured it was that but the problem is i dont have the know how to implement that in my automation.

I basically want a toggle to turn on/off the radiator and then a toggle(slider i spose) to run an automation to tirn off after a set number of hours.

You could create a script, with a delay like

script1:
  sequence:
    - service: switch.turn_on
      entity_id: switch.tank_pump
    - delay: '{{ states.input_number.hours.state | int }}:00:00'
    - service: switch.turn_off
      entity_id: switch.tank_pump

I gave you the code in your other thread. as posted in previous replies, you create an input_number (HA v0.55 or higher). then in your automation, you put the value of the input_number in the delay. like so:

input_number:
  radiator_hours:
    name: Radiator Hours
    icon: mdi:clock
    min: 0
    max: 12
    step: 1

Then in the automation:

- delay: '{{ states.input_number.radiator_hours.state | int }}:00:00'

whenever the automation is triggered, it will wait however long the input_number is set for.

EDIT: Here’s the post I originally suggested this in.

Thank you! Yeah I hadnt realised, i managed to get it to work all thanks to you!