Automation help - slider input number

Hey all,
ive read a few topis on this but im still getting errors and need some help please!
I cant work out where this is going wrong…

i copied the info found here: Using input_number in an automation

which gave me this:

- id: barlightsoffafterxminnomotion
  alias: bar lights off no motion timer expired
  description: ''
  trigger:
  - entity_id: binary_sensor.bar_motion_sensor_hue_dz
    for:
      minutes: "{{ states('input_number.timer_bar_motion_slider') | int(0) }}"
    platform: state
    to: 'off'
  condition: []
  action:
  - service: homeassistant.turn_off
    entity_id: group.room_bar_all_lights_group

and

input_number:
  timer_bar_motion_slider:
    name: Timer Bar Motion
    initial: 5
    min: 5
    max: 55
    step: 5

however i keep getting this error

Logger: homeassistant.config
Source: config.py:415
First occurred: 11:01:17 (1 occurrences)
Last logged: 11:01:17
Invalid config for [automation]: must be a value between 0 and 59 for dictionary value @ data[‘minutes’]. Got None. (See /config/configuration.yaml, line 28).

Try removing the " " around the code behind minutes:.

get a fatal error if i do that:

image

- id: barlightsoffafterxminnomotion
  alias: bar lights off no motion timer expired
  description: ''
  trigger:
  - entity_id: binary_sensor.bar_motion_sensor_hue_dz
    for:
      minutes: {{ states('input_number.timer_bar_motion_slider') | int(0) }}
    platform: state
    to: 'off'
  condition: []
  action:
  - service: homeassistant.turn_off
    entity_id: group.room_bar_all_lights_group```

Ok. What happens when you replace int(0) by int?
I’m used to using float or int, never heared/seen using int(0).

Also, what happens when you leave out the | int part?

I have something similar

I have two sliders which control my lights

  1. Minutes to turn off lights with no motion
  2. Time to send a notification is the light has been on

I then have this set up for my automation (note the time is HH.MM.SS)

- id: '1608068903614'
  alias: '[Light Auto Off With No Motion] [Landing] Off after X minutes without motion'
  description: ''
  trigger:
  - platform: state
    entity_id: binary_sensor.landing_motion_sensor_motion
    to: 'off'
    for: 00:0{{ states('input_number.lights_automation_lights_off_after') |int}}:00
  condition:
  - condition: state
    entity_id: input_boolean.lights_automation_master_lights_off_after_x_minutes
    state: 'on'
  - condition: state
    entity_id: light.landing
    state: 'on'
  action:
  - type: turn_off
    device_id: 435f7a3d12fe11eb947f1b4c72e93e25
    entity_id: light.landing
    domain: light
  mode: single

input_boolean.lights_automation_master_lights_off_after_x_minutes
I can turn this on/off to stop all the automations

input_number.lights_automation_lights_off_after
Can only be set 1 to 9 minutes

To summarise above, your time is only a single digit (5) - but the actual time on the motion sensor will be hh/mm/ss

00:{{ states('input_number.lights_on_notify_lights_on_for_x_minutes')|float |int }}:00

Maybe something like this

- id: barlightsoffafterxminnomotion
  alias: bar lights off no motion timer expired
  description: ''
  trigger:
  - entity_id: binary_sensor.bar_motion_sensor_hue_dz
    for:
      minutes: " 00:{{ states('input_number.timer_bar_motion_slider')|float |int }}:00 "
    platform: state
    to: 'off'
  condition: []
  action:
  - service: homeassistant.turn_off
    entity_id: group.room_bar_all_lights_group

But you’ll need to change your value input from 11 to 59

When using your idea you can’t use the minutes:part. Only use the for:part.

And why do you suggest using |float |int in your last post while you use only |int in your first post?

I’m unsure what you mean by this?
“When using your idea you can’t use the minutes: part. Only use the for: part.”

I don’t think you need the |float - this is just used for decimal numbers.
The issue you have when creating a slider, is that the numbers 1-9 are only single digit…

As you can see below, I had to compensate for this

00:{{ states('input_number.lights_on_notify_lights_on_for_x_minutes')|float |int }}:00

00:0{{ states('input_number.lights_automation_lights_off_after') |int}}:00

So my first slider only goes from 1-9 minutes (the hard coded leading zero takes care of the rest)
My second slider goes from 10-59

Your automation isn’t working because it’s looking for a single digit time (5 not 00:05:00)

From…

    for:
      minutes: "{{ states('input_number.timer_bar_motion_slider') | int(0) }}"

To…

    for:
      minutes: "00:{{ states('input_number.timer_bar_motion_slider') | int(0) }}:00"

From…

input_number:
  timer_bar_motion_slider:
    name: Timer Bar Motion
    initial: 5
    min: 5
    max: 55
    step: 5

to…

input_number:
  timer_bar_motion_slider:
    name: Timer Bar Motion
    initial: 10
    min: 10
    max: 55
    step: 5

I think it should be either:

for:
    minutes: "{{ states('input_number.timer_bar_motion_slider') | int }}"

Or:

for: "00:{{ states('input_number.timer_bar_motion_slider') | int }}:00"

After minutes: there can only be a number that’s between 0 and 59.

And, you are correct about the slider, that 10 must be the lowest number, otherwise the 2nd solution will not work.

3 Likes

This works:


for:
    minutes: "{{ states('input_number.timer_bar_motion_slider') | int }}"

I have the exact same setup in my config. Using the above code for the minutes works like a charm.
You only need to leave out the (0) in int(0).

1 Like

cheers!! have applied

Hi,

Sorry to revive this old thread, but I’m trying to setup an automation to pull the minute duration from a slider helper and I keep getting the error message “Message malformed: expected float for dictionary value @ data[‘for’][‘minutes’]”. The slider is setup for 10 to 59 and my code is below. Any idea why this command isn’t working for the minutes variable? When I enter it, I get a popup with the correct setting, so it’s reading the variable from the slider.

Thanks in advance.

description: ""
trigger:
  - platform: device
    type: turned_on
    device_id: 423260d61030d0cb76a1c27ec9389ff9
    entity_id: light.cottage_driveway_light
    domain: light
    for:
      minutes: "{{ states('input_number.motion_light_on_duration') | int }}"
condition:
  - condition: state
    entity_id: input_boolean.virtual_switch
    state: "on"
action:
  - type: turn_off
    device_id: 423260d61030d0cb76a1c27ec9389ff9
    entity_id: light.cottage_driveway_light
    domain: light
mode: single