Automation based on thermostat temparature

Hello,
I have created an automation, but it is not working as I wish.
My request:
If the room temperature (based on thermostat) is higher then a max value then close the covers but only if the time is between 13:00 and 19:00 and the outer tempeature is higher then a max value.
I have created the following automation:

- id: '15'
  alias: Redőny napsütésben
  description: ''
  trigger:
  - platform: template
    value_template: '{{ states.climate.termosztat.attributes.current_temperature >
      states.climate.termosztat.attributes.max_temp }}'
  condition:
  - after: '13:00:00'
    before: '19:00:00'
    condition: time
  - condition: template
    value_template: '{{ states.weather.otthon.attributes.temperature > states.climate.termosztat.attributes.max_temp
      }}'
  action:
  - data: {}
    entity_id: cover.terass_cover1
    service: cover.close_cover
  - data: {}
    entity_id: cover.terass_cover2
    service: cover.close_cover

It not working correctly: I suppose it can work only if the inner temparature become higher than the max value between 13:00 and 19:00, and if in that moment the outer temperature is already higher than the max value.
For example it works correctly if max temp is 24C and at 14:00 the outer temperature is 25C and the inner temperature become from 23,5C to 24C.
But it not works if at 12:59 the inner temperature is 25C and the outer temperature is already 26C. In this case the action does not triggers at 13:00.

How do I have to modify the automation to work correctly?

Thanks for your support!
BR:
P!

I don’t know if this is the complete solution, but the automation will only trigger based on the entities in the trigger section. If you want it to check the trigger template based on other entities (the ones in the condition), you need to list them. I tend to list all involved entities anyway, just in case the auto-detection doesn’t work:

trigger:
  - platform: template
    entity_id:
      - weather.otthon
      - climate.termosztat
    value_template: …

Also it would be wise to ensure your attributes (and definitely states) are numbers, not strings when making mathematical comparisons. e.g. this

    value_template: '{{ states.climate.termosztat.attributes.current_temperature >
      states.climate.termosztat.attributes.max_temp }}'

Should be:

    value_template: "{{ state_attr('climate.termosztat', 'current_temperature')|float >
      state_attr('climate.termosztat', 'max_temp')|float }}"

Also using the state_attr() format rather than state.xxx.attribute format will prevent errors. See the warning here: https://www.home-assistant.io/docs/configuration/templating/#states

I have already checked it in development tools/template editor.

Which does not invalidate my second point. Read and heed the warning.

I will try this but really not sure this is the problem because sometimes the automation works.

Thanks, it seems you were right!

Just because the output looks the same doesn’t mean it is.
so ‘123’ looks like 123 in the front end
but ‘123’ (string) does not equal 123 (number)
If you mess with strings you can get unexpected results like ‘9’ > ‘123’ == True

If you look at Tom’s activity on the site you will see that he has spent 64 DAYS reading this stuff (I’m amazed he keeps it all straight in his head as what is true today could have been complete rubbish 3 releases ago ) He’s jumped through a lot of hoops !