Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # lovelace_gen
- ############################################################
- #### Lights Glances by J-Lindvig ####
- ############################################################
- #### PLUGINS NEEDED ####
- # Lovelace Gen, https://github.com/thomasloven/hass-lovelace_gen
- # Stack In Card, https://github.com/custom-cards/stack-in-card
- # browser_mod, https://github.com/thomasloven/hass-browser_mod
- # state-switch, https://github.com/thomasloven/lovelace-state-switch
- # Make a 2D array ( a list containing lists) with the rooms and
- # their lights.
- # The first element is the entity for all entities i a room, ex:
- # light.kokken is a light group which contains all lights in the kitchen
- # If a room only has 1 light, then there is only 1 element int the list
- {% set rooms = {
- "Stuen": ["light.hue_color_spisebord"],
- "Gangen": ["light.huego_tv1"]
- } %}
- # Macro that makes a Glance card
- # It takes a string that it uses to find the wanted room in the list of rooms
- {%- macro glance(room) %}
- type: glance
- show_state: false
- {%- if (rooms[room] | length) > 4 %}
- columns: 4
- {%- endif %}
- entities:
- # If the list contains more than 1 element
- # Loop all elements - except the first,
- # which is the enity of the entire room
- # Call the macro entity with the pregiven string "room"
- # and the current light
- #
- # else call the macro entity with the pregiven string "room"
- # and the first element in the found list with the key "room"
- {%- if (rooms[room] | length ) > 1 %}
- {%- for light in rooms[room] %}
- {%- if not loop.first -%}
- {{ entity(room, light) }}
- {%- endif %}
- {%- endfor %}
- {%- else -%}
- {{ entity(room, rooms[room][0]) }}
- {%- endif %}
- {% endmacro %}
- # Macro entity takes a string og the wanted room
- # and a entity of the given light
- #
- # The macro macro makes an enity and calls
- # the macro open_slider with the room
- {%- macro entity(room, light) %}
- - entity: {{ light }}
- tap_action:
- action: toggle
- hold_action:
- {{ open_slider(room) }}
- double_tap_action:
- {{ open_slider(room) }}
- {% endmacro %}
- # open_slider takes a string with the wanted room
- {%- macro open_slider(room) -%}
- action: call-service
- service: browser_mod.popup
- service_data:
- title: Indstilling af lys
- style:
- border-radius: 20px
- --ha-card-border-radius: 20px
- card:
- type: entities
- # The title of the room
- title: {{ room }}
- show_header_toggle: true
- entities:
- # If the list contains more than 1 element
- # Loop all elements - except the first,
- # which is the enity of the entire room
- # Make a slider-entity- element with the given light
- #
- # else make a slider-entity- element with the
- # first element in the found list with the key "room"
- {%- if (rooms[room] | length ) > 1 %}
- {%- for light in rooms[room] %}
- {%- if not loop.first %}
- - type: custom:slider-entity-row
- entity: {{ light }}
- {%- endif %}
- {%- endfor %}
- {% else %}
- - type: custom:slider-entity-row
- entity: {{ rooms[room][0] }}
- {% endif %}
- deviceID:
- - this
- {%- endmacro %}
- # Stack the vertical
- type: custom:stack-in-card
- cards:
- # input_select to choose the room
- - type: entities
- entities:
- - input_select.room_light
- # state-switch to change the card
- - type: custom:state-switch
- entity: input_select.room_light
- states:
- # Call the macro with the string
- Stuen:
- {{ glance("Stuen") }}
- Gangen:
- {{ glance("Gangen") }}
Add Comment
Please, Sign In to add comment