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.
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.
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 true → true. And as I said, the trigger only fires when the template goes false → true.
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.