When item is =! 'play' for X time do Y

Hi, I’m trying to achieve this :

When media_player.spotify is =! ‘play’ for X time do Y

Since I want a ‘is not’ I think I should use a template but then I can’t use the ‘for…’

If I’m not clear I want to do something like

- alias: tab_salon_auto
  trigger:
    platform: state
    entity_id: media_player.nvidiashield
    to: NOT 'play' #THIS IS HERE I NEED HELP
    for:
      hours: 1
      minutes: 10
      seconds: 5
  action:
    service: shell_command.stop

here ya go.

 - condition: template
    value_template: "{{ states.media_player.nvidiashield.attributes.state != 'play' }}"

Not true anymore. I added the for: option to the template trigger in 0.95. And in 0.96 I added template support so you can use a template in the for: option if you want. See: Automation Trigger - Home Assistant

I don’t use media_player’s, so not sure. Is the state ‘play’, or is it in an attribute that you see that? Assuming it is the state:

- alias: tab_salon_auto
  trigger:
    platform: template
    value_template: "{{ not is_state('media_player.nvidiashield', 'play') }}"
    for:
      hours: 1
      minutes: 10
      seconds: 5
  action:
    service: shell_command.stop
1 Like

Oh cool thank you !

I’m still in 0.95 ( I need to update but I saw that break something and I was not ready to fix it so I wait )

so you tell me as soon as I update to 0.96 it’s gonna work ?

The above will work in 0.95, which is when I added the for: option itself to the template trigger. In 0.96 I added the ability to use a template in the for: option. (I.e., in 0.96 you can use templates in the template trigger in both value_template: and for:.) Since you’re not using a template in the for: option you don’t need to wait for 0.96.

I did not know this! This makes you my hero!

1 Like