Skip to content

Person Card

Series 2 will be released in 2025!

Visualization

Swiss Army Knife Functional Card Person D06 Light Home Swiss Army Knife Functional Card Person D06 Light Home

This card uses the Material 3 theme D06, TealBlue

This card shows you some possibilities to apply JavaScript to the animations section

The card seems like a standard, simple card, but isn't due to some Home Assistant functionalities and the possibilities of using either an icon or an entity picture for the person.

The use of JavaScript to fetch the zone's Icon, to do some state dependent color changes and taking care of the "use entity_picture yes/no" setting are nice examples of the possibilities that JavaScript adds to tools. It are just a few lines, but very powerful!

It also takes care of fetching the icon of additional zones (ie not the home zone).

Description Aspect Ratio Target Size
A card that shows in which zone a person is, or if in no known zone as away / not home. 1/1 Grid with 2 columns

Interaction

Part Description
Card All tools connected to an entity do show by default the "more-info" dialog once clicked

Usage

4.0.1

Using the default mode: an icon for the person entity:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
- type: 'custom:swiss-army-knife-card'
  entities:
    - entity: person.marco
      name: 'Person'
      icon: mdi:face-man
    - entity: person.marco
      name: 'Person'
      secondary_info: last_changed
      format: time-24h_date-short
  layout:
    template:
      name: sak_layout_fce2_person
      variables:
        - sak_layout_person_zone_entities:
            - zone.outside
            - zone.marco_work
Using an entity_picture for the person entity. Picture can be defined here, or (default) the entity_picture defined for the person is used:
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
- type: 'custom:swiss-army-knife-card'
  entities:
    - entity: person.marco
      name: 'Tha Washer'
      icon: mdi:face-man
      entity_picture: "/local/images/clip-test.jpg"
    - entity: person.marco
      name: 'Tha Washer'
      secondary_info: last_changed
      format: time-24h_date-short

  layout:
    template:
      name: sak_layout_fce2_person
      variables:
        - sak_layout_person_use_entity_picture: true
        - sak_layout_person_zone_entities:
            - zone.outside
            - zone.marco_work

Data Default Required Description
entities The person entity
sak_layout_person_zone_entities The list of zone entities for this person to be displayed. There is no limit, it is really a list which is used when the person is not at home!
sak_layout_person_use_entity_picture false If set to true, an entity picture is displayed instead of the persons icon. Default the picture configured for the person is used, but can be overridden by specifying an entity_picture in the entity configuration in the view

YAML Template Definition

4.0.1

Full definition of layout template
  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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
