Automation Message malformed: template value should be a string for dictionary value @ data[‘action’][0][‘data’]

Hi there,

I’m struggeling with some automation code and do not know how to fix it. Can anyone of you give me a quick hint?
I was creating an automation with a code part and got message, that value should be a string.

service: input_number.set_value
metadata: {}
data:
  value: >-
    {{ states('input_number.amortisation') | float +
    (states('input_number.einspeisevergutung') | float *
    states('sensor.solaranlage_wechselrichter_export_energy_today') | float) + 
    (state_attr('input_number.strompreis', 'avg_price') | float *
    (states('sensor.solaranlage_wechselrichter_solar_generation_today') | float
    - states('.solaranlage_wechselrichter_export_energy_today') | float) }}
target:
  entity_id: input_number.amortisation

Thank you in advance

I’m counting more opening braces then I do closing ones. Also, the domain (sensor, input_number, …) is missing in the above.

Something that may or may not be wrong (because it is below a multiline indicator), but is at least confusing: a minus at the start of a line has a meaning in yaml, so personally I’d avoid that in a template like this.

It is always best to test the template in the developer tools. Build it step by step if a big one fails.

And when all the above is fixed, then you need to enclose the full template in () and add | string to make it a string

I’m not so sure that is needed, especially for setting an input number.

Neither am I, but the error message says so…

Probably for different reasons that can ot be cured by a cast.