Hi,

wanted to share my recent automation. What it does: Whenever you want to watch a movie and use chromecast, it looks up the title on IMDB and gets the rating. Then announces the rating via tts.

Sorry for bad formatting - I don’t get this to work here

  • Install pyscript from hacs
  • Create a pyscript folder in your config
  • In your pyscript folder create a file “requirements.txt”
  • Write “cinemagoer” and save
  • Create a file “movieinfo.py
  • Add the following python code
from imdb import Cinemagoer

import sys

import requests

@service
def multimedia_getmovieinfos(mytitle=None):
    """yaml
    name: get imdb movie infos
    description: obtain infos from imdb for a movie, stored in multiple input_text sensors
    fields:
        mytitle:
            description: provide the movie title
            example: Rollo Aller
            required: true
"""

    ia = Cinemagoer()
    search = task.executor(ia.search_movie, mytitle)

    for i in range(len(search)):
      if i == 0:
        id = search[i].movieID
        info = task.executor(ia.get_movie, id)
        genre_list = info.data['genres']
        service.call("input_text", "set_value", blocking=True, limit=10, entity_id="input_text.multimedia_current_movie_title", value=search[i]['title'] + ' ('+str(info.data['year'])+')')
        
        service.call("input_text", "set_value", blocking=True, limit=10, entity_id="input_text.multimedia_current_movie_genre", value=','.join(map(str, genre_list)).replace(',', ', '))

        service.call("input_text", "set_value", blocking=True, limit=10, entity_id="input_text.multimedia_current_movie_rating", value=( str(round(info.data['rating'], 2))))
        
        if 'plot outline' in info.data:
            service.call("input_text", "set_value", blocking=True, limit=10, entity_id="input_text.multimedia_current_movie_plot", value=info.data['plot outline'][:255])
        else:
            service.call("input_text", "set_value", blocking=True, limit=10, entity_id="input_text.multimedia_current_movie_plot", value="no plot available")

  • Create four input_text sensors in homeassistant
input_text:

  multimedia_current_movie_title:
    name: Multimedia Current Movie Title
    
  multimedia_current_movie_rating:
    name: Multimedia Current Movie Rating
    
  multimedia_current_movie_genre:
    name: Multimedia Current Movie Genre
    
  multimedia_current_movie_plot:
    name: Multimedia Current Movie Plot
    max: 255
  • Create an input_number sensor for the rating threshold
  multimedia_tv_minimum_rating:
    name: Movie Minimum Rating
    icon: mdi:brightness-percent
    mode: slider
    step: 0.1
    max: 10
    min: 0
    initial: 5.0
  • Add an automation to trigger getting the movie infos
alias: multimedia_tv_aerocast_get_movie_infos
description: ""
trigger:
  - platform: state
    entity_id:
      - media_player.aerocast
    to: playing
    id: "1"
  - platform: state
    entity_id:
      - media_player.aerocast
    from: playing
    id: "2"
condition: []
action:
  - choose:
      - conditions:
          - condition: trigger
            id: "1"
        sequence:
          - service: pyscript.multimedia_getmovieinfos
            data:
              mytitle: |
                {{ state_attr('media_player.aerocast', 'media_title') }}
  - choose:
      - conditions:
          - condition: trigger
            id: "2"
        sequence:
          - service: input_text.set_value
            data:
              value: " "
            target:
              entity_id: input_text.multimedia_current_movie_genre
          - service: input_text.set_value
            data:
              value: " "
            target:
              entity_id: input_text.multimedia_current_movie_title
          - service: input_text.set_value
            data:
              value: " "
            target:
              entity_id: input_text.multimedia_current_movie_rating
          - service: input_text.set_value
            data:
              value: " "
            target:
              entity_id: input_text.multimedia_current_movie_plot
mode: single




  • Add an automation to announce whenever you play your movie - I do that through mqtt. Adjust to your liking :)

alias: jarvis_notify_movie_rating
description: ""
trigger:
  - platform: state
    entity_id:
      - input_text.multimedia_current_movie_rating
condition:
  - condition: template
    value_template: "{{ states('input_text.multimedia_current_movie_rating') != ' ' }}"
action:
  - choose:
      - conditions:
          - condition: template
            value_template: >-
              {{ states('input_text.multimedia_current_movie_rating') |
              float(default=0) <
              states('input_number.multimedia_tv_minimum_rating') |
              float(default=0) }}
        sequence:
          - service: mqtt.publish
            data:
              topic: notifications
              payload_template: |
                { 
                  "heading": "Movie underrated",
                  "details":
                    { 
                      "msg": "Do you really want to watch {{ state_attr('media_player.aerocast', 'media_title') }}? It only has a rating of {{ states('input_text.multimedia_current_movie_rating') }} on I M D B.",
                      "player": "livingroom",
                      "importance": "high",
                      "received": "{{ now().strftime("%H:%M:%S") }}" 
                    }
                }
      - conditions:
          - condition: template
            value_template: >-
              {{ states('input_text.multimedia_current_movie_rating') |
              float(default=0) >=
              states('input_number.multimedia_tv_minimum_rating') |
              float(default=0) }}
        sequence:
          - service: mqtt.publish
            data:
              topic: notifications
              payload_template: |
                { 
                  "heading": "Movie well rated",
                  "details":
                    { 
                      "msg": "Nice choice for a{% if states('input_text.multimedia_current_movie_genre').split(',')[0] | lower | regex_search("[aeiou]")%}n{% endif %} {{ states('input_text.multimedia_current_movie_genre').split(',')[0] | lower }} movie. {{ state_attr('media_player.aerocast', 'media_title') }} has a rating of {{ states('input_text.multimedia_current_movie_rating') }} on I M D B.",
                      "player": "livingroom",
                      "importance": "high",
                      "received": "{{ now().strftime("%H:%M:%S") }}" 
                    }
                }
mode: single