Help with automation to turn off lights depending on media type

Hi,

I’m trying to set up that turns off a certain switch when media_player.Emby_… starts playing after 7pm if it’s playing anything but music.

So far i’ve got it working to turn off the switch when emby starts playing any type of media.

I;m basically stuck on one of the conditions. This is what i’ve got so far:

- id: '1602144843617'
  alias: Turn off Living room spots when Palpatine Emby starts playing after 7pm
  description: ''
  trigger:
  - platform: state
    entity_id: media_player.emby_kodi_stormtrooper_2
    from: idle
    to: playing
  - platform: state
    entity_id: media_player.emby_chrome
    from: idle
    to: playing
  condition:
  - condition: time
    after: '19:00'
    before: 05:00
  action:
  - type: turn_off
    device_id: 38da31f5082811eb804c51ca716b67a4
    entity_id: switch.living_room_spots
    domain: switch
  mode: single

This automation has 2 triggers. both media players. When they start playing after 7pm they turn off a certain switch. Can somebody help me turning this into an automation that only does this only when the content played is not music

I do exactly this with a Rasplex box I have in the lounge room.
If I start a movie the lounge lamp turns off.
If I start anything that isn’t a movie, nothing.

You need to know what your options are.
Start playing something on your media player then go to Home Assistant.
Under the Developer / States tab, select your media player and look for somthing you can use as a condition.


In my case, my media player entity has an attribute
media_content_type:

and my condition

  condition:
  - condition: template
    value_template: '{{is_state_attr("media_player.plex_rasplex_2","media_content_type","movie")}}'
1 Like

Thanks for that!
I’m very new to this, is there a way to turn that template into the opposite, so it doesn’t do it when movies play? That’s what i’m after, i need the light to turn off when movies or tv series play, but not music. so the easiest way seems to just exclude music

ok never mind!
I just found out this will do the trick

{{is_state_attr("media_player.emby_chrome","media_content_type","tvshow")
or
is_state_attr("media_player.emby_chrome","media_content_type","movie")}}

At least it gives the correct result in the template editor, so it should also work in the automation

There is ! Unfortunately I had to go digging for it as it’s not intuitive relative to the template we already have.
You will need

{{ state_attr("media_player.emby_chrome","media_content_type") != "music" }}

1 Like

I think you’ll need to quote the 05:00 too.

Also there is no time within the period from midnight to midnight that is both after 7pm and before 5am. forget that bit!

Thanks for all the input!

I’ve got it working now.

1 Like