Problem with data types in script fields

Hi,
I’m trying to call a script, from an automation, that runs the sprinkler stations controlled by OpenSprinkler.
Here is my automation:

- id: '1765084247067'
  alias: 00-sprinkler
  description: ''
  triggers:
  - trigger: time
    at: input_datetime.sprinkler_start_time
  conditions:
  - condition: state
    entity_id: input_boolean.sprinklers_automation_cutoff
    state:
    - 'on'
  actions:
  - action: script.00_sprinkler
    metadata: {}
    data:
      stationA: switch.s01_station_enabled
      time_to_run: '{{ input_number.sprinkler_staion01_time }}'
  mode: single

The script is as follows:

00_sprinkler:
  fields:
    stationA:
      selector:
        text:
      name: stationA
      description: First sprinkler station
      required: true
    time_to_run:
      selector:
        text:
      description: Time in seconds for the station to run
      name: time
      required: true
  sequence:
  - action: opensprinkler.run_station
    metadata: {}
    data:
      entity_id: '{{ stationA }}'
      run_seconds: '{{ time }}'
  alias: 'Script: Run Sprinkler'
  description: 'Script: Run Sprinklers'

And I keep getting this error when the automation is triggered:

Executed: December 6, 2025 at 9:28:00 PM
Error: Error rendering data template: ValueError: Template error: int got invalid input 'unknown' when rendering template '{{ states('time') | int }}' but no default was specified

If anyone can spot any error or flaw in the code above, please let me know.
Thanks.

In the automation you were using {{ input_number.sprinkler_staion01_time }} which the template engine interprets as a request for the property sprinkler_staion01_time of a variable object input_number… which you haven’t defined. If you want the state of the entity input_number.sprinkler_staion01_time, you need to use the states() function:

- id: '1765084247067'
  alias: 00-sprinkler
  description: ''
  triggers:
  - trigger: time
    at: input_datetime.sprinkler_start_time
  conditions:
  - condition: state
    entity_id: input_boolean.sprinklers_automation_cutoff
    state:
    - 'on'
  actions:
  - action: script.00_sprinkler
    metadata: {}
    data:
      stationA: switch.s01_station_enabled
      time_to_run: '{{ states("input_number.sprinkler_staion01_time") }}'
  mode: single

In this one you had the action using time, which is the name of the field, instead of time_to_run which is the variable ID:

00_sprinkler:
  fields:
    stationA:
      selector:
        text:
      name: stationA
      description: First sprinkler station
      required: true
    time_to_run:
      selector:
        text:
      description: Time in seconds for the station to run
      name: time
      required: true
  sequence:
  - action: opensprinkler.run_station
    metadata: {}
    data:
      entity_id: '{{ stationA }}'
      run_seconds: '{{ time_to_run | int(0) }}'
  alias: 'Script: Run Sprinkler'
  description: 'Script: Run Sprinklers'

FWIW, starting an object ID with numbers ( like script.00_sprinkler) should be avoided since it can cause some annoying issues down the line…

1 Like

@Didgeridrew thanks for your suggestions, the code is now working :sunglasses:

PS: I only use “00” prefix for the stuff under testing so that it shows up on top in the summary view.

@Didgeridrew if I want to input time for running sprinklers in minutes instead of seconds, how would it change the code “run_seconds: ‘{{ time | int(0) }}’”?

I tried few versions like “run_seconds: ‘{{ (time | int(0)) * 60 }}’” but the script always keeps giving an error.
Thanks!

You still need to use time_to_run, not time

"{{ (time_to_run | int(0)) * 60 }}"

1 Like

My bad, I was frantically plugging in different combinations and did not realize that I reverted to my original error…thanks for your patience!!