Input select with time

Hi

So I am trying to select an input from my frontend to trigger an action in this case I am trying to turn on my heater for ‘X’ number of minutes. Here is my code but it doesnt work as intended:

automation:
    - alias: 'Turn heater on for 5 minutes'
      initial_state: True
      trigger:
        - platform: homeassistant
          event: start
      action:
        - service: switch.turn_on
          entity_id: switch.heater
        - delay: '00:05:00'
        - service: switch.turn_off
          entity_id: switch.heater

Input Select:

input_select:

  heater:
    name: 'Turn on Heater'
    options:
     - 'automation.turn_heater_on_for_5_minutes'

Can anyone please help?

Thanks.

You are triggering from HA startup…

It should look like this…

 - alias: Turn heater on for 5 minutes
#   hide_entity: false
   initial_state: 'on'
   trigger:
     - platform: state
       entity_id: input_select.heater_bedroom
       to: "Turn_On_Heater"
   action:
     - service: switch.turn_on
       entity_id: switch.heater
     - delay: '00:05:00'
     - service: switch.turn_off
       entity_id: switch.heater

and your input_select should look like this…

heater_bedroom:
  name: Bedroom Heater Options
  options:
    - Turn_On_Heater
    - Turn_Off_Heater
    - None
  initial: None 

Notice I didn’t call my input_select the same name as my switch :wink:

Thanks Keith.

All works well. I had a question with regards to the input selection; If I select “Turn_On_Heater” the heater turns on for 5 mins, however if I then select “None” I expect nothing to happen which is fine but if I select “Turn_On_Heater” again it turns the heater off. I would have expected it not to do anything?

Also in the options can I get away with the underscore and use spaces?

And finally in the automation for “None” what shall I put as an action?

Thanks mate.

I don’t know why it would turn off the heater, it shouldn’t unless the delay is getting by passed somehow.

In the options you can indeed use spaces…

lullaby:
  name: Lullaby
  options:
    - Heavy Rain MP3
    - Rain In The Woods 10hrs MP3
    - Rain and Thunder MP3
    - Babbling Brook MP3
    - Ocean Waves MP3
    - Watersounds Bird Song MP3        
    - FireplaceBurning AVI
    - Campfire by the River AVI  
    - WaterfallOceanBeach AVI
    - Coral Reef Aquarium AVI
    - None
  initial: None
  icon: mdi:weather-rainy

I wouldn’t bother with an automation for none it’s just there if you don’t want to select off or on.

1 Like

Thanks buddy.

@Tinkerer could you please share your thoughts as to why the delay is getting by passed when I select the “Turn_on_heater” after selecting delay.

Thanks.

Does the Logbook show anything?

It’s possible the issue is just that the delay is too long. I’d suggest splitting it into 2:

 - alias: Turn heater on for 5 minutes
   initial_state: 'on'
   trigger:
     - platform: state
       entity_id: input_select.heater_bedroom
       to: "Turn_On_Heater"
   action:
     - service: switch.turn_on
       entity_id: switch.heater
     - service: input_boolean.turn_on
       entity_id: input_boolean.heater_bedroom

 - alias: Turn heater off after 5 minutes
   initial_state: 'on'
   trigger:
     - platform: state
       entity_id: switch.heater
       to: 'on'
       for:
         minutes: 5
   condition:
     - condition: state
       entity_id: input_boolean.heater_bedroom
       state: 'on'
   action:
     - service: switch.turn_off
       entity_id: switch.heater
     - service: input_boolean.turn_off
       entity_id: input_boolean.heater_bedroom

Obviously you also need the matching input_boolean:

input_boolean:
  heater_bedroom:
    name: Bedroom heater turned on by an automation
    initial: off
1 Like

Logbook doesnt show anything just for the heater on and heater off i.e. as soon as I select “None” and then select “Turn_On_Heater” again it turns the heater off.

What does it do if you don’t select none?

Nothing happens.

So remove none from the input_select and set the initial to off or on and you are good to go :slight_smile:

@Tinkerer your automation solved it thanks !
If I wanted to turn the heater on for 3 minutes, its the same code just the minutes to 3 correct?

Yes, that’s right.

Thanks !

Can the title of the card “Input Select” be changed?

i.e. 13

can you share the full config code, I also want to use flexible timed heating if that’s possible, ie 1 hour upto 5 hours

Just give the group a name:

well its not in a group its just like this:

input_select:
  heater_bedroom:
    name: Bedroom Heater
    options:
     - 'Heater on for 5 mins'
     - 'None'
    initial: 'None'
    icon: 'mdi:fan'

ok made a group and sorted it. Thanks for your help.

@elRadix The code I used is the one provided by @Tinkerer :

In the minutes where it says 5 i.e

       trigger:
         - platform: state
           entity_id: switch.heater
           to: 'on'
           for:
             minutes: 5 

change it to 60 (1 hour) or 300 (5 hours) whichever you prefer.

or use hours instead of minutes i.e.

           for:
             hours: 5

Hi thank you for the code it works great for my pool.
Was just wondering can the state change back to none when the 5 min/hours is over?