Counting Air Conditioner

I have a couple of Air Conditioners on my home, some of them control using Broadlink other their native Home Assistant Integration. I want to count how many are in a “cool” and/or “heat” state. Is there a way to count an identity if one of the states are on?

This it what i have con my .yaml

# AV On
- platform: template
  sensors:
    number_of_ac_on: 
#      unit_of_measurement: 'on'
      value_template: >
        {% set climate = [
          states.climate.clima_invitados,
          states.climate.clima_recamara,
          states.climate.clima_sala,
          states.climate.clima_sofia,
          ] %}
        {{ climate | selectattr('state','eq','cool') | list | count }}

Please use the new template sensor format for new sensors. e.g. configuration.yaml:

 template:
   - sensor:
       - name: Number of ac on
         state: >
           {% set climate = [
             states.climate.clima_invitados,
             states.climate.clima_recamara,
             states.climate.clima_sala,
             states.climate.clima_sofia,
             ] %}
           {{ climate | selectattr('state','eq','cool') | list | count }}

Tested as working.