Pass the template value as a python integer

Hey,

I’m trying to make a script that calls a service which needs an integer value Id as extra data field.

Now if I trigger the following script it works:

script:
  landroid_start:
    alias: Landroid Start
    sequence:
      service: landroid_cloud.start
      data:
        id: 12345

Next I want to template the Id value but I can’t get it to work because with every attempt I try to template the value, I pass the correct value but it arrives at the service as a Python String type instead of a Python Integer value… ?

I tried the following examples:

  landroid_start:
    alias: Landroid Start
    sequence:
      service: landroid_cloud.start
      data_template:
        id: "{{ state_attr('sensor.landroid_vanachter_status','id') }}"
        
  landroid_start:
    alias: Landroid Start
    sequence:
      service: landroid_cloud.start
      data_template:
        id: "{{ state_attr('sensor.landroid_vanachter_status','id') | int }}"


  landroid_start:
    alias: Landroid Start
    sequence:
      service: landroid_cloud.start
      data_template:
        id: "{{ state_attr('sensor.landroid_vanachter_status','id') | int + 0}}"

Is there a way to make the templated value to be passed as a Python Integer value instead of a String?
The service compares the id to a integer and ends up refusing to match the id: “12345” == 12345

No, there’s no way to get a template to return anything but a string.

The problem is in the landroid_cloud.start service. It needs to use a schema that converts the id input to an int. This does not seem to be a standard integration, so I assume it is custom, yes? Where did you get it from?

Its a project from HACS

Yep, sure enough, when registering the start service it does not specify a schema. You should create an issue on that repo.

Thanks for the quick and useful replies!
Will created an issue on that repo

1 Like