#Buttons to Control Casting

1 messages · Page 1 of 1 (latest)

sage shore
#

Having a hard time figuring out how to control this flow, but I'd like to have 3 buttons (something like the screenshot) control various casts of camera dashboards.

However, I'd also like to change the icon to something different if I select one of them to indicate it's casting. Additionally, it'd be nice to be able to click the button again to call media_player.turn_off to stop the casting.

I currently have 3 individual scripts (below) to control the actual casting action and they work fine. I'm just not sure how to wire up buttons to the scripts in a way where only one button can be active at a time, and clicking it again calls turn_off like above.

I've done some searching and I'm not sure if using an input_select entity would be the right approach since I'd be able to then select from a pre-determined list of options.

Any guidance (or how to approach this) would be appreciated as I'm learning HA. Thank you!


alias: Show All Cameras
action: cast.show_lovelace_view
data:
  entity_id: media_player.living_room_tv
  dashboard_path: dashboard-cameras
  view_path: all
dense scarab
#

What you can do is use the "Template Switch" Helper - it lets you define the on and off actions for the button as well as a way to extract on/off (e.g. media_player.is_playing or whatever the actual check you can make to see if a media player is playing)

#

So your downstairs one would have a "state" of "is downstairs playing something", "turn on" actions of turn on downstairs, turn off upstairs, and a "turn off action" of "turn off downstairs"
Upstairs would be the same but reversed
All would turn on/off both and would check for both being active

#

this would result in standard blue/yellow colouring of the icon to indicate if it's active or not

#

If you wanted something different, I'd suggest looking at button cards or mushroom cards as they let you define different icons for on and off quite easily

sage shore
#

Hi hillburn, thank you! I wasn't aware of a "template switch" helper, but it definitely looks like that is on the right track of what I'm looking for. I've already started digging into the custom:button-card addon and I'm sure there's enough configuration there to do what I want, just need to mess with them more.

Thanks for the quick response, I'll follow up if I have any more questions

dense scarab
#

the thing that button card doesn't do easily is different actions depending on state - so "if on -> send X command on press, if off -> send Y" - it's doable, just messy

#

so i'd recommend doing the template switch even if you use BC for the frontend

sage shore
# dense scarab the thing that button card doesn't do easily is different actions depending on s...

Makes sense, thank you. I've started to look into building out my first template switch, and just want to confirm that I will need 3 button entities defined for each of the buttons above in the screenshot. That way, in the template switch, I can turn off the "other two" as necessary when the buttons are switched on/off. I'm in th emiddle of feeding kids and am just trying to wrap my head around what I will need to put together my template swithes.

Then, the button-card frontend will hook up to the template switch entity I think

dense scarab
#

Yeah basically

sage shore
#

Hi @dense scarab, wanted to see if there was a better way to do this. Here's what I have so far (screenshots probably show it better)

The input_boolean toggles were a way that I could switch between template switches without calling the media_player.turn_off action defined on the template switch. The template switches then control the input_booleans state and the value of the template switch is set to the toggle.

Curious if there's a more effective way to do this. Thank you

dense scarab
#

Why do you need the additional input booleans?

#

What's wrong with calling media_player.turn_off?

sage shore
#

I think the problem I was running into was if I "turn on" the "all" cameras template switch, then I also want to set the other (upstairs/downstairs) switches to off.

If I call off to those other templates, then won't that call emdia_player.turn_off and stop casting everything?

dense scarab
#

make their "on" state be "upstairs is playing and downstairs is not playing" and vice versa

#

that way if you turn on both with the "play all" it will make both of them return false

sage shore
dense scarab
#

Yes. Make it check whatever is being played

sage shore