Typing this while doing it, so forgive me if I don’t even finish this post (my entities will be different to Grayson’s)
Configuration|Autmations|Add Automation|Start with an empty automation
Fill in a name and description
Scroll down to trigger and choose state, then start typing entity_id. As you type (It’ll start with media_player) the choices will narrow until you can click on an entity you want in the automation. Mine is media_player.kodibedroom
In the To: field type playing
Click Add Condition, then under Type choose template.
In the Value Template field type {{ states.media_player.kodibedroom.attributes.media_content_type == "movie" }}
Under Action choose Call Service
In service type or choose light_turnoff
Choose the area/device/entity you want to turn off.
Actually I have to say that doesn’t work on my system. The media player entity state switches to playing moments before media_content_type is set to movie, resulting in the condition failing. At least I think that is what is happening.
EDIT: more correctly media_content_type changes to video then to movie. Fixed by adding
I can’t post all 3 of my automations if you like? Your best bet if you’re not confident with Yaml would be to paste the YAML code and then switch to GUI mode. You’ll also need to add the input text into your config as well.
Thanks I’d like to see what you are doing.
As for YAML, I’m quite comfortable with it, HA seems to be pushing the GUI interface a lot so I figured why not learn the GUI as I build a new HA instance.
And, I just figured out that if I hit the three dot menu for an ‘entry’ there is an option to edit in YAML… I’ll show myself out now
Make sure you add the below to your configuration.yaml, if you want to implement for tv shows as well change the media content type from movie to tvshow
input_text:
kodi_media_content_type:
name: KODI Media Content Type
Movie Playing
alias: KODI Home Theater Movie Playing
trigger:
- entity_id: media_player.kodi
platform: state
to: playing
condition:
- condition: state
entity_id: sun.sun
state: below_horizon
action:
- delay: '00:00:01'
- condition: template
value_template: '{{ is_state_attr(''media_player.kodi'', ''media_content_type'', ''movie'') }}'
- data:
entity_id: light.diningroomlamp
service: light.turn_off
- data:
entity_id: light.livingroomlamp
service: light.turn_off
- service: input_text.set_value
data_template:
entity_id: input_text.kodi_media_content_type
value: '{{ states.media_player.kodi.attributes.media_content_type }}'
mode: single
Movie Pause / Play
alias: KODI Home Theater Movie Paused
trigger:
- entity_id: media_player.kodi
from: playing
platform: state
to: paused
condition:
- condition: template
value_template: '{{ states.media_player.kodi.attributes.media_content_type == "movie" }}'
- condition: and
conditions:
- condition: state
entity_id: sun.sun
state: below_horizon
action:
- data:
entity_id: light.diningroomlamp
service: light.turn_on
- data:
entity_id: light.livingroomlamp
service: light.turn_on
mode: single
Movie Stopped
alias: KODI Home Theater Movie Ended
trigger:
- entity_id: media_player.kodi
platform: state
to: idle
condition:
- condition: state
entity_id: input_text.kodi_media_content_type
state: movie
action:
- data:
entity_id: light.diningroomlamp
service: light.turn_on
- data:
entity_id: light.livingroomlamp
service: light.turn_on
- data:
entity_id: input_text.kodi_media_content_type
value: ''
service: input_text.set_value
mode: single
Hi there. Thank you for your great code. I saw this and ordered a new Synology DS to run docker and HA make this happen to my homecinema. So… as you will guess… I’m a total newbie
I have a problem with the content type detection. When it’s enabled the automation isn’t working. If I disable the template condition, it works. I’ve added
input_text:
kodi_media_content_type:
name: KODI Media Content Type`Preformatted text`
to the top of my configuration.yaml in the Home Assistant root-folder and rebootet the HA-server but still no function. I’m using Kodi 20.1.
Here’s my yaml:
alias: KODI Home Theater Movie Playing
trigger:
- entity_id: media_player.kodi_kino
platform: state
to: playing
condition: []
action:
- delay:
hours: 0
minutes: 0
seconds: 2
milliseconds: 0
- condition: template
value_template: "{{ is_state_attr('media_player.kodi', 'media_content_type', 'movie') }}"
enabled: true
- service: switch.turn_off
data: {}
target:
entity_id: switch.3gang_switch_switch_1
- service: input_text.set_value
data_template:
entity_id: input_text.kodi_media_content_type
value: "{{ states.media_player.kodi.attributes.media_content_type }}"
mode: single
Thanks for your fast response. That was an copy-error, but I still fixed it. Looks like this now:
# Loads default set of integrations. Do not remove.
default_config:
# Load frontend themes from the themes folder
frontend:
themes: !include_dir_merge_named themes
# Text to speech
tts:
- platform: google_translate
automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml
input_text:
kodi_media_content_type:
name: KODI Media Content Type
Now it’s working but it also does when I run tvshows or music.
I know this is a extremely old post. I’m really new to the HA world. I’ve been trying to get this to work properly for days. Hopefully someone will chime in. Whatever I need to upload please let me know anything would be appreciated.