View difference between Paste ID: sXEa4bEJ and FQGkrfTR
SHOW: | | - or go back to the newest paste.
1
# lovelace_gen
2
############################################################
3
####           Lights Glances by J-Lindvig              ####
4
############################################################
5
6
#### PLUGINS NEEDED ####
7
# Lovelace Gen, https://github.com/thomasloven/hass-lovelace_gen
8
# Stack In Card, https://github.com/custom-cards/stack-in-card
9
# browser_mod, https://github.com/thomasloven/hass-browser_mod
10
# state-switch, https://github.com/thomasloven/lovelace-state-switch
11
12
# Make a 2D array ( a list containing lists) with the rooms and
13
# their lights.
14
# The first element is the entity for all entities i a room, ex:
15
# light.kokken is a light group which contains all lights in the kitchen
16
# If a room only has 1 light, then there is only 1 element int the list
17
{% set rooms = {
18
  "Stuen": ["light.hue_color_spisebord"],
19-
  "Gangen": ["light.huego_tv1"],
19+
  "Gangen": ["light.huego_tv1"]
20
} %}
21
22
# Macro that makes a Glance card
23
# It takes a string that it uses to find the wanted room in the list of rooms
24
{%- macro glance(room) %}
25
        type: glance
26
        show_state: false
27
        {%- if (rooms[room] | length) > 4 %}
28
        columns: 4
29
        {%- endif %}
30
        entities:
31
        # If the list contains more than 1 element
32
        # Loop all elements - except the first,
33
        # which is the enity of the entire room
34
        # Call the macro entity with the pregiven string "room"
35
        # and the current light
36
        #
37
        # else call the macro entity with the pregiven string "room"
38
        # and the first element in the found list with the key "room"
39
        {%- if (rooms[room] | length ) > 1 %}
40
          {%- for light in rooms[room] %}
41
            {%- if not loop.first -%}
42
              {{ entity(room, light) }}
43
            {%- endif %}
44
          {%- endfor %}
45
        {%- else -%}
46
          {{ entity(room, rooms[room][0]) }}
47
        {%- endif %}
48
{% endmacro %}
49
50
# Macro entity takes a string og the wanted room
51
# and a entity of the given light
52
#
53
# The macro macro makes an enity and calls
54
# the macro open_slider with the room
55
{%- macro entity(room, light) %}
56
          - entity: {{ light }}
57
            tap_action:
58
              action: toggle
59
            hold_action:
60
              {{ open_slider(room) }}
61
            double_tap_action:
62
              {{ open_slider(room) }}
63
{% endmacro %}
64
65
# open_slider takes a string with the wanted room
66
{%- macro open_slider(room) -%}
67
              action: call-service
68
              service: browser_mod.popup
69
              service_data:
70
                title: Indstilling af lys
71
                style:
72
                  border-radius: 20px
73
                  --ha-card-border-radius: 20px
74
                card:
75
                  type: entities
76
                  # The title of the room
77
                  title: {{ room }}
78
                  show_header_toggle: true
79
                  entities:
80
                  # If the list contains more than 1 element
81
                  # Loop all elements - except the first,
82
                  # which is the enity of the entire room
83
                  # Make a slider-entity- element with the given light
84
                  #
85
                  # else make a slider-entity- element with the
86
                  # first element in the found list with the key "room"
87
                  {%- if (rooms[room] | length ) > 1 %}
88
                    {%- for light in rooms[room] %}
89
                      {%- if not loop.first %}
90
                    - type: custom:slider-entity-row
91
                      entity: {{ light }}
92
                      {%- endif %}
93
                    {%- endfor %}
94
                  {% else %}
95
                    - type: custom:slider-entity-row
96
                      entity: {{ rooms[room][0] }}
97
                  {% endif %}  
98
                deviceID:
99
                  - this
100
{%- endmacro %}
101
102
# Stack the vertical
103
type: custom:stack-in-card
104
cards:
105
  # input_select to choose the room
106
  - type: entities
107
    entities:
108
      - input_select.room_light
109
  # state-switch to change the card
110
  - type: custom:state-switch
111
    entity: input_select.room_light
112
    states:
113
      # Call the macro with the string
114
      Stuen:
115
        {{ glance("Stuen") }}
116
      Gangen:
117
        {{ glance("Gangen") }}
118