announcement: Error executing script. Unexpected error for call_service at pos 9: Error rendering data template: TypeError: object of type 'float' has no len()
Based on the error message, it’s now assuming the type, of the variable being passed, is float (not string). If the value’s type is float or int then you can’t use it with the length filter.
Try this:
test_1:
sequence:
- service: input_number.set_value
data:
entity_id: >
{{ 'input_number.announcement_quiet_time_volume' if quiet_time_volume is defined and quiet_time_volume != none else 'none' }}
value: >
{{ quiet_time_volume if quiet_time_volume is defined and quiet_time_volume != none else 0 }}
It checks if quiet_time_volume is defined. For example if you call the script without supplying the quiet_time_volume variable.
It also checks if the value of quiet_time_volume is not none. That would be the case where you supply the variable but assign it no value (quiet_time_volume: )
Unless you’re using an old version of Home Assistant, it’s no longer necessary to use data_template when one of the options is templated. It has been deprecated and you can simply use data in all cases (with or without templated options).