Help with input_number for light timer automation

Trying to add a slider bar to enable a light off timer automation so I can chanmge the time the light is on for before turning off.

Currently this is my automation set to 20 min. I wish to be able to change that 20 min between 1 and 60

- id: timed_ensuite_light
  alias: Ensuite Light Timer
  trigger:
  - entity_id: light.ensuite_light
    for:
      minutes: 20
    platform: state
    to: 'on'
  action:
  - entity_id: light.ensuite_light
    service: light.turn_off

and this is the slider in my config.yaml

input_number:
  slider1:
    name: Slider
    initial: 30
    min: 1
    max: 60
    step: 1

Still learning input number so just left it all defaults but cant figure out what needs to go in the automation to enable the slider.

Have tried different things with the trigger and even with a condition but cant get it.

Any help for be great.

Thanks

You will be able to use a template with the state trigger’s for: option starting with 0.96. In fact it’s already in the beta release. See:

Thanks so I just have to wait or go beta

Well people have done this other ways because they had to. But, yes, it will be much easier once you are using 0.96.0b0 or later.

1 Like

Thanks for the info

0.96 has included it and it now works a treat.

Have mine set so when set to 0 it disables the automation that it is linked to for its timer so I am able to remove a toggle switch and just replace it with a slider.

code just in case someone else is seeking the same

input_number

  ensuite:
    name: Ensuite Light Timer
    min: 0
    max: 60
    step: 1
    unit_of_measurement: mins

Automation with the slider

- id: timed_ensuite_light
  alias: Ensuite Light Timer
  trigger:
  - entity_id: light.ensuite_light
    for: 
      minutes: "{{ states('input_number.ensuite') | int }}"
    platform: state
    to: 'on'
  action:
  - entity_id: light.ensuite_light
    service: light.turn_off

Automations to trigger the above automation on/off with the slider

- id: turn_off_ensuite_timer
  alias: Ensuite Timer Off
  trigger:
  - entity_id: input_number.ensuite
    platform: state
    to: '0.0'
  action:
  - service: automation.turn_off
    entity_id: automation.ensuite_light_timer
    
- id: turn_on_ensuite_timer
  alias: Ensuite Timer On
  trigger:
  - entity_id: input_number.ensuite
    from: '0.0'
    platform: state
  action:
  - service: automation.turn_on
    entity_id: automation.ensuite_light_timer

Glad to hear it! :slight_smile:

No real need for the extra automations. You can effectively do the same by adding a condition to the first automation:

 - id: timed_ensuite_light
  alias: Ensuite Light Timer
  trigger:
  - entity_id: light.ensuite_light
    for: 
      minutes: "{{ states('input_number.ensuite') | int }}"
    platform: state
    to: 'on'
  condition:
    condition: template
    value_template: "{{ states('input_number.ensuite') | int > 0 }}"
  action:
  - entity_id: light.ensuite_light
    service: light.turn_off

Had a feeling there was a cleaner way to do it and was going to look into that today so you just saved me the effort. Thanks.

1 Like

Wondering if you can help with my next input_number problem.

Have a humidity sensor in the bathroom that activates the exhaust fan but I want to be abe to change the humidity trigger point.

Ive tried the following but it does not like it.
input_number.ensuitefanhum is the humidity input_number slider

- id: ensuit_fan_humidity
  alias: Exhaust Fan
  trigger:
  - entity_id: sensor.test_humidity
    platform: numeric_state    
    above: "{{ states('input_number.ensuitefanhum') | int }}"
  condition:
  - condition: state
    entity_id: light.ensuite_light
    state: 'on'
  action:
  - entity_id: fan.ensuite_fan
    service: fan.turn_on

doing

  - entity_id: sensor.test_humidity
    platform: numeric_state    
    above: '80'

works for readings above 80 but I would like to use a slider to change this.

I can get it working using a time_pattern but this seems like extra work the system needs to do for a simply task

- id: ensuit_fan_humidity
  alias: Exhaust Fan
  trigger:
    platform: time_pattern
    seconds: '/15'
  condition:
  - condition: state
    entity_id: light.ensuite_light
    state: 'on'
  - condition: template
    value_template: "{{ states('sensor.test_humidity') | float > states('input_number.ensuitefanhum') | float }}"
  action:
  - entity_id: fan.ensuite_fan
    service: fan.turn_on

I think it would be better to create a new topic, just for the sake of clarity and readability :wink:
Speaking about time_pattern - I don’t remember and can’t check right now, but my setup reacts to state change of the slider instead of periodic checks, hope it helps.

Was going to create a new topic but it is still a similar issue so thought I could just tag it on.

The issue I have is I can’t get the slider to be used as a trigger to enable any state change reactions.

The time_pattern is my current work around to get it working

why? something like this

trigger:
 platform: state
 entity_id: input_number.ensuitefanhum

should do the job.

Thanks I will give that a go. Maybe what I was doing was over complicating the formula.

If I understand the question properly, use the following as a trigger

trigger:
  - platform: state
    entity_id: input_number.ensuitefanhum

which should cause a trigger any time that input_number is changed

Damn it! @AhmadK beat me to it :slight_smile:

1 Like

Sorry I think the question has been misunderstood.

I need the trigger to be linked to the humidity sensor and only trigger when the sensor is above the slider value.

The issue is with the above: entry. I will try putting input_number.ensuitefanhum in the above: section once I finish work and get home

The above code looks like it will work only if the slider is changed. Unless I am reading it wrong.

trigger:
  - platform: state
    entity_id: input_number.ensuitefanhum

condition:
  - platform: template
    value_template: "{{ states('sensor.test_humidity') | float > states('input_number.ensuitefanhum') | float }}"
action:
  - service: fan.turn_on
    entity_id: fan.ensuite_fan

Won’t this only trigger if the slider is changed?(assuming the condition is met)

I want to use the slider to change the point where the trigger activates.

It will trigger to test the condition any time the slider is moved. It will only process the action if the value is above the slider value. In order to have it trigger on the sensor value as well, we need another trigger:

trigger:
  - platform: state
    entity_id: input_number.ensuitefanhum
  - platform: state
    entitiy_id: sensor.test_humidity

condition:
  - platform: template
    value_template: "{{ states('sensor.test_humidity') | float > states('input_number.ensuitefanhum') | float }}"
action:
  - service: fan.turn_on
    entity_id: fan.ensuite_fan

which will then also test the condition whenever the humidity changes

1 Like

Will that only trigger if the slider is moved?

Want the slider to set the value that the humidity sensor triggers when it’s above the slider value.

(On my phone so it’s a pain in the backside)