Trigger based on sensor text content from and to

I want to set up some automations based on weather, however the weather sensor contains variable texted ie it might be light snow, heavy snow, lightly cloudy etc. I don’t have a full listing of the possible values so I would prefer to trigger on CHANGES in key words IE… goes from contains snow to does not contain snow, contains rain to not contains rain

What is the best way to structure this? Setting up a template for a trigger “snow” isn’t hard but it may also fire when going form light snow, to heavy snow. So I want the FROM and the TO to be part of the trigger and it is a partial text match.

Something like this:

mode: queued # important if using more than one trigger word.
triggers:
  - id: snow
    trigger: template # only triggers when snow first appears in text
    value_template: "{{ 'snow' in states('sensor.weather_text') }}"
  - id: no_snow
    trigger: template # only triggers when snow first disappears from text
    value_template: "{{ 'snow' not in states('sensor.weather_text') }}"
actions:
  - choose:
      - conditions:
          - condition: template
            value_template: "{{ trigger.id == 'snow' }}"
        sequence:
          - action: # your 'to snow' actions here
      - conditions:
          - condition: template
            value_template: "{{ trigger.id == 'no_snow' }}"
        sequence:
          - action: # your 'from snow' actions here

The templates only trigger when going from false to true. So they do take this into account:

Add more triggers and choose actions for your other words, ‘rain’, ‘cloudy’ etc…

You must use the queued (or parallel) automation mode if adding triggers for multiple words. Just in case more than one looked for word changes at a time.

Your logic would fire every time the snow changed intensity which I am trying to avoid.

IE your logic would trigger with “light snow”, “heavy snow”, “lights snow” as it would be TO a state with “snow” in the name.

I ONLY want to trigger once when it starts snowing or when it ends, IE “clear sunny” is the next state for example or it goes from clear to snowing.

No it would not. Those examples all contain the word “snow”. If the first template trigger has already fired, the first time it changed to say, “light snow”, it would not fire again when it changed to “heavy snow”. In that case the template goes truetrue. And as I said, the trigger only fires when the template goes falsetrue.

The trigger only fires the first time the word “snow” appears. And the other trigger only fires when the word “snow” becomes absent from the text.

Ill give it a short, will be hours or days before I know how well it is working it wasn’t clear to me that the templates worked that way.

You may need to test for snow, and if that is valid, check for the other text and then take the appropriate action. Multilevel state tables.