Timers for all switches and lights

Hi all,

I have been using HA for around 2 years and is great. The only one feature that I am lazy doing is the timers. I have done one and use it everyday. I have it working with a timer, drop-down input for the minutes and it turns of my predefined switch. I was thinking to have a drop-down for the ID of the switch, but this was can’t use it for than one thing at a time, cause I have only one timer.

And there is my pain point, I have to do this setup for all my switches and lights (everything that could be toggled).

I noticed that most smart things have some sort of turn on/off timer in their apps.
I wish HA have the same functionality. An easy to setup turn on/off timer.

Until this is (ever) implemented just use an input number/slider and a short automation to turn off each device. Not a timer.

Just cut and paste, and edit the entity_id’s for every device:

input_number

kitchen_light_time: # one of these for each device
  name: Kitchen Light Time 
  initial: 5
  min: 0.5
  max: 15
  step: 0.5
  unit_of_measurement: Min
  icon: mdi:clockwise

automation

- alias: Turn off kitchen light after xx minutes # repeat for each device
  trigger:
    platform: state
    entity_id: light.kitchen_light # change this id for each device
    to: 'on'
    for:
      minutes: "{{ states('input_number.kitchen_light_time') }}" # change this id for each
  action:
    service: homeassistant.turn_off
    entity_id: light.kitchen_light # change this id for each.

It may be possible to use only one automation (and multiple input numbers) if you cleverly name all your entity id’s but honestly that is more trouble than it is worth. Cut and paste is quick.

I cheated and just use node red. I create a flow for each of my lights that I want on timer, basically saying

If status changed from off to on then start timer for x minutes, after timer has ended turn off.

I like the utility and slider on this automation. It’s perfect for my water heater. But it’s not working.

I put both pieces of code in the Automations.yaml
I have a feeling that the first one belongs somewhere else. :confused:

switch.boiler_parents: # one of these for each device
  name: Boiler Parents  
  initial: 10
  min: 0.5
  max: 90
  step: 0.5
  unit_of_measurement: Min
  icon: mdi:clockwise
  
   - alias:Turn off Boiler Parents after xx minutes # repeat for each device
  trigger:
    platform: state
    entity_id: switch.boiler_parents # change this id for each device
    to: 'on'
    for:
      minutes: "{{ states('input_number.switch.boiler_parents') }}" # change this id for each
  action:
    service: homeassistant.turn_off
    entity_id: switch.boiler_parents # change this id for each.

The error from the log is


Invalid config for [automation]: [switch.boiler_parents] is an invalid option for [automation]. Check: automation->switch.boiler_parents. (See /config/configuration.yaml, line 10).

The first code snippet is an input number. So it goes under input_number: in your configuration.yaml file. Or create it in the Configuration/ Input Helpers UI.

Sounds simple to me. Do you want the same timer for all entities
If so list all the entities as a state trigger with a for: time. Then template the action to the trigger entity?

If you want different times you’ll have to make seperate triggers with their own for: times. But the action can be a template

Thanks!

I made that change.

I then ran the check configuration and it suggested I change

switch.boiler_parents

to

switch_boiler_parents:

So it now looks like:

input_number:
  switch_boiler_parents: # one of these for each device
  name: Boiler Parents  
  initial: 10
  min: 0.5
  max: 90
  step: 0.5
  unit_of_measurement: Min
  icon: mdi:clockwise

So I did, and re-started and then received this:

2021-03-31 09:13:57 ERROR (MainThread) [homeassistant.config] 

Invalid config for [automation]: [automation] is an invalid option for [automation]. 

Check: automation->automation. (See /config/configuration.yaml, line 11).

2021-03-31 09:13:57 ERROR (MainThread) [homeassistant.components.hassio] 
Invalid config for [input_number]: 
expected a dictionary for dictionary value @ data['input_number']['icon']. Got 'mdi:clockwise'

expected a dictionary for dictionary 
value @ data['input_number']['initial']. Got 10

expected a dictionary for dictionary value 
@ data['input_number']['max']. Got 90

expected a dictionary for dictionary value 
@ data['input_number']['min']. Got 0.5

expected a dictionary for dictionary value 
@ data['input_number']['name']. Got 'Boiler Parents'

expected a dictionary for dictionary value 
@ data['input_number']['step']. Got 0.5

expected a dictionary for dictionary value 
@ data['input_number']['switch_boiler_parents']. Got None

expected a dictionary for dictionary value 
@ data['input_number']['unit_of_measurement']. 
Got 'Min'. (See /config/configuration.yaml, line 20).

Then I returned the Initial, min, max to the same as the original template script. I still get the same errors.

Once this works - will it show up as and entity or something else?