So I want a Master Control on my first lovelace card. These button should show if one of the group (I have a group for media players, switches etc.) is on or running. So I will push the button and everything at this group switch to off.
That won’t work with media players. You’ll have to make a universal media_player entity that marries all the media players together. This is no easy task and I don’t have a full example on hand. However you should study scripts, media_players, and templates. With all that knowledge, you should be able to make a universal media player that controls all of them.
So I think the first step is taken. I have a group for my Sonos Media Players (nothing Special) and a template for the Master Control:
platform: template
sensors:
tmp_sonosmedia_master:
friendly_name: "Sonos Master"
entity_id:
- media_player.bad
- media_player.buro
- media_player.computer
- media_player.keller
- media_player.kuche
- media_player.schlafzimmer
- media_player.terrasse
- media_player.toilette
- media_player.wohnzimmer
value_template: >-
{% set output = namespace(state="off") %}
{% for entity in states.group.grp_sonosmedia.attributes.entity_id %}
{% set domain, device = entity.split('.') %}
{% if ((states[domain][device].state == "playing") and (output.state == "off")) %}
{% set output.state = "on" %}
{% endif %}
{% endfor %}
{{ output.state }}
icon_template: >-
{% set output = namespace(state="off") %}
{% for entity in states.group.grp_sonosmedia.attributes.entity_id %}
{% set domain, device = entity.split('.') %}
{% if (((states[domain][device].state) == "playing") and (output.state == "off")) %}
{% set output.state = "on" %}
{% endif %}
{% endfor %}
{% if output.state == "on" %}
mdi:play
{% else %}
mdi:stop
{% endif %}
Here I run the group entity_id’s (it’s nicer to manage the devices a one group file then at many automations, templates etc.) and look at the state. If one is ‘playing’ then the master-template is ‘on’.
So I can use the Entity Button and it works.
So now I think I should make a script to set all media-players off and run this from a button action right?
I’m new to hass.io and it would be nice to here I running Ok without the universal media player or do I have a showstopper at my scripting?