How can you use an input_number with a time_pattern trigger?

Hello,

I can’t seem to figure out how to utilize an input_number with a time_pattern trigger in my automation.yaml.

Here’s my current yaml:

- alias: Alarm if grey water is fatal
  trigger:
    platform: time_pattern
    seconds: '/60'
  condition:
    - condition: template
      value_template: "{{ states('sensor.grey_water') > states('input_number.grey_water_fatal_level') }}"
  action:
    - service: media_player.play_media
      data:
        entity_id: all
        media_content_id: 'http://192.168.1.2:8123/local/sounds/grey-tank-level-fatal.mp3'
        media_content_type: 'music'

I would like the seconds configurable, but I do understand how I can put the value as a template. I tried:

- alias: Alarm if grey water is fatal
  trigger:
    platform: time_pattern
    seconds: "/{{ states('input_number.alarm_frequency') }}"
  condition:
    - condition: template
      value_template: "{{ states('sensor.grey_water') > states('input_number.grey_water_fatal_level') }}"
  action:
    - service: media_player.play_media
      data:
        entity_id: all
        media_content_id: 'http://192.168.1.2:8123/local/sounds/grey-tank-level-fatal.mp3'
        media_content_type: 'music'

However, I get a ValueError: invalid literal for int() with base 10 when I try to use this automation. Any help is appreciated.

You can not template that option.

Unless the documentation specifically states that an option supports templates, it doesn’t.

Your alternative would be to use a platform: template trigger.

I recently suggested how to do this to someone else:

Let me know if you try it and if it works for you. (You’ll see my original suggestion didn’t work in all cases, but I provided a new suggestion which I actually tried :sweat_smile: and it seems to do the trick.)