I am relatively new to Home Assistant and would greatly appreciate some help with something I think is pretty basic. I haven’t been able to find much in the documentation.
I’m using the androidtv integration to monitor the status of my Android TV device.
I’m trying to figure out how to write an automation do to the following:
If media_player.androidtv app is launcher
or media_player.androidtv status is off
or media_player.androidtv status is standby
then
call a rest command
else
call a different rest command
I am doing something similar with several different automations but it is proving somewhat unreliable, for example:
The if portion of your pseudo-code is easy to implement. However, it’s the else portion that I find to be odd. You want it to trigger when any other androidtv app is active? Because that’s what that else portion will do.
Hi @123 – yes that’s exactly what I want to do. If Launcher is active, or if the device is in off or standby mode then I want a certain action. For any other state (i.e. an app is loaded) then I want another action.
If you can provide me with a yaml example I would be grateful. From there I could change things as needed.
“Look for red cars”
It will trigger when it sees a red car and not when it sees “anything else” like a white car or yellow truck.
“Look for vehicles.”
It will trigger when it sees anything that fits the definition of a vehicle (any color of car or truck). After it has triggered, you could use a condition to filter it or, within the action, determine what kind of vehicle was spotted and proceed to handle it accordingly.
In your case, the pseudo-code’s else obliges to you to create a trigger that monitors for any change to media_player.android_tv regardless of what that change may be. That’s a simple State Trigger like this (it’s triggered by any changes to the entity’s state or attributes):
trigger:
- platform: state
entity_id: media_player.android_tv
Then it’s left to the action to determine what to do:
That’s what choose does. In the example I posted, if the first conditions section within choose is not met then it will execute the default portion. You can have more than one conditions section.
Please consider marking my post (containing the suggested automation) with the Solution tag. It will automatically place a check-mark next to the topic’s title which signals to other users that this topic has an accepted solution. Effectively it indicates that the problem is resolved and helps users find answers to similar questions.