Hi everyboy,
First, let me explain what i am trying to do. I m triying to automatically add products to my shopping list, by using this great Activity Manager Card.
It should work like this:
- Connect my shopping list (done)
- Install activiy manager and the lovelace card (done)
- Create a lovelace card and introduce some products with their frecuency, which is supposed to be the period to buy the product (done).
- Create a script to automatically add to my shopping list all those products which are due, and restart the period. Here is where i am lost.
Since Activity manager card creates an entity to each product like “activity_manager.CATEGORY_PRODUCT”, mi idea was to get all entities beginning with “activity_manager.CATEGORY_”, compare the due date with the actual date, and restart all the products where it matches. However, sometimes i get no results (i check it should be working with developer tools), and sometimes i get “Call-service not working: connection lost”. I presume this last error may be caused because of the loop.
I am lost here anyway. Can someone help? Find attached a version of the script.
alias: Actualizar Lista de Compra (sin resultados)
sequence:
- service: script.turn_off
entity_id: script.actualizar_lista_de_compra
- variables:
fecha_actual: "{{ now().date().isoformat() }}"
- repeat:
while:
- condition: template
value_template: "{{ entities | length > 0 }}"
sequence:
- variables:
entities: >-
{{ states | selectattr('entity_id', 'startswith',
'activity_manager.lista_de_la_compra_') | list }}
producto: "{{ entities[0].name }}"
fecha: "{{ entities[0].state[:10] }}"
- choose:
- conditions:
- "{{ fecha == fecha_actual }}"
sequence:
- service: shopping_list.add_item
data:
name: "{{ producto }}"
- service: activity_manager.update_activity
data:
name: "{{ producto }}"
category: Lista de la compra
- delay: "00:00:02"
- variables:
entities: "{{ entities[1:] }}"
- service: script.turn_on
entity_id: script.actualizar_lista_de_compra
mode: single