Input_number to minutes

Hello.
I have input_number slider that I wan to adjust when the lights turn off (in minutes).

input_number:
  bathroom_delay_minutes:
    mode: slider
    name: Bathroom Light Delay
    initial: 5
    min: 0
    max: 60
    step: 1

I alse have a simple automation that turn off light in Bathroon based on motion sensor inactivity.
It turns light off after 5min.

- id: bathroom_light_motion_off
  alias: Bathroom Light Motion Off
  initial_state: false
  trigger:
  - platform: state
    entity_id: binary_sensor.aeotec_zw100_multisensor_6_001_sensor
    to: 'off'
    for:
      minutes: 5

What I want to do is to use input_number insted og 5 minutes:
Something like this:

minutes: (inoput number slider value here)

I have tried to read documentation up and down, and none of examples works.

I know that there are different ways for this aproach, but I want to know if there is a wa yto put input value intu minutes…

Any one who could hellp?

Martin

Try this

- delay: "00:{{ states.input_number.bathroom_delay_minutes.state | int }}:00"

Just re read your question, delay won’t as part of the trigger. You could use a script and put the variable delay in there. The action could be script turn off and then script turn on to reset the timer

I see.
So there is no way to convert input_number so it works with a trigger: minutes:…

Thx…

There may well be, hopefully someone with a bit more knowledge will have the answer. I’ve only just started using input_numbers

Then we are in the same boat… :slight_smile:

I tried to solve your problem as an exercise. :slight_smile:

This will work without script:

- id: bathroom_light_motion_off
  alias: Bathroom Light Motion Off
  trigger:
    - platform: time
      seconds: '/10'
  condition:
    condition: and
    conditions:
      - condition: template
        value_template: "{{(as_timestamp(now())-as_timestamp(states.binary_sensor.aeotec_zw100_multisensor_6_001_sensor.last_updated)) | int > states.input_number.bathroom_delay_minutes.state | int*60 }}"
      - condition: state
        entity_id: binary_sensor.aeotec_zw100_multisensor_6_001_sensor
        state: 'off'
      - condition: state
        entity_id: BATHROOM_LIGHT
        state: 'on'
  action:
    - service: light.turn_off
      entity_id: BATHROOM_LIGHT

Hello guys.

This thread is outdated due to new version of HA and indroduction of timer.
I manadged to get it to work with timers:

Bathroom Light On By Motion - Begin Code

  • id: bathroom_light_on_by_motion
    alias: Bathroom Light On By Motion
    initial_state: true
    trigger:
    • platform: state
      entity_id: binary_sensor.aeotec_zw100_node5_multisensor6_sensor
      to: ‘on’
      action:
    • service: timer.cancel
      entity_id: timer.bathroom_timer
    • service: switch.turn_on
      entity_id: switch.qubino_flush1_node6_inwall_switch

End Code

Bathroom Light Motion Timer On - Begin Code

  • id: bathroom_light_motion_timer on
    alias: Bathroom Light Motion Timer On
    initial_state: true
    trigger:
    • platform: state
      entity_id: binary_sensor.aeotec_zw100_node5_multisensor6_sensor
      to: ‘off’
      action:
    • service: timer.start
      entity_id: timer.bathroom_timer

End Code

Bathroom Light Off By Motion - Begin Code

  • id: bathroom_light_off_by_motion
    alias: Bathroom Light Off By Motion
    initial_state: true
    trigger:
    • platform: event
      event_type: timer.finished
      event_data:
      entity_id: timer.bathroom_timer
      condition:
      condition: state
      entity_id: binary_sensor.aeotec_zw100_node5_multisensor6_sensor
      state: ‘off’
      action:
    • service: switch.turn_off
      entity_id: switch.qubino_flush1_node6_inwall_switch

End Code

What I am doing is:

  • When there is a motion: Turn lights on and cancel timer
  • When there is no motion: start timer
  • When timer is fininshed: Turn Lights Off.

This works great.

Right now I have timer set to 3 min:

bathroom_timer:
name: Bathroom Timer
duration: ‘00:03:00’
icon: mdi:ceiling-light

But I want to use input_number to control delay.

bathroom_delay_minutes:
mode: slider
name: Bathroom Light Delay
initial: 1
min: 0
max: 10
step: 1

I tried to:

bathroom_timer:
name: Bathroom Timer
duration: “00:{{ states.input_number.bathroom_delay_minutes.state | int }}:00”
icon: mdi:ceiling-light

But I get error.

Any ideas?

You can’t specify a dynamic duration when the timer is initialized. If you do it that way you would have to restart home assistant every time you change the value.
The timer.start service allows to pass a duration on the fly. So you could use a template for the service data, which then would be evaluated every time the timer is started. The sevice accepts either the time like '00:11:22' or just raw seconds. It may be easier to just use the value from your input_number and multiply it by 60 instead of trying to convert to the time-format.

1 Like