sak_layout_fce2_person:
  template:
    type: layout
    defaults: 
      - sak_layout_person_use_entity_picture: false
      - sak_layout_person_icon_color: var(--theme-sys-color-primary)
      - sak_layout_person_icon_color_on: var(--theme-sys-color-error)
      - sak_layout_person_history_disabled: false
      - sak_layout_person_history_color_on: var(--theme-sys-color-error)

  layout:
    aspectratio: 1/1
    toolsets:
      # ================================================================
      - toolset: background-icon
        position:
          cx: 50
          cy: 50
        tools:
          # ------------------------------------------------------------
          - type: 'usersvg'
            position:
              cx: 50
              cy: 30
              height: 100
              width: 100
            clip_path:
              position:
                cx: 50
                cy: 50
                height: 60
                width: 100
                radius:
                  all: 0
            style: 'images'
            images:
              - default: "/local/images/backgrounds/map-background.jpg"
            styles:
              usersvg:
                opacity: 0.8
              mask:
                fill: url(#sak-sparkline-area-mask-tb-0)
      # ==============================================================================
      - toolset: circle-with-icon
        position:
          cx: 20
          cy: 20
        tools:
          # ------------------------------------------------------------
          - type: circle
            position:
              cx: 50
              cy: 50
              radius: 12.5
            entity_index: 0
            animations:
              - state: 'on'
                styles:
                  circle:
                    stroke: var(--theme-sys-color-error)
              - state: 'off'
                styles:
                  circle:
                    # stroke: var(--theme-sys-elevation-surface-neutral10)
                    stroke: '[[sak_layout_person_icon_color]]'
            styles:
              circle:
                stroke-width: 2em
                # stroke: var(--theme-sys-elevation-surface-neutral10)
                stroke: '[[sak_layout_person_icon_color]]'
                fill: var(--primary-background-color)

          # ------------------------------------------------------------
          - type: icon
            position:
              cx: 50
              cy: 50
              align: center
              icon_size: 20
            entity_index: 0
            variables:
              sak_layout_person_use_entity_picture: '[[sak_layout_person_use_entity_picture]]'
              sak_layout_person_icon_color:  '[[sak_layout_person_icon_color]]'
            animations:
                # Return current state, so always a match!
              - state: '[[[ return state; ]]]'
                styles:
                  icon:
                    # Set fill depending on being at home!
                    fill: >
                      [[[ if (['home', 'not_home'].includes(state)) return tool_config.variables.sak_layout_person_icon_color;
                          return 'var(--theme-sys-color-secondary)';
                      ]]]
                    # Hide icon if using entity_picture!
                    display: >
                      [[[ if (tool_config.variables.sak_layout_person_use_entity_picture) return 'none';
                          return 'initial';
                      ]]]
            styles:
              icon:
                fill: var(--theme-sys-color-secondary)
                opacity: 0.9

          # ------------------------------------------------------------
          - type: usersvg
            position:
              cx: 50
              cy: 50
              height: 20
              width: 20
            entity_index: 0
            variables:
              sak_layout_person_use_entity_picture: '[[sak_layout_person_use_entity_picture]]'
            clip_path:
              position:
                cx: 50
                cy: 50
                height: 20            # Slightly crop image (from 45->40)
                width: 20
                radius:
                  all: 10             # Radius 20 results in full circle
            style: 'images'
            images:                   # Fetch entity_picture from config or entity itself
              - default: >
                  [[[
                    if (tool_config.variables.sak_layout_person_use_entity_picture) {
                      return (entity_config?.entity_picture ||
                            entity.attributes?.entity_picture || 'none');
                    } else {
                      return 'none';
                    }
                  ]]]
            animations:
                # Return current state, so always a match!
              - state: '[[[ return state; ]]]'
                image: default
                styles:
                  icon:
                    # Hide usersvg tool if using icon!
                    display: >
                      [[[ if (!tool_config.variables.sak_layout_person_use_entity_picture) return 'none';
                          return 'initial';
                      ]]]

          # - template:
          #     name: tool_valmardav_icon

      # ==============================================================================
      - toolset: name
        position:
          cx: 7.5
          cy: 45
        tools:
          # ------------------------------------------------------------
          - type: name
            position:
              cx: 50
              cy: 50
            entity_index: 0
            show:
              ellipsis: 12
            styles: 
              name: 
                text-anchor: start
                font-size: 12em
                font-weight: 700
                opacity: 1
          # ------------------------------------------------------------
          - type: state
            position:
              cx: 50
              cy: 62.5
            entity_index: 0
            show:
              uom: none
            styles:
              state:
                text-anchor: start
                font-size: 10em
                font-weight: 400
                opacity: 0.6

      # ==============================================================================
      - toolset: alert-time-boxes
        position:
          cx: 50
          cy: 75
        tools:
          # ------------------------------------------------------------
          - type: rectex
            position:
              cx: 20
              cy: 50
              width: 25
              height: 18
              radius:
                left: 5
                right: 0
            entity_index: 0
            animations:
              - state: 'home'
                operator: '!='
                styles:
                  rectex:
                    fill: var(--theme-sys-color-error)
              - state: 'home'
                styles:
                  rectex:
                    fill: var(--theme-sys-elevation-surface-neutral10)
            styles:
              rectex:
                fill: var(--theme-sys-elevation-surface-neutral10)

          # ------------------------------------------------------------
          - type: icon
            position:
              cx: 20
              cy: 50
              align: center
              icon_size: 12.5
            entity_index: 0
            variables:
              zone_ids: '[[sak_layout_person_zone_entities]]'
            animations:
                # Return current state, so always a match!
              - state: '[[[ return state; ]]]'
                # Fetch icon of zone. If no match on zone, the state 'not_home' is given.
                # Check that state, and return the 'not home' icon in that case!
                icon: >
                  [[[ if (state == 'not_home') return 'mdi:home-off-outline';
                      if (state == 'home') return states['zone.home'].attributes.icon;
                      // For not home, we get the friendly name as input. Must find that one to retrieve
                      // the zone's id...

                      for (var i=0; i<tool_config.variables.zone_ids.length; i++) {
                        var zone = states[tool_config.variables.zone_ids[i]];
                        if (zone && zone.attributes.friendly_name == state) {
                          return states[zone.entity_id].attributes.icon;
                        }
                      }
                      return 'mdi:map-marker-question';
                  ]]]
                styles:
                  icon:
                    fill: var(--primary-background-color)
            styles:
              icon:
                fill: var(--primary-background-color)
          # ------------------------------------------------------------
          - type: rectex
            position:
              cx: 64
              cy: 50
              width: 57
              height: 18
              radius:
                left: 0
                right: 5
            entity_index: 0
            animations:
              - state: 'home'
                styles:
                  rectex:
                    fill: var(--theme-sys-elevation-surface-neutral4)
              - state: 'home'
                operator: '!='
                styles:
                  rectex:
                    fill: var(--theme-sys-elevation-surface-error4)
            styles:
              rectex:
                fill: var(--theme-sys-color-on-error)

          # ------------------------------------------------------------
          - type: state
            position:
              cx: 64 #92
              cy: 50
            entity_indexes:
              - entity_index: 1
              - entity_index: 0
            animations:
              - state: 'home'
                entity_index: 0
                styles:
                  state:
                    fill: var(--theme-sys-elevation-surface-neutral10)
              - state: 'home'
                entity_index: 0
                operator: '!='
                styles:
                  state:
                    fill: var(--theme-sys-color-error)
            styles: 
              state:
                # fill: var(--theme-sys-color-error-container)
                fill: var(--theme-sys-color-error)
                font-size: 12em
                text-anchor: middle #end
                # alignment-baseline: middle
                font-weight: 700
              uom:
                # fill: var(--theme-sys-color-error-container)
                fill: var(--theme-sys-color-error)
                alignment-baseline: hanging
                font-weight: 600

      # ==============================================================================
      - toolset: alert-history
        position:
          cx: 50
          cy: 92.5
        tools:
          # ------------------------------------------------------------
          - type: sparkline
            # When disabled, SAK will not use this tool
            disabled: '[[sak_layout_person_history_disabled]]'
            entity_index: 0
            position:
              cx: 50
              cy: 50
              width: 85
              height: 3
              margin: 0
            period:
              calendar:
                period: day
                offset: 0
                duration:
                  hour: 24
                bins:
                  per_hour: 1
            sparkline:
              show:
                chart_type: barcode
                # chart_variant: stalagmites
              state_map:
                template:
                  name: sak_statemap_person
              # State value settings
              # - set agg to max to see the binary changes
              # - set lower_bound to -1 to offset 'off' state
              #   the barcode will start wider now, instead of at minimum width
              # - set upper_bound to 1 ('on') to fix upper scale
              state_values:
                aggregate_func: max
                lower_bound: -1
                upper_bound: 1
              barcode:
                column_spacing: 3
                line_width: 0.1
              colorstops_transition: hard
              colorstops:
                colors:
                  - value: 0
                    color: var(--theme-sys-elevation-surface-neutral10)
                  - value: 1
                    color: '[[sak_layout_person_history_color_on]]'
              styles: 
                tool: 
                  opacity: 1
                barcode_graph:
                  rx: 5
                  ry: 5