Post

Managing groups visibility in Home Assistant

The States UI is now deprecated and will be completely removed from Home Assistant in version 0.107.0. Therefore, this won’t work anymore after that.

After I wrote Dynamically hide / unhide an entire view in Home Assistant, many people asked me if it is possible to do the same with the cards (groups). It is, and it’s easy too.

Here is an example code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
group:
  default_view:
    view: yes
    entities:
      - group.test_group
      - group.test_subgroup1
      - group.test_subgroup2
      - group.test_subgroup3

  test_group:
    name: "Test Group"
    control: hidden
    entities:
      - input_boolean.test_input_boolean1
      - input_boolean.test_input_boolean2
      - input_boolean.test_input_boolean3

  test_subgroup1:
    name: "Test Subgroup 1"
    entities:
      - sensor.sensor_1

  test_subgroup2:
    name: "Test Subgroup 2"
    entities:
      - sensor.sensor_2

  test_subgroup3:
    name: "Test Subgroup 3"
    entities:
      - sensor.sensor_3

input_boolean:
  test_input_boolean1:
    name: "Change Subgroup 1 visibility"
    initial: on
  test_input_boolean2:
    name: "Change Subgroup 2 visibility"
  test_input_boolean3:
    name: "Change Subgroup 3 visibility"

sensor:
  - platform: random
    name: Sensor 1
  - platform: random
    name: Sensor 2
  - platform: random
    name: Sensor 3

customize:
  group.test_subgroup2:
    visible: false
  group.test_subgroup3:
    visible: false

automation:
  - alias: "group_view_default"
    trigger:
      - platform: homeassistant
        event: start
    action:
      - service: group.set_visibility
        entity_id: group.test_subgroup1
        data:
          visible: true
      - service: group.set_visibility
        entity_id: group.test_subgroup2
        data:
          visible: false
      - service: group.set_visibility
        entity_id: group.test_subgroup3
        data:
          visible: false

  - alias: "subgroup1_visible"
    trigger:
      - platform: state
        entity_id: input_boolean.test_input_boolean1
        to: "on"
    action:
      - service: group.set_visibility
        entity_id: group.test_subgroup1
        data:
          visible: true

  - alias: "subgroup1_hidden"
    trigger:
      - platform: state
        entity_id: input_boolean.test_input_boolean1
        to: "off"
    action:
      - service: group.set_visibility
        entity_id: group.test_subgroup1
        data:
          visible: false

  - alias: "subgroup2_visible"
    trigger:
      - platform: state
        entity_id: input_boolean.test_input_boolean2
        to: "on"
    action:
      - service: group.set_visibility
        entity_id: group.test_subgroup2
        data:
          visible: true

  - alias: "subgroup2_hidden"
    trigger:
      - platform: state
        entity_id: input_boolean.test_input_boolean2
        to: "off"
    action:
      - service: group.set_visibility
        entity_id: group.test_subgroup2
        data:
          visible: false

  - alias: "subgroup3_visible"
    trigger:
      - platform: state
        entity_id: input_boolean.test_input_boolean3
        to: "on"
    action:
      - service: group.set_visibility
        entity_id: group.test_subgroup3
        data:
          visible: true

  - alias: "subgroup3_hidden"
    trigger:
      - platform: state
        entity_id: input_boolean.test_input_boolean3
        to: "off"
    action:
      - service: group.set_visibility
        entity_id: group.test_subgroup3
        data:
          visible: false


And here is the result.


This post is licensed under CC BY 4.0 by the author.

Comments powered by Disqus.