Ubiquity Unifi Gateway Alert Notification

I have been trying to setup an automation that would tell me if I have any alerts from my unifi system.
Currently I have 7 (saved to test the automation). The automation I wrote does not seem to trigger.
It displays the messages as seen below. So I believe I have all the sensors setup correctly.

Here is my code for the automation.

- id: '1662560952541'
  alias: '++A-UNIFI Notify if Unifi Gateway Alert (24DEC2020)'
  description: UNIFI Notify if Unifi Gateway Alert
  initial_state: true
  trigger:
    - platform: template
      value_template: "{{ states(' sensor.unifi_gateway_alerts') > '0' }}"
  condition:
    - condition: template
      value_template: "{{ trigger.from_state.state != 'None' }}"
    - condition: template
      value_template: "{{ trigger.from_state.state != 'unavailable' }}"
    - condition: template
      value_template: "{{ trigger.from_state.state < trigger.to_state.state }}"
  action:
  - service: notify.telegram_carlton
    data_template:
      title: 'Unifi Gateway Alert'
      message: 'There are currently {{ trigger.to_state.state }} Unifi Gateway Alerts'
  - service: persistent_notification.create
    data_template:
      title: 'Unifi Gateway Alert'
      message: 'There are currently {{ trigger.to_state.state }} Unifi Gateway Alerts' 
  mode: single

What is wrong with the code!
Or what else should I check to see why it will not notify me.
Thanks

The trigger you have set up will only trigger one time when the state changes from 0 to above 0.

since the state is already above 0 the the trigger never transitions from false to true to trigger the automation.

And second but most importantly - all states are strings but you can’t compare a string to a string the way you are trying it.

when comparing strings with > or < it looks at the string length and compares that. So in your case 7 isn’t greater than 0, it’s equal to 0.

try this:

trigger:
  - platform: template
    value_template: "{{ states(' sensor.unifi_gateway_alerts') | int > 0 }}"

Thank you for the quick reply. I understand the thought process.
I replaced my line with the one you gave me.
Reloaded and ran it. Nothing happens.
If I take your line and put it into the template editor it says false, but in should it not state true as there are alerts.
Thanks

Sorry I had a typo.

I added an extra space in the state definition.

try this instead:

trigger:
  - platform: template
    value_template: "{{ states('sensor.unifi_gateway_alerts') | int > 0 }}"

Darn spacing and quotes!
Though I now get a true statement, it still will not send me a notice.
I will continue to work my way through it.
Thank you

I believe this condition suffers from the same flaw as your trigger:

- condition: template
  value_template: "{{ trigger.from_state.state < trigger.to_state.state }}"

the states are strings so you are comparing string lengths instead of what you think you are comparing.

try this instead:

- condition: template
  value_template: "{{ trigger.from_state.state | int < trigger.to_state.state | int }}"

Thank you, I will give it a try.