Using old_state in automation condition with media player content type

Hi all

I’m wondering if someone could point me in the right direction. I want to dim the lights when kodi starts playing but only when the content type is “movie” and the sun is below the horizon. I have created an automation that does this as you can see here (I’m using an input_boolean just for testing as I’ve not configured the scene yet):

automation 2:
alias: Movie time on
trigger:
platform: state
entity_id: media_player.kodi
to: ‘playing’
condition:
condition: and
conditions:
- condition: template
value_template: ‘{{ states.media_player.kodi.attributes.media_content_type == “movie” }}’
- condition: state
entity_id: sun.sun
state: ‘below_horizon’
- condition: state
entity_id: input_boolean.film_time
state: ‘off’
action:
service: input_boolean.turn_on
entity_id: input_boolean.film_time

I wan’t a rule that will go back to a normal scene when the movie stops. I’m struggling with this, because when I stop a movie, its state isn’t “stopped” it returns to “idle” and there is no media_content_type attribute in the state of idle.

So I wan’t to be able to access the media_content_type of the old_state, and check in the condition that this was “movie” to avoid the normal scene to be enabled when stopping other media content types. I can see in the logs that this information is there, but I don’t know if you can, or how to access it?

Does anyone have any ideas how you can achieve this?

Thanks
Mat

You could have an input boolean that you can use as a limiting condition in your other automation that will only be true when the media content type is a Movie.

@Robban, could you please provide an example on how to set and use the input in between different automations?

I’ve just made it work. I hope this could be useful to anyone.

# Flag for Kodi video playback
input_boolean:
  video_playback:
    name: Tells whether Kodi is playing a video
    initial: off
    icon: mdi:movie

# Automation
automation:
  - alias: "Kodi starts playing a video"
    trigger:
      platform: state
      entity_id: media_player.kodi
      to: 'playing'
      from: 'paused'
    condition:
      condition: and
      conditions:
        - condition: state
          entity_id: sun.sun
          state: 'below_horizon'
        - condition: template
          value_template: '{{ states.media_player.kodi.attributes.media_content_type == "video" }}'
    action:
      - service: light.turn_off
        entity_id: light.sonoff1
      - service: input_boolean.turn_on
        data:
          entity_id: input_boolean.video_playback

  - alias: "Kodi pauses/stops playing a video"
    trigger:
      platform: state
      entity_id: media_player.kodi
      from: 'playing'
    condition:
      condition: and
      conditions:
        - condition: state
          entity_id: sun.sun
          state: 'below_horizon'
        - condition: state
          entity_id: input_boolean.video_playback
          state: 'on'
    action:
      - service: light.turn_on
        entity_id: light.sonoff1
      - service: input_boolean.turn_off
        data:
          entity_id: input_boolean.video_playback
2 Likes