Wait for Trigger Fails Even When True

This keeps happening:

391.209 is very clearly higher than 0.001, and yet the automation just stops here. Almost, but not quite, every time.

actions:
  - if:
      - condition: or
        conditions:
          - condition: template
            value_template: '{{ trigger.json.Item.MediaStreams[0].ColorPrimaries == ''bt2020'' }}'
          - condition: template
            value_template: '{{ trigger.json.Item.Video3DFormat == "MVC" }}'
    then:
      - action: media_player.media_stop
        metadata: {}
        data: {}
        target:
          entity_id: media_player.emby_shield_standard
      - device_id: d7d7547ded358a9a1b303741e188b6a9
        domain: select
        entity_id: 0a5af3b6dddfddb6def5c21589ee014e
        type: select_option
        option: UGOOS
        enabled: true
    else:
      - wait_for_trigger:
          - trigger: numeric_state
            entity_id:
              - media_player.emby_shield_standard
            attribute: media_position
            above: 0.001
        continue_on_timeout: false
        enabled: true
      - if:
          - condition: template
            value_template: >-
              {{ trigger.json.Item.MediaStreams[1].DisplayTitle is
              search('DTS:X|Atmos') }}
        then:
          - action: denonavr.get_command
            metadata: {}
            data:
              command: /goform/formiPhoneAppDirect.xml?SPPR2<CR>
            target:
              entity_id: media_player.denon_avc_x3800h
      - action: light.turn_off
        metadata: {}
        data: {}
        target:
          entity_id: light.theater
      - action: input_boolean.turn_on
        metadata: {}
        data: {}
        target:
          entity_id: input_boolean.ignore_light_commands
      - action: media_player.media_pause
        metadata: {}
        data: {}
        target:
          entity_id: media_player.emby_shield_standard
      - delay:
          hours: 0
          minutes: 0
          seconds: 7
          milliseconds: 0
      - action: media_player.media_play
        metadata: {}
        data: {}
        enabled: true
        target:
          entity_id: media_player.emby_shield_standard
      - delay:
          hours: 0
          minutes: 0
          seconds: 0
          milliseconds: 500
      - action: input_boolean.turn_off
        metadata: {}
        data: {}
        target:
          entity_id: input_boolean.ignore_light_commands
      - action: input_select.select_option
        metadata: {}
        data:
          option: '{{ "AR " ~ trigger.json.PlaybackInfo.MediaSource.Path[-8:-4] }}'
        target:
          entity_id: input_select.aspect_ratio

If the state is above this value already then the wait for trigger won’t trigger.
It has to see a change from below to above. Just like all other triggers.

1 Like

Then why does it sometimes work?

How should I be going about this? I’m trying to make sure the media is actually loaded into the player before firing the pause command, because if it fires before the media is playing it has no effect.

A bit clunky but it works.

If above 1 
[Do nothing]
Else
Wait for trigger above 1
End if
Pause.

Isn’t that just going to do what I’m already doing, where the pause fails to fire if you’re resuming an in-progress media item?

A wait template will do what you want, because it will proceed when true. A wait trigger will not because it waits for a trigger to go off, which (as explained) won’t happen if the threshold isn’t crossed.

Could you explain what you mean by a “wait template”?

No.
It will do the opposite.
It will work

Ah, you meant for me to add that block above the rest of it, not to put all the other actions in the “else” bit, right? That does indeed seem to work.

Actually no, it doesn’t work. I assume Emby is reporting the playback position before playback actually begins, meaning the pause command is firing too early.

So if it’s above 0.001, I need to wait for it to increase from its initial value. Not sure how to do that.

That is why I said above 1, not above a fraction of a second.
One second should not matter too much. Or perhaps it does.
I don’ know, but triggering on such a small fraction will probably lead to issues.

If Emby reports the playback position before the file loads into the media player, it doesn’t matte what number I use as the trigger, it will never work.

But the media position updates at some point?

In the code you posted, if the position is higher than 1 it never checks for an increase.

It won’t do that if it’s above 0.001 either

But I want to wait for an increase, that’s the whole point here.

That has never been clear.
You have not once explained what you want.
Set the wait for trigger to a state trigger and leave both to and from empty

I said it here: