Remove states UI options in group integration (#11765)

This commit is contained in:
Franck Nijhof 2020-01-16 18:43:00 +01:00 committed by GitHub
parent 2871accb5f
commit 1865b41d99
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 2 additions and 272 deletions

View File

@ -1,184 +0,0 @@
---
title: "Group Visibility"
description: "Instructions on how to change group visibility using automations."
redirect_from: /topics/group_visibility/
---
After filling Home Assistant with all your precious home automation devices, you usually end up with a cluttered interface and lots of groups that are not interesting in your current context. What if you just want to show groups that are interesting _now_ and hide the rest? That's when group visibility comes to play.
## Changing visibility of a group
To change visibility of a group, use the service `group.set_visibility`, pass the group name as `entity_id` and use `visible` to decide whether the group should be shown or hidden.
```yaml
service: group.set_visibility
entity_id: group.basement
data:
visible: false
```
<div class='note'>
If a sensor belongs to only one group and that group is hidden, the sensor will "jump" to the top of the web interface. Add the sensor to an additional (visible) group if you do not want this to happen.
</div>
## Automations
First you should decide under which circumstances a group should be visible or not. Depending on the complexity, you might have to write two automations: one that hides the group and another that shows it.
In this example, the group `group.basement` is hidden when the sun sets and shown again when it rises:
```yaml
automation:
trigger:
platform: sun
event: sunset
action:
service: group.set_visibility
entity_id: group.basement
data:
visible: false
automation 2:
trigger:
platform: sun
event: sunrise
action:
service: group.set_visibility
entity_id: group.basement
data:
visible: true
```
## Easier automations
One of the most common uses cases are to show groups during certain times of day, maybe commuting information during a work day morning or light switches when it is getting dark. The complexity of automations needed to make this happen will quickly get out of hand. So, one way to make the automations easier is to create a sensor that alters its state depending on time of day. One way of doing that is using a `command_line` sensor and a script:
```python
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from datetime import time, datetime
def mk_occasion(name, start, end, days=None):
s = start.split(":")
e = end.split(":")
return {
"name": name,
"start": time(int(s[0]), int(s[1]), int(s[2])),
"end": time(int(e[0]), int(e[1]), int(e[2])),
"days": days,
}
# Matching is done from top to bottom
OCCASIONS = [
# More specific occasions
mk_occasion("work_morning", "06:00:00", "07:10:00", range(5)),
# General matching
mk_occasion("weekday", "00:00:00", "23:59:59", range(5)),
mk_occasion("weekend", "00:00:00", "23:59:59", [5, 6]),
]
def get_current_occasion(occasion_list, default_occasion="normal"):
now = datetime.now()
for occasion in OCCASIONS:
if occasion["start"] <= now.time() <= occasion["end"] and (
occasion["days"] is None or now.weekday() in occasion["days"]
):
return occasion["name"]
return default_occasion
if __name__ == "__main__":
print(get_current_occasion(OCCASIONS))
```
This script will output "work_morning" from 06:00-07:10 during weekdays (Monday-Friday), "weekday" during all other time from Monday-Friday and "weekend" on Saturdays and Sundays. Adjust according to your needs. To create the sensor, just add it like this:
```yaml
sensor:
- platform: command_line
name: Occasion
command: "python3 occasion.py"
```
<div class='note'>
If you are using docker to run Home Assistant then the occasion.py script will be placed under /config. Your command should instead be: command: "python3 /config/occasion.py"
</div>
To simplify things, we create a Home Assistant script that changes the visibility of a group, but also verifies that an entity is in a specific state:
```yaml
script:
group_visibility:
sequence:
- service: group.set_visibility
data_template:
entity_id: '{% raw %}{{ entity_id }}{% endraw %}'
visible: '{% raw %}{{ is_state(cond, visible_state) }}{% endraw %}'
```
The last part is writing an automation that hides or shows the group:
```yaml
automation:
- alias: Work morning
trigger:
- platform: state
entity_id: sensor.occasion
- platform: homeassistant
event: start
action:
service: script.group_visibility
data:
entity_id: group.work_sensors
cond: sensor.occasion
visible_state: 'work_morning'
```
Our previously defined script will be called if `sensor.occasion` changes state OR when Home Assistant has started. The group `group.work_sensors` will be shown when `sensor.occasion` changes state to "work_morning" and hidden otherwise.
### The complete example
```yaml
group:
default_view:
entities:
- group.work_sensors
# Only visible when it's time to go to work
work_sensors:
name: Time to go to work
entities:
- sensor.something1
- sensor.something2
sensor:
- platform: command_line
name: Occasion
command: "python3 occasion.py"
script:
group_visibility:
sequence:
- service: group.set_visibility
data_template:
entity_id: '{% raw %}{{ entity_id }}{% endraw %}'
visible: '{% raw %}{{ is_state(cond, visible_state) }}{% endraw %}'
automation:
- alias: Work morning
trigger:
- platform: state
entity_id: sensor.occasion
- platform: homeassistant
event: start
action:
service: script.group_visibility
data:
entity_id: group.work_sensors
cond: sensor.occasion
visible_state: 'work_morning'
```

View File

@ -54,10 +54,6 @@
{% active_link /docs/configuration/secrets/ Storing Secrets %} {% active_link /docs/configuration/secrets/ Storing Secrets %}
</li> </li>
<li>{% active_link /docs/configuration/templating/ Templating %}</li> <li>{% active_link /docs/configuration/templating/ Templating %}</li>
<li>
{% active_link /docs/configuration/group_visibility/ Group
Visibility %}
</li>
<li> <li>
{% active_link /docs/configuration/platform_options/ Entity {% active_link /docs/configuration/platform_options/ Entity
component platform options %} component platform options %}

View File

@ -10,7 +10,7 @@ ha_codeowners:
- '@home-assistant/core' - '@home-assistant/core'
--- ---
Groups allow the user to combine multiple entities into one. Groups allow the user to combine multiple entities into one.
Check the **States** <img src='/images/screenshots/developer-tool-states-icon.png' class='no-shadow' height='38' /> page from the **Developer Tools** and browse the **Current entities:** listing for all available entities. Check the **States** <img src='/images/screenshots/developer-tool-states-icon.png' class='no-shadow' height='38' /> page from the **Developer Tools** and browse the **Current entities:** listing for all available entities.
@ -48,16 +48,7 @@ all:
type: boolean type: boolean
default: false default: false
icon: icon:
description: The icon that shows in the front end. **The rest of this only applies to the deprecated UI `/states`**. If the group is a view, this icon will show at the top in the frontend instead of the name. If the group is a view and both name and icon have been specified, the icon will appear at the top of the frontend and the name will be displayed as the mouse-over text. description: The icon that shows in the front end.
required: false
type: string
view:
description: "**Only applies to the deprecated UI `/states`**. If yes then the entry will be shown as a view (tab) at the top. Groups that are set to `view: true` cannot be used as entities in other views. *Does not apply to Lovelace.*"
required: false
type: boolean
default: false
control:
description: "**This is only a feature in generated mode of Lovelace** If value set to `hidden` the group switch will be hidden."
required: false required: false
type: string type: string
{% endconfiguration %} {% endconfiguration %}
@ -65,76 +56,3 @@ control:
## Group behavior ## Group behavior
By default when any member of a group is `on` then the group will also be `on`. Similarly with a device tracker, when any member of the group is `home` then the group is `home`. If you set the `all` option to `true` though, this behavior is inverted and all members of the group have to be `on` for the group to turn on as well. By default when any member of a group is `on` then the group will also be `on`. Similarly with a device tracker, when any member of the group is `home` then the group is `home`. If you set the `all` option to `true` though, this behavior is inverted and all members of the group have to be `on` for the group to turn on as well.
---
## Old user interface
This section only applies if you've not moved off the deprecated `/states` user interface.
A group can be promoted to a **view** by setting `view: true` under the group definition. This will make the group available as a new tab in the frontend.
By default, every group appears in the HOME tab. If you create a group `default_view` it will REPLACE the contents of the HOME tab so you can customize the HOME tab as you wish.
```yaml
# Example configuration.yaml entry
group:
default_view:
view: true
icon: mdi:home
entities:
- group.kitchen
- group.awesome_people
- group.climate
kitchen:
name: Kitchen
entities:
- switch.kitchen_pin_3
upstairs:
name: Kids
icon: mdi:account-multiple
view: true
entities:
- input_boolean.notify_home
- camera.demo_camera
- device_tracker.demo_paulus
- group.garden
climate:
name: Climate
view: false
entities:
- sensor.bedroom_temp
- sensor.porch_temp
awesome_people:
name: Awesome People
view: false
entities:
- device_tracker.dad_smith
- device_tracker.mom_smith
```
<p class='img'>
<img src='/images/blog/2016-01-release-12/views.png'>
Example of groups shown as views in the frontend.
</p>
If all entities in a group are switches or lights then Home Assistant adds a switch at the top of the card that turns them all on/off at once. If you want to hide this switch, set `control` to `hidden`.
You can create views (tabs) that contain other groups (but not other groups which are marked as `view: true`).
Notice in the example below that in order to refer to the group "Living Room", you use `group.living_room` (lowercase and spaces replaced with underscores).
```yaml
# Example configuration.yaml entry that shows two groups, referred to in a view group (tab)
Living Room:
control: hidden
entities:
- light.light_family_1
- binary_sensor.motion_living
Bedroom: light.light_bedroom, switch.sleeping
Rooms:
view: true
name: Rooms
entities:
- group.living_room
- group.bedroom
```