Help understanding Conditions templates

So I have an automation who’s job is to tell me when the washing machine has finished.

Works fine, other than that every time i reload my HA server or every time you twist the program selector knob on the washing machine, the automation is triggered.

I am trying to write a condition set so that if the device state WAS “unknown” or “none” then the automation wont trigger.

Here’s where i’m at

alias: Washing Machine finished
description: ""
trigger:
  - type: duration
    platform: device
    device_id: c4876c80cf0ad0a881de235925b0b1a4
    entity_id: fd67a84d25ee14a0d3388a1650acd1b1
    domain: sensor
    below: 1
condition:
  - condition: template
    value_template: "{{ (trigger.from_state.state) not in ['unknown', 'unavailable', 'None'] }}"
action:
  - service: media_player.volume_set
    data:
      volume_level: 0.2
    target:
      entity_id: media_player.dining_room
  - service: media_player.play_media
    target:
      entity_id: media_player.dining_room
    data:
      media_content_id: >-
        media-source://tts/tts.google_en_com?message=The+washing+machine+has+finished&language=en
      media_content_type: provider
    metadata:
      title: The washing machine has finished
      thumbnail: https://brands.home-assistant.io/_/tts/logo.png
      media_class: app
      children_media_class: null
      navigateIds:
        - {}
        - media_content_type: app
          media_content_id: media-source://tts
        - media_content_type: provider
          media_content_id: >-
            media-source://tts/tts.google_en_com?message=The+washing+machine+has+finished&language=en
mode: single

While their basic setup may be “easy” for beginners to understand, the quirks and limitations of Device triggers can drive you crazy as soon as you need to do anything beyond the basics.

What is your question about template conditions?

Ok… if the trigger [remaining duration] state of the washer changes to a numeric value below “1” then play the TTS saying that the washing machine has finished.
What’s happening though is that if i restart HA, the automation says “hey, that value is 0… i’m going to do my thing…” so I need help with figuring out how to phrase the conditions so that if the from_state was one of those in the list, the automation wouldnt trigger.

There isn’t anything wrong with your condition. You might be able to include additional conditions to guard against the cases you’ve described. For example, if the program selector value is available in HA, your condition could be that it’s state has been stable for at least X amount of time.

Thanks guys.
The problem was actually with TTS - I added a SSL cert to HA and had made a mistake on the Internal URL.
Of all the things.
Thanks everyone for replying so quickly.

Do look at the link that tells you how to avoid device id’s though, the numerical state trigger is way better and can do away with the template condition altogether. Much simpler and much more future proof, as device triggers tend to break when you change things.

Guys that link about avoiding Device IDs is GREAT.

Thanks for sharing!!!

alias: Washing Machine finished
description: ""
trigger:
  - platform: numeric_state
    entity_id: sensor.washer_duration
    below: "1"
condition:
  - condition: template
    value_template: "{{ (trigger.from_state.state) not in ['unknown', 'unavailable', 'None'] }}"

SOOOOO much easier and clearer !!!