Automation with service_template

service_template: "script.set_hvac_{{states('climate.4055_front')}}_temp"
data_template:
  hvac: climate.4055_front
  temp: >-
    {% if is_state('climate.4055_front','cool')
    %}{{states('input_number.cool_hold_temp')|int}} {% else
    %}{{states('input_number.heat_hold_temp')|int}} {% endif %}

Getting this error:
Failed to call service /null. expected str for dictionary value @ data[‘service’]. Got None

I feel like this was working previously… Currently on .118.5

try this?:

service: script.set_hvac_{{states('climate.4055_front')}}_temp
data:
  hvac: climate.4055_front
  temp: >-
    {% if is_state('climate.4055_front','cool')%}
      {{states('input_number.cool_hold_temp')|int}} 
    {% else %}
      {{states('input_number.heat_hold_temp')|int}}
    {% endif %}

TY for the quick response, unfortunately still the same error… Tried this as well:

service_template: >-
  script.set_hvac_{{states('climate.4055_front')}}_temp
data:
  hvac: climate.4055_front
  temp: >-
    {% if is_state('climate.4055_front','cool')%}
      {{states('input_number.cool_hold_temp')|int}} 
    {% else %}
      {{states('input_number.heat_hold_temp')|int}}
    {% endif %}

Hmmm…I’ve got one more thing to try (courtesy of petro in another thead):

service: script.set_hvac_{{states('climate.4055_front') ~ '\x00'}}_temp

I believe from his explanation that it should forcfe the template to return a string. Otherwise with the new template engine it will automatically return an int.

Hope it works.

I’m on my phone now but I’ll have to try that when I get back to my PC. Thank you!

I think I remember reading a prior thread a few weeks back that the templating engine was going to mess with some of these default return types… Maybe they need to add a | str suffix for this…

any word on whether my last suggestion worked?

Unfortunately I haven’t had time to try it. I went with a script to do it and just call that in the automation, which is working fortunately.

I haven’t seen this yet. Look interesting, will have to look into it to see how it works.

I think in this you could also make a template sensor for the climate set temp. States are still always strings right?

sensor:
  - platform: template
    sensors:
      hvac_set_temp:
        value_template: >
          {{ states('input_number.cool_hold_temp') is_state('climate.4055_front','cool') 
               else states('input_number.heat_hold_temp') }}

You can then use the state of that sensor value in the service call and it will be a string as expected by the component.

service_template: "script.set_hvac_{{states('climate.4055_front')}}_temp"
data_template:
  hvac: climate.4055_front
  temp: "{{ states('sensor.hvac_set_temp') }}"