Error executing script. Invalid data for call_service at pos 2: Value is not a number for dictionary value @ data['value']

I’m trying to use a utility meter calibration with a value that I compute from a script, and I am getting hung up on having my action trigger the script.

Here’s the automation I trigger by a button press on my dashboard:

alias: calibrate_soc
description: ""
triggers: []
conditions: []
actions:
  - action: script.soc_calibration_script
    metadata: {}
    data: {}
    response_variable: soc_result
  - action: utility_meter.calibrate
    metadata: {}
    data:
      value: soc_result.depletion
    target:
      entity_id: sensor.battery_utility_meter_peak
mode: single

And here is the script

alias: soc_calibration_script
variables:
  new_depletion_value: |
    {% set SOCtarg = states('input_text.soc_calibrate_text') | float(100) %}
    {% set new_depletion = ((SOCtarg/float(100) - float(1))*float(29)) |float(0) %}
    {{ {'value': (new_depletion|float(0)) } }}
sequence:
  - stop: end
    response_variable: new_depletion_value
description: ""
icon: mdi:car-battery

I can’t seem to figure out what it’s talking about when it mentions “value” and position 2.

Here’s the log snippet for what’s happening when I press my button.

2025-01-11 12:05:49.140 INFO (MainThread) [homeassistant.components.automation.calibrate_soc] calibrate_soc: Running automation actions
2025-01-11 12:05:49.141 INFO (MainThread) [homeassistant.components.automation.calibrate_soc] calibrate_soc: Executing step call service
2025-01-11 12:05:49.143 INFO (MainThread) [homeassistant.components.script.soc_calibration_script] soc_calibration_script: Running script sequence
2025-01-11 12:05:49.143 INFO (MainThread) [homeassistant.components.script.soc_calibration_script] soc_calibration_script: Stop script sequence: end
2025-01-11 12:05:49.149 INFO (MainThread) [homeassistant.components.automation.calibrate_soc] calibrate_soc: Executing step call service
2025-01-11 12:05:49.150 ERROR (MainThread) [homeassistant.components.automation.calibrate_soc] calibrate_soc: Error executing script. Invalid data for call_service at pos 2: Value is not a number for dictionary value @ data['value']
2025-01-11 12:05:49.151 ERROR (MainThread) [homeassistant.components.automation.calibrate_soc] Error while executing automation automation.calibrate_soc: Value is not a number for dictionary value @ data['value']

Could anyone point me in the right direction for resolving this?

Thanks!

socresult.depletion is just a plain string unless you put it in a template where it will be interpreted as a variable:

  - action: utility_meter.calibrate
    metadata: {}
    data:
      value: "{{ soc_result.depletion }}"
    target:
      entity_id: sensor.battery_utility_meter_peak
1 Like

Oh, and based on your script, I think it should be

"{{ soc_result.value }}"
1 Like

Thank you!

I’m still pretty new at both yaml and jinja. And home assistant for that matter.

This community is great