Automation doesn't fire automatically / Fan control / service_template

Hi,

I’ve been trying to run bathroom fan automatically, based on moisture difference, via automation. This works manually but it doesn’t fire automatically. Why?

alias: fan_control
description: ''
trigger:
  - platform: state
    entity_id: sensor.simap_s2_h
condition: []
action:
  - entity_id: switch.sonoff_1000cf7330
    service_template: >-
      {% if state_attr('switch.sonoff_1000cf7330', 'humidity') | float > 
      states('sensor.simap_s2_h') | float %} switch.turn_on {% else %}
      switch.turn_off {% endif %}
mode: single
initial_state: 'on'

It works when I fire this manually, but it doesn’t work automatically. I’ve waited several hours and both sensors data updates multiple times.