Conditions in Hassio for Media Player

Can someone help me figure out why this is not working correctly. This automation triggers and starts playing music, which is good. The issue is, the condition should detect if the music is already playing. If it is, I don’t want it to start the music over again. It’s like the automation is not looking at the conditions. The conditions should stop the automation from triggering if the states of the media devices are not correct.

- id: '1536431827329'
  alias: Back Slidding Door Trigger Music
  trigger:
  - entity_id: sensor.elkm1_zone_008
    from: Normal
    platform: state
    to: Violated
  condition: 
    condition: or
    conditions:
      - condition: state
        entity_id: media_player.googlehome3641
        state: 'off'
      - condition: state
        entity_id: media_player.googlehome3641
        state: 'idle'
    condition: and
    conditions:
      - after: '6:00'
        before: '23:00'
        condition: time
  action:
  - data:
      entity_id: media_player.googlehome3641
      media_content_id: https://www.youtube.com/watch?v=77ZozI0rw7w
      media_content_type: video/youtube
    service: media_extractor.play_media

Are you sure this is working? I would have thought it would cause a config error and not work at all. (because you had two things under condition but you didn’t use dashes to make them list items.)

In any case, I think what you want is:

  condition: 
    - condition: or
      conditions:
        - condition: state
          entity_id: media_player.googlehome3641
          state: 'off'
        - condition: state
          entity_id: media_player.googlehome3641
          state: 'idle'
    - after: '6:00'
      before: '23:00'
      condition: time

By default conditions listed under condition are anded together. So this will allow the actions to run only if time is between 06:00 and 23:00, and the state of the player is either ‘off’ or ‘idle’.

It does trigger. So I started this in the GUI. Then I edited it in the automations file. if I remove the dashes (which the GUI put in) will it work then you think?

Sorry, I don’t understand your question. Remove what dashes from where?

As far as I understand it, the condition section in your OP was wrong. You had two items under it, but they did not have dashes. Also, you had “condition: and”, but only had one condition under it. Although this second problem isn’t really “wrong”, it’s just unnecessary. You only had one condition under “and”, so there was nothing to “and” it with.

If you change the whole condition section to what I showed you, it should work for you.

Perfect. Thanks. Re-reading what you said and it makes sense now. Ill give it a try. Thank you!

What you posted worked!

1 Like