Skip to content

Instantly share code, notes, and snippets.

@hectorzin
Last active February 25, 2024 16:19
Show Gist options
  • Save hectorzin/f9a1803a510a2d8253fdd5e6a085cbd8 to your computer and use it in GitHub Desktop.
Save hectorzin/f9a1803a510a2d8253fdd5e6a085cbd8 to your computer and use it in GitHub Desktop.
Shopping list
alias: Bring - Actualizar sensor de texto con lista de la compra
description: ""
trigger:
- platform: state
entity_id: todo.bring_todo_la_compra
action:
- service: todo.get_items
target:
entity_id: todo.bring_todo_la_compra
data:
status: needs_action
response_variable: incompleted
- variables:
incompleted_items: |
{%- for item in incompleted['todo.bring_todo_la_compra']['items'] -%}
{{ item.summary }};
{%- endfor -%}
- service: input_text.set_value
target:
entity_id: input_text.lista_compra
data:
value: "{{ incompleted_items }}"
- service: todo.get_items
target:
entity_id: todo.bring_todo_la_compra
data:
status: completed
response_variable: completed
- variables:
completed_items: |
{%- for item in completed['todo.bring_todo_la_compra']['items'] -%}
{{ item.summary }};
{%- endfor -%}
- service: input_text.set_value
target:
entity_id: input_text.lista_compra_completado
data:
value: "{{ completed_items }}"
type: vertical-stack
cards:
- type: custom:bubble-card
card_type: pop-up
hash: '#catalogue'
icon: mdi:view-grid
name: Catálogo
- type: custom:swipe-card
cards:
- type: custom:auto-entities
show_empty: false
card_param: cards
card:
square: false
type: grid
columns: 3
filter:
template: |-
{% set ns = namespace(result = [], categories = {}) %}
{% set categories = states
|selectattr('object_id', 'contains', 'shopping_list_cat')
|sort(attribute='attributes.friendly_name')
|map(attribute='entity_id')
|list
%}
{% for cat in categories -%}
{%- set name_cat = (state_attr(cat,'friendly_name')).split("Shopping List - cat - ")[1] -%}
{%- set icon_cat = state_attr(cat,'icon') -%}
{% for i in range(1, 4) %}
{%- if i==2 -%}
{% set ns.result = ns.result + [
{
'type': 'custom:mushroom-template-card',
'secondary': name_cat,
'icon': icon_cat,
'layout': 'vertical',
'card_mod': {
'style': 'ha-card { background: linear-gradient( rgba(131, 58, 180, 1), rgba(4, 80, 236, 1) ); --icon-size: 0px; --card-secondary-font-size: 15px; --secondary-text-color: #ffffff;};',
},
}
]%}
{%- else -%}
{% set ns.result = ns.result + [
{
'type': 'custom:mushroom-template-card',
'secondary': none,
'icon': icon_cat,
'layout': 'vertical',
'card_mod': {
'style': 'ha-card { background: linear-gradient( rgba(131, 58, 180, 1), rgba(4, 80, 236, 1) ); --icon-size: 28px; --card-secondary-font-size: 15px; --secondary-text-color: #ffffff;};',
},
}
]%}
{%- endif %}
{%- endfor %}
{% set items = states(cat).split(",") | sort -%}
{% set list = states('input_text.lista_compra') %}
{% for group in items | batch(3, fill_with="blank") -%}
{% for item in group -%}
{%- set name_item = item | replace ('.','') -%}
{%- set picture = 'local/Shopping List/'+ name_item +'.png' -%}
{% if item == 'blank' -%}
{% set ns.result = ns.result + [
{
'type': 'custom:mushroom-template-card',
'entity': 'sensor.bought_items_number',
'secondary': "",
'multiline_secondary': 'true',
'picture': none,
'layout': 'vertical',
'fill_container': 'true',
'tap_action': {
'action': 'none',
},
'card_mod': {
'style': 'ha-card { background: linear-gradient( rgba(91, 91, 91, 0), rgba(91, 91, 91, 0) ); --icon-size: 0px; --card-secondary-font-size: 0px; --secondary-text-color: #ffffff;};',
},
}
]%}
{%- elif item in list -%}
{% set ns.result = ns.result + [
{
'type': 'custom:mushroom-template-card',
'entity': 'sensor.bought_items_number',
'secondary': name_item,
'multiline_secondary': 'true',
'picture': picture,
'layout': 'vertical',
'fill_container': 'true',
'tap_action': {
'action': 'none',
},
'card_mod': {
'style': 'ha-card { background: linear-gradient( rgba(238, 82, 79, 1), rgba(181, 42, 39, 1) ); --icon-size: 60px; --card-secondary-font-size: 12px; --secondary-text-color: #ffffff;};',
},
}
]%}
{%- else -%}
{% set ns.result = ns.result + [
{
'type': 'custom:mushroom-template-card',
'entity': 'sensor.bought_items_number',
'secondary': name_item,
'multiline_secondary': 'true',
'picture': picture,
'layout': 'vertical',
'fill_container': 'true',
'tap_action': {
'action': 'call-service',
'service': 'todo.add_item',
'target': {
'entity_id': 'todo.bring_todo_la_compra'},
'data': { 'item': name_item}
},
'card_mod': {
'style': 'ha-card { background: linear-gradient( rgba(79, 171, 162, 1), rgba(38, 133, 124, 1) ); --icon-size: 60px; --card-secondary-font-size: 11px; --secondary-text-color: #ffffff; };',
},
}
]%}
{%- endif -%}
{%- endfor %}
{%- endfor %}
{%- endfor %}
{{ ns.result }}
- type: custom:auto-entities
show_empty: false
card:
square: true
type: grid
columns: 3
card_param: cards
filter:
template: |-
{% set items = ((states
|selectattr('object_id', 'contains', 'shopping_list_cat')
|map(attribute='state'))
|list
|join(',')).split(',')
|sort
%}
{% set list = states('input_text.lista_compra') %}
{% for item in items -%}
{%- set product = item -%}
{%- set picture = 'local/Shopping List/'+ product +'.png' -%}
{%- if item in list -%}
{{
{
'type': 'custom:mushroom-template-card',
'entity': 'sensor.bought_items_number',
'secondary': product,
'multiline_secondary': 'true',
'picture': picture,
'layout': 'vertical',
'fill_container': 'true',
'tap_action': {
'action': 'none',
},
'card_mod': {
'style': 'ha-card { background: linear-gradient( rgba(238, 82, 79, 1), rgba(181, 42, 39, 1) ); --icon-size: 60px; --card-secondary-font-size: 12px; --secondary-text-color: #ffffff;};',
},
}
}},
{%- else -%}
{{
{
'type': 'custom:mushroom-template-card',
'entity': 'sensor.bought_items_number',
'secondary': product,
'multiline_secondary': 'true',
'layout': 'vertical',
'fill_container': 'true',
'picture': picture,
'tap_action': {
'action': 'call-service',
'service': 'todo.add_item',
'target': {
'entity_id': 'todo.bring_todo_la_compra'},
'data': { 'item': product}
},
'card_mod': {
'style': 'ha-card { background: linear-gradient( rgba(79, 171, 162, 1), rgba(38, 133, 124, 1) ); --icon-size: 60px; --card-secondary-font-size: 11px; --secondary-text-color: #ffffff; };',
},
}
}},
{%- endif -%}
{%- endfor %}
lista_compra:
name: "Lista de la compra"
min: 0
max: 5000
lista_compra_completado:
name: "Lista de la compra completado"
min: 0
max: 5000
square: false
type: grid
columns: 3
cards:
- type: custom:mushroom-template-card
primary: Catálogo
secondary: ''
icon: mdi:view-grid
tap_action:
action: navigate
navigation_path: '#catalogue'
layout: vertical
icon_color: white
card_mod:
style: |
ha-card {
background: linear-gradient( rgba(83, 125, 182, 1), rgba(62, 94, 140, 1) );
--primary-text-color: #ffffff;
}
- type: custom:mushroom-template-card
primary: Recientes
secondary: ''
icon: mdi:history
tap_action:
action: navigate
navigation_path: '#bought_items'
layout: vertical
icon_color: white
card_mod:
style: |
ha-card {
background: linear-gradient( rgba(79, 171, 162, 1), rgba(38, 133, 124, 1) );
--primary-text-color: #ffffff;
}
- type: custom:mushroom-template-card
primary: Recetas
secondary: ''
icon: mdi:creation
tap_action:
action: navigate
navigation_path: '#recipes'
layout: vertical
icon_color: white
card_mod:
style: |
ha-card {
background: linear-gradient( rgba(143, 184, 84, 1), rgba(107, 139, 62, 1) );
--primary-text-color: #ffffff;
}
type: conditional
conditions:
- entity: todo.bring_todo_la_compra
state_not: '0'
card:
type: vertical-stack
cards:
- type: custom:bubble-card
card_type: separator
name: Productos en la lista de la compra
icon: mdi:shopping
- type: custom:auto-entities
show_empty: false
card:
square: true
type: grid
columns: 3
card_param: cards
filter:
template: |-
{%- set LISTA = states('input_text.lista_compra') -%}
{%- set ITEMS = states('todo.bring_todo_la_compra') | int -%}
{%- for INDEX in range(ITEMS) -%}
{%- set product_total = LISTA.split(';')[INDEX] -%}
{%- set product = product_total.split(':')[0] -%}
{%- set picture = 'local/Shopping List/'+ product +'.png' -%}
{{
{
'type': 'custom:mushroom-template-card',
'entity': 'todo.bring_todo_la_compra',
'secondary': product_total,
'multiline_secondary': 'true',
'picture': picture,
'layout': 'vertical',
'fill_container': 'true',
'tap_action': {
'action': 'call-service',
'service': 'todo.update_item',
'target': {
'entity_id': 'todo.bring_todo_la_compra'},
'data': { 'item': product_total,'status': 'completed'}
},
'card_mod': {
'style': 'ha-card { background: linear-gradient( rgba(238, 82, 79, 1), rgba(181, 42, 39, 1) ); --icon-size: 60px; --card-secondary-font-size: 11px; --secondary-text-color: #ffffff; };',
},
}
}},
{%- endfor %}
ingredients:
name: "Ingredientes"
min: 0
max: 2000
shopping_list_recipe_salmon:
name: "Shopping List-recipe-Salmón al horno macerado con miel y soja"
min: 0
max: 2000
initial: "Salmón;Salsa de soja;Miel;Jengibre;Cebollas;Pimiento rojo"
shopping_list_recipe_calamarcitos:
name: "Shopping List-recipe-Calamarcitos patagónicos al ajillo"
min: 0
max: 2000
initial: "Calamarcitos: 500gr;Ajo;Cayena;Perejil"
type: vertical-stack
cards:
- type: custom:bubble-card
card_type: pop-up
hash: '#bought_items'
icon: mdi:history
name: Compras recientes
- type: custom:auto-entities
show_empty: false
card:
square: true
type: grid
columns: 3
card_param: cards
filter:
template: |-
{% set LISTA = states('input_text.lista_compra_completado') %}
{% for INDEX in range(LISTA.split(';')|length-1) -%}
{%- set product_total = LISTA.split(';')[INDEX] -%}
{%- set product = product_total.split(':')[0] -%}
{%- set picture = 'local/Shopping List/'+ product +'.png' -%}
{{
{
'type': 'custom:mushroom-template-card',
'entity': 'sensor.bought_items_number',
'secondary': product_total,
'multiline_secondary': 'true',
'picture': picture,
'layout': 'vertical',
'fill_container': 'true',
'tap_action': {
'action': 'call-service',
'service': 'todo.update_item',
'target': {
'entity_id': 'todo.bring_todo_la_compra'},
'data': { 'item': product_total,'status': 'needs_action'}
},
'card_mod': {
'style': 'ha-card { background: linear-gradient( rgba(79, 171, 162, 1), rgba(38, 133, 124, 1) ); --icon-size: 60px; --card-secondary-font-size: 11px; --secondary-text-color: #ffffff; };',
},
}
}},
{%- endfor %}
alias: Actualiza ingredientes receta
sequence:
- service: todo.get_items
target:
entity_id: todo.la_compra
data:
status: needs_action
response_variable: incompleted
- variables:
items_to_add: >
{% for INDEX in
range((states('input_text.ingredients')).split(';')|length-1) -%}
{% set ns = namespace(found=false) %}
{%- set product_total = (states('input_text.ingredients')).split(';')[INDEX] -%}
{%- set product = product_total.split(':')[0] -%}
{%- for item in incompleted['todo.la_compra']['items'] -%}
{%- if item.summary|capitalize == product|capitalize -%}
{% set ns.found = true %}
{%- endif -%}
{%- endfor -%}
{%- if not ns.found -%}
{{ product|capitalize }};
{%- endif -%}
{%- endfor -%}
- repeat:
for_each: "{{ (items_to_add).split(';') | list }}"
sequence:
- condition: template
value_template: "{{ repeat.item != \"\" }}"
- service: todo.add_item
target:
entity_id: todo.la_compra
data:
item: "{{ repeat.item }}"
enabled: true
mode: single
shopping_list_cat_verduras:
name: "Shopping List - cat - Verduras"
initial: "Cebollas,Tomates,Pepino,Pimiento,Calabacín"
icon: "mdi:sprout"
min: 0
max: 2000
shopping_list_cat_frutas:
name: "Shopping List - cat - Frutas"
initial: "Plátanos,Aguacate,Uvas,Limón,Naranja"
icon: "mdi:fruit-grapes"
min: 0
max: 2000
shopping_list_cat_pan_y_pasteles:
name: "Shopping List - cat - Pan y pasteles"
icon: "mdi:baguette"
min: 0
max: 2000
shopping_list_cat_lacteos:
name: "Shopping List - cat - Lácteos"
icon: "mdi:cheese"
min: 0
max: 2000
shopping_list_cat_carne:
name: "Shopping List - cat - Carne"
initial: "Albóndigas,Bistec,Bacón,Butifarra,Bratwurst,Carne,Pollo,Salchicha,Ternera,Cordero"
icon: "mdi:food-steak"
min: 0
max: 2000
shopping_list_cat_pescado:
name: "Shopping List - cat - Pescado"
initial: "Anchoas,Atún,Calamares,Boquerones,Bogavante,Dorada,Gambas,Sepia,Merluza"
icon: "mdi:fish"
min: 0
max: 2000
shopping_list_cat_ingredientes_y_especias:
name: "Shopping List - cat - Ingredientes y especias"
initial: "Aceite,Vinagre,Sal,Azúcar,Sacarina,Azafrán,Pimienta,Curry,Eneldo,Tomillo,Romero,Pimentón,Salsa de soja,Vainilla,Canela"
icon: "mdi:spoon-sugar"
min: 0
max: 2000
shopping_list_cat_congelados_y_preparados:
name: "Shopping List - cat - Congelados y preparados"
initial: "Canelones,Alitas de pollo,Pizza,Doritos,Ensaladilla rusa,Patatas fritas"
icon: "mdi:french-fries"
min: 0
max: 2000
shopping_list_cat_cereales_y_pasta:
name: "Shopping List - cat - Cereales y pasta"
initial: "Arroz,Macarrones,Garbanzos,Fideos,Espaguetis,Harina"
icon: "mdi:barley"
min: 0
max: 2000
shopping_list_cat_aperitivos_y_dulces:
name: "Shopping List - cat - Aperitivos y dulces"
initial: "Patatas chips,Nachos,Chuches,Chocolate,Mermelada,Miel,Pipas,Palomitas"
icon: "mdi:popcorn"
min: 0
max: 2000
shopping_list_cat_bebidas:
name: "Shopping List - cat - Bebidas"
initial: "Cerveza,Clara,Cola,Vino,Agua,Zumo de naranja,Horchata"
icon: "mdi:beer"
min: 0
max: 2000
shopping_list_cat_drogueria:
name: "Shopping List - cat - Droguería"
initial: "Alcohol,Amoníaco,Bolsas de basura,Detergente de lavadora,Estropajo,Papel de aluminio,Papel de cocina,Suavizante,Papel hijiénico"
icon: "mdi:broom"
min: 0
max: 2000
shopping_list_cat_aseo_y_salud:
name: "Shopping List - cat - Aseo y salud"
initial: "Acondicionador,Champú,Gel,Pasta de dientes,Compresas,Tampón,Desodorante"
icon: "mdi:toothbrush"
min: 0
max: 2000
shopping_list_cat_mascotas:
name: "Shopping List - cat - Mascotas"
initial: "Alpiste,Arena,Comida para perros,Comida de gato,Golosinas para perros,Golosinas para gato,Pienso"
icon: "mdi:dog"
min: 0
max: 2000
shopping_list_cat_jardin_y_hogar:
name: "Shopping List - cat - Jardín y hogar"
initial: "Carbón,Pastillas barbacoa"
icon: "mdi:grill"
min: 0
max: 2000
type: vertical-stack
cards:
- type: custom:bubble-card
card_type: pop-up
hash: '#recipes_items'
icon: mdi:food-variant
name: Ingredientes
- type: custom:auto-entities
show_empty: false
card:
square: true
type: grid
columns: 3
card_param: cards
filter:
template: |-
{% set LISTA = states('input_text.ingredients') %}
{% set nombre = LISTA.split('|') %}
{% set list = states('input_text.lista_compra') %}
{% for INDEX in range(LISTA.split(';')|length-1) -%}
{%- set product_total = LISTA.split(';')[INDEX] -%}
{%- set product = product_total.split(':')[0] -%}
{%- set picture = 'local/Shopping List/'+ product +'.png' -%}
{%- if product in list -%}
{{
{
'type': 'custom:mushroom-template-card',
'entity': 'sensor.bought_items_number',
'secondary': product_total,
'multiline_secondary': 'true',
'picture': picture,
'layout': 'vertical',
'fill_container': 'true',
'tap_action': {
'action': 'none',
},
'card_mod': {
'style': 'ha-card { background: linear-gradient( rgba(238, 82, 79, 1), rgba(181, 42, 39, 1) ); --icon-size: 60px; --card-secondary-font-size: 12px; --secondary-text-color: #ffffff;};',
},
}
}},
{%- else -%}
{{
{
'type': 'custom:mushroom-template-card',
'entity': 'sensor.bought_items_number',
'secondary': product_total,
'multiline_secondary': 'true',
'picture': picture,
'layout': 'vertical',
'fill_container': 'true',
'tap_action': {
'action': 'call-service',
'service': 'todo.add_item',
'target': {
'entity_id': 'todo.la_compra'},
'data': { 'item': product}
},
'card_mod': {
'style': 'ha-card { background: linear-gradient( rgba(79, 171, 162, 1), rgba(38, 133, 124, 1) ); --icon-size: 60px; --card-secondary-font-size: 11px; --secondary-text-color: #ffffff; };',
},
}
}},
{%- endif -%}
{%- endfor %}
- type: custom:mushroom-template-card
secondary: Añadir todos los ingredientes
entity: script.1708859554201
icon: mdi:all-inclusive-box
tap_acton:
action: call-service
service: script.1708859554201
card_mod:
style: >-
ha-card { text-align: center; background: linear-gradient( rgba(131, 58,
180, 1), rgba(4, 80, 236, 1) ); --icon-size: 0px;
--card-secondary-font-size: 15px; --secondary-text-color: #ffffff;};
type: vertical-stack
cards:
- type: custom:bubble-card
card_type: pop-up
hash: '#recipes'
icon: mdi:pizza
name: Recetas
- type: custom:auto-entities
show_empty: false
card:
square: true
type: grid
columns: 3
card_param: cards
filter:
template: |-
{% set ns = namespace(result = [], recipes = {}) %}
{% set recipes = states
|selectattr('object_id', 'contains', 'shopping_list_recipe')
|sort(attribute='attributes.friendly_name')
|map(attribute='entity_id')
|list
%}
{% for recipe in recipes -%}
{%- set name_recipe= (state_attr(recipe,'friendly_name')).split("Shopping List-recipe-")[1] -%}
{%- set recipe_items=(states(recipe)) -%}
{%- set picture = '/local/Shopping List/Recipes/'+ name_recipe +'.jpg' -%}
{%- set ns.result = ns.result + [
{
'type': 'custom:button-card',
'name': name_recipe,
'tap_action': {
'action': 'custom',
'custom': '[[[ hass.callService("input_text","set_value",{ entity_id: "input_text.ingredients", value: "'+recipe_items+'"}); window.history.pushState(null,"","#recipes_items"); window.dispatchEvent(new CustomEvent("location-changed"));]]]',
},
'styles': {
'card': [{
'width': '100%',
'height': '100%',
'font-size': '13px',
'color': 'white',
'background-image': 'url("'+picture+'")',
'background-size': 'cover',
'text-shadow': '1px 1px 1px rgba(0, 0, 0, 1),-1px -1px 1px rgba(0, 0, 0, 1),1px -1px 1px rgba(0, 0, 0, 1),-1px 1px 1px rgba(0, 0, 0, 1);',
}],
'name': [{
'padding-top': '70%',
}],
},
}
] -%}
{%- endfor -%}
{{ ns.result }}
type: custom:mushroom-template-card
primary: '{{ states(''todo.bring_todo_la_compra'') }} productos'
secondary: Lista de la compra
icon: mdi:shopping
entity: todo.bring_todo_la_compra
icon_color: |-
{% if states('todo.bring_todo_la_compra') | int >= 15 %} white
{% endif %}
layout: vertical
fill_container: false
tap_action:
action: navigate
navigation_path: /dashboard-casa/lista-de-la-compra
card_mod:
style: |
{% if states('todo.bring_todo_la_compra') | int >= 15 %}
ha-state-icon {
animation: beat 2s ease-out infinite both;
transform-origin: 50% 50%;
}
@keyframes beat {
0% { transform: scale(1); }
10% { transform: scale(1.2); }
17% { transform: scale(1.05); }
33% { transform: scale(1.30); }
60% { transform: scale(1); }
}
ha-card {
--primary-text-color: #ffffff;
--secondary-text-color: #ffff00;
background: linear-gradient( rgba(238, 82, 79, 1), rgba(181, 42, 39, 1) ) }}');
}
{% endif %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment