Using input_number in automation not working

Hi all – kind of befuddled here. I’m trying to reference an “input_number” in the threshold for an automation so I can control it via the UI. This is the relevant condition field in the automation:

condition:
  - condition: device
    type: is_off
    device_id: b5bcb7ccadb6a4056652863b710fe094
    entity_id: switch.main_sump_pump
    domain: switch
    for:
      hours: 0
      minutes: {{input_number.sump_off_length | float}}
      seconds: 0

The “minutes: {{input_number.sump_off_length | float}}” is my attempt at imputing the input value into the automation. My understanding from the documentation is that this should work, but I keep getting

Message malformed: expected float for dictionary value @ data['for']['minutes']

Is this use case supported? Any thoughts on how to make this work? The goal is to set the input slider in the UI to, e.g., 10 and then to trigger this automation after the device is off for 10 minutes.

You’re using a Device Condition and it doesn’t support templates. Even if it did, your template contains syntax errors.

Use a State Condition.

condition:
  - condition: state
    entity_id: switch.main_sump_pump
    state: 'off'
    for:
      minutes: "{{ states('input_number.sump_off_length') | float(0) }}"
2 Likes

Thank you for taking the time to answer – I really appreciate it.

For posterity / future reference, how did you divine that distinction from the documentation? Why states() v.s. direct interpolation (seems arbitrary? {{input_number.sump_off_length | float}} resolves in the template debugger) and why the state condition type v.s. device. These appear to be equivalent just behave differently?

Typically, if the documentation doesn’t include a particular operation, or provide examples of performing it, then it cannot be done.

For example, nowhere in the documentation for Device Trigger does it explain that after creating it using the UI, you can then switch to YAML mode and add templates to any part of it. For Device Condition, there’s simply no documentation; create it via the UI and nothing more. Device Trigger, Device Condition, and Device Action were designed to be used exclusively via the UI (the visual automation/script editor) and not meant to be created/modified via YAML.

To get an entity’s state value, you can do this:

{{ states.input_number.example.state }}

or (preferably) this:

{{ states('input_number.example' }}

but you cannot do this:

{{ input_number.example }}

Review the States chapter of the documentation, especially this warning:

1 Like