Started down the road of looking into alternatives to Tasker for home automation and came across Home Assistant on my UnRaid server. Loving what I have setup so far and the possibilities. Syntax seems easy, but as always Im going to need a bit of help with something more advanced.
So right now I have two of the Android Set-top boxes (shield and mibox) in different rooms of my house controlling the scene lighting in their respective rooms. Dim on play and Brighten on Pause/Stop, which works well.
Here is the problem though. Stop is way to generic. It can cause problems such as when I watch a show in my room at night and fall asleep with a show playing. After the show has finished and the player returns to its default state (stopped?) the lights in my room raise and stay that way till I wake up in the AM.
What are the full list of states for media players? Is it simply playing, paused and stopped, or are there more?
Is the perhaps a null state of not doing anything? If so what would be the trigger “To” state I would enter?
Ive been trying to think of the more logical way I would like to have this all function, but I need some help in creating the conditionals. Ideally I would like to have the lights turn off after I fall asleep and a show ends and the player goes into a null state, in my room at night. On the opposite side I dont want to make it so strict in the living room. In the living room Id like to have the lights stay dimmed after a show ends for a say 30 seconds, in case Im binge watching. IE I dont want the lights to go from dimmed to bright back to dimmed just because the last episode ended and the new one is selected and moved into the play state.
I would think they would correspond with the services but I’m not in a position to test that theory right now. The list of services exposed is on the docs page at the top:
How are you triggering your “un-dim” automation? Could you add a conditional to it that only will brighten the lights if they are on?
In my bedroom, I have an automation that dims the lights (only if they are on, and only if it is after sunset) when I play media in there. When that media player stops, it will brighten the lights again, but only if they are on, and only if it is before 11:30pm. If it is after 11:30pm, it will turn the lights off, instead. I also set up idle timers (Kodi) that will shut off the screen if I haven’t hit anything for awhile.
Maybe that is the sort of thing you’re looking for?
I’m only doing the first part of this, in two steps - scene plays at full brightness when Harmony senses an activity start at sundown - 00:45:00 (because that’s when my east facing living room gets dark), then after 2:00 minutes runs a dimmer scene for watching TV. If I choose another activity, it runs again.
Here’s mine, maybe post yours and between the two of us there might be something he can use.
# If media player stops and it isn't quite "late" yet.
- alias: "Bedroom Kodi paused/stopped-early"
trigger:
- platform: state
# sleepypi is our bedroom Kodi
entity_id: media_player.sleepypi
# using "from: 'playing'" catches both stop and pause
from: 'playing'
condition:
- condition: state
# light.master is the main overhead in our master bedroom
entity_id: light.master
# we only want this to fire if the overhead is currently on
state: 'on'
- condition: state
entity_id: sun.sun
# and when the sun is down
state: 'below_horizon'
- condition: time
# but only if it isn't "late"
before: '23:20:00'
action:
service: scene.turn_on
# this scene just returns the light to its default state
entity_id: scene.bedroom_normal
# if the media player stops and it IS "late"
- alias: "Bedroom Kodi paused/stopped-late"
trigger:
- platform: state
entity_id: media_player.sleepypi
from: 'playing'
condition:
- condition: state
entity_id: light.master
# AND if the light is still on
state: 'on'
- condition: time
# What am I still doing awake, anyways?
after: '23:20:00'
action:
service: scene.turn_on
# this turns the light off, instead of brightening
entity_id: scene.bedroom_sleep
# This is just the dimming on play portion
- alias: "Media player playing"
trigger:
- platform: state
entity_id: media_player.sleepypi
# only fires when you start playing (from paused or stopped state)
to: 'playing'
condition:
- condition: state
entity_id: light.master
# only fire if the overhead is on. that way we don't turn on and dim a light that is already off!
state: 'on'
- condition: time
# again, only before it gets too late in the evening
before: '23:20:00'
action:
service: scene.turn_on
# this is the scene that sets the lights dim
entity_id: scene.bedroom_dim
Thanks for the response. Im looking over the list but not seeing anything for a state of NO PLAY.
Not sure if you are familiar with some of the Android Theming communities, but I use to work for MyColorScreen on the Themer project. I was brought in because I ran the community for Zooper and later helped the dev for Kustom, start his communities.
Both the apps listed were basically used for creating desktop widgets through a WYSIWYG editor. Lets say I wanted to build a music widget that was large enough to display the album art fullscreen. I would use the Play/Paused/Stopped states for showing the art and the null state (later on the no-media state) to hide the art layer and display the controls alone.
Id like to us a setup similar to that to control the lighting in my room. This way when the system goes into this state of not stopped but instead doing nothing, I can have the lights automatically go off in the room.
Looking at the history and logbook tabs in the HASS UI it looks as though there is an “idle” state. This might be what Im looking for. I think on the Android Tv players this is when the players start showing a screensaver.
I remember MyColorScreen and still use Zooper on my Droid Turbo (custom ROM)!
I’d be interested in what you find and providing what help I can as I would like to implement some similar functions myself based on the media player states. I think “idle” might be what you’re looking for, though I find that my FireTV tends to go into idle sometimes when I’m not even using it. I don’t currently use the FireTV server so it may be just detecting the power on state when my AVR connects to it.
I’ve been thinking of setting up the FireTV server to see if it will report state and devices better though.
Let me know what you find; I’m no dev but I’ll help where I can.
So I have confirmed that “idle” will serve this purpose well, and my bedroom script is for the most part done. Well at least the falling asleep part.
Small slightly on/off topic question regarding all this. Do you know how if we can write an “OR” in the entity_id field.
I ask only because every Android TV player actually shows up as two players for HASS, one is the native player and the other is the cast player. So Id like to have the lighting scripts more compact where i can have the automation look at the state of two players at once. “entity_id: media_player.mi_box | media_player.miboxCast”
Also where do I use the “media_content_type: VIDEO”? Im assuming it should be in condition:, but Im not sure of the condition type I should use.
Here is what I have for the bedroom, Ive hashed out the sunrise stuff mainly because I use a projector in the bedroom and always have it dark in there.
automation:
- alias: "MiBox Media player paused/stopped"
trigger:
- platform: state
entity_id: media_player.mi_box
#media_content_type: VIDEO
from: 'playing'
#condition:
#- condition: state
#entity_id: sun.sun
#state: 'below_horizon'
action:
service: scene.turn_on
entity_id: scene.Master_Bedroom_normal
- alias: "MiBox Media player playing"
trigger:
- platform: state
entity_id: media_player.mi_box
#media_content_type: VIDEO
to: 'playing'
#condition:
#- condition: state
#entity_id: sun.sun
#state: 'below_horizon'
action:
service: scene.turn_on
entity_id: scene.Master_Bedroom_Dim
- alias: "MiBox Media player idle"
trigger:
- platform: state
entity_id: media_player.mi_box
to: 'idle'
#condition:
#- condition: state
#entity_id: sun.sun
#state: 'below_horizon'
action:
service: scene.turn_on
entity_id: scene.Master_Bedroom_Off
- alias: "MiBox Media player paused/stopped"
trigger:
- platform: state
entity_id: media_player.mibox3
#media_content_type: VIDEO
from: 'playing'
#condition:
#- condition: state
#entity_id: sun.sun
#state: 'below_horizon'
action:
service: scene.turn_on
entity_id: scene.Master_Bedroom_normal
- alias: "MiBox Media player playing"
trigger:
- platform: state
entity_id: media_player.mibox3
#media_content_type: VIDEO
to: 'playing'
#condition:
#- condition: state
#entity_id: sun.sun
#state: 'below_horizon'
action:
service: scene.turn_on
entity_id: scene.Master_Bedroom_Dim
- alias: "MiBox Media player idle"
trigger:
- platform: state
entity_id: media_player.mibox3
to: 'idle'
#condition:
#- condition: state
#entity_id: sun.sun
#state: 'below_horizon'
action:
service: scene.turn_on
entity_id: scene.Master_Bedroom_Off
I think you could accomplish this with a template trigger. You create the template for the state and then test the state.
That one I don’t know. But hopefully someone will come along with a better answer! Looking good so far. I think for my use case I’d have to make some changes but it gives me a start I didn’t have before. Thanks for sharing!
Nice work! I haven’t played with the idle state at all. Does it fire immediately after media is done playing, or does it wait for some other event? (eg: the screensaver activating or similar)
Thanks for sharing the automations for media player. Can you also share your media_player configuration for Mi Box? I have that same box and would like to have the states in HA. It is autodiscovered but state is always off.
How do you get the Mi Box to show up in HA? I can only get the chromecast portion of the Mi Box showing. Can you please explain how you added the Mi Box?
Thank you!