New Service with field for a value to pass to a script

I am trying to create a Service that will have a field to be filled out that will pass the value to another script. The use case is call a service in an automation that will ask for a temperature Setpoint value then pass that temperature to a script that will load it into a input_number Helper that is used in another service that sets the temperature and retries if thermostat did not update the Setpoint. I have tested the script by loading a value manually in the Helper and it all works fine.

I’m trying to have a single service call in an automation that takes the input for the helper as part of the call…only one call is needed.

This test version I used the normal call to Climate Set Temperature to simplify things. The modified version uses the Helper value to see if the Setpoint was set or not. So I need to store it in the Helper.

Here is what tried but doesn’t work.

Script -

alias: Set Helper and Therm with Retry
sequence:
  - service: input_number.set_value
    data:
      value: {{ value }}
    target:
      entity_id: input_number.lr_setpoint
  - service: climate.set_temperature
    data:
      temperature: "{{ states('input_number.mbr_setpoint') }}"
    target:
      entity_id: climate.living_room
mode: single

Service Call -

sequence:
  - service: script.Set Temp Modified
    data:
        value: 
    target:
      entity_id: script.set_helper_and_therm_with_retry

Thanks for any help in advance.

Your script-as-service call is a jumble of direct and indirect methods… I think you mean for it to be:

  - service: script.set_helper_and_therm_with_retry
    data:
      value: 

All templates must be surrounded by quotes… add them in the setting script:

- service: input_number.set_value
    data:
      value: "{{ value }}"

Thanks very much for the response. In your simple example above what I’m looking for is when I call this service in an automation, it would come up with a required field which is the value passed to the script. Just like the Climate Setpoint service requires the Setpoint value.

I know it doesn’t make sense to do this for this example, but I need to reuse the passed value in the more complicate script.

If I understand your goal correctly, you should add a fields configuration key to your script:

alias: Set Helper and Therm with Retry
fields:
  value:
    name: Temperature Value
    description: "The temperature to set the thermostat to"
    example: 17.0
    required: true
    selector:
      number:
        min: 0
        max: 30
        step: 0.1
sequence:
  - service: input_number.set_value
    data:
      value: "{{ value }}"
    target:
      entity_id: input_number.lr_setpoint
  - service: climate.set_temperature
    data:
      temperature: "{{ states('input_number.mbr_setpoint') }}"
    target:
      entity_id: climate.living_room
mode: single
1 Like

That was the ticket! Fields Configuration. I see that now in the //Script docs…totally missed that.

Many thanks!

1 Like