Allow Templates in for: Condition

I’ve been slowly converting my system to use helper entities to replace hardcoded values in scripts and automations allowing easier modification.

However when trying to use a template to return the state of an input_number in a condition the following error is encountered. Using the same template for the trigger: section works fine.

Error

Invalid config for [automation]: expected float for dictionary value @ data['action'][0]['default'][0]['for']['minutes']. Got None. (See ?, line ?).

Related Configuration

action:
  - choose:
    - alias: Auto Light Entry
      conditions:
        - condition: state
          entity_id: input_boolean.auto_light_entry
          state: "on"

      sequence:
        - service: light.turn_on
          target:
            entity_id: light.entry

    default:
      - condition: state
        entity_id: binary_sensor.entry
        state: "off"
        for:
          minutes: "{{states('input_number.auto_light_timeout')}}"

      - service: light.turn_off
        target:
          entity_id: light.entry

If there are any workarounds or something I’ve overlooked, please let me know. Otherwise this would be a welcome addition to Home Assistant.

Not sure what you’re after, but is it this you’re looking for:

    default:
      - condition: state
        entity_id: binary_sensor.entry
        state: "off"
        for:
          minutes: "{{ states('input_number.auto_light_timeout') | float }}"

According to the documentation

states('device_tracker.paulus') will return the state string (not the object) of the given entity or unknown if it doesn’t exist.

you need to type cast / convert that string to a float, that’s what the filter does. Take a look here:

Another possibility would be to use the state object directly, like states.input_number.auto_light_timeout. That should return a float already, but should be avoided.

This is not a syntax problem. The for: clause does not allow templates at the moment.
I’ve been missing this as well.

1 Like

Vote for this