Compare two attribute values syntax correct?

Is this the correct way to compare two attribute values ?
The input.boolean does not change

- id: '1587296168639'
  alias: Welke container
    platform: template
    value_template: "{{ state_attr('sensor.afvalinfo_gft','days_until_collection_date') <  state_attr('sensor.afvalinfo_restafval','days_until_collection_date')  }}"
   - service: input_boolean.turn_off
     entity_id: input_boolean.grijze_container

No. You are comparing strings (words) you need to convert them to numbers:

value_template: "{{ state_attr('sensor.afvalinfo_gft','days_until_collection_date')|int <  state_attr('sensor.afvalinfo_restafval','days_until_collection_date')|int  }}"

It depends on how those attributes are defined. Only a State Object’s state field must be a string. Attributes can be any type. I searched for that attribute name but it didn’t come up, so it must be some sort of custom integration. But, yeah, if they are strings, then they need to be converted to numbers first.

EDIT: If it’s not clear if the attribute is a string or number, the following can be put into the Template Editor:

{{ state_attr('sensor.afvalinfo_gft','days_until_collection_date') is number }}

Turned out that the indent of the called service was not correct. Configuation check did not notice.
Thank for your help. I learned more about using the template editor.

What you posted was correct:

   - service: input_boolean.turn_off
     entity_id: input_boolean.grijze_container

then I must have changed it accidentally when I copied pnbruckner’s template, because that did not work at first.
When I changed indent it worked, so then pnbruckner’s template was the solution appearanty.

Just to be clear, my template was only a way to check if the attribute was a string or a number (e.g., float or int.) I did not actually suggest a template for use directly in your automation.

I agree with @tom_l, the indentation of the automation in the original post was technically ok, although unusual.

It’s still not clear what you did to make it work for you, but since it does, we’re happy! :tada: