thiagobruch / HA_Addons

MIT License
9 stars 2 forks source link

Idea: Capitalize the first letter of every item in the list #11

Closed metalmarco closed 1 month ago

metalmarco commented 2 months ago

Alexa has this behavior that every item you add to its shopping list is stored all lowercase. (e.g. "apples" or "bread"). It would be great if before calling the home assistant webhook, this add-on could capitalize the first letter of every item in the list (so "Apples" "Bread"). On the contrary, if you use HA Assist, to add items, they are all capitalized.

Maybe it's just my OCD, but I think it would be a nice touch.

What do you think?

thiagobruch commented 2 months ago

We can try using the HA Automation to capitalize the letters.

I'm not using the Blueprint. I still use the the webhook automation that I created. To capitalize what is coming from Alexa Shopping List, we can use the following:

alias: Shopping List WebHook
description: ""
trigger:
  - platform: webhook
    allowed_methods:
      - POST
      - PUT
    local_only: true
    webhook_id: "<MY_WEBHOOK>"
condition: []
action:
  - action: todo.get_items
    data:
      status:
        - needs_action
        - completed
    response_variable: todo
    target:
      entity_id: todo.shopping_list
  - if:
      - condition: template
        value_template: >-
          {{trigger.json.name | capitalize not in
          todo['todo.shopping_list']['items'] |
                    map(attribute='summary') | list}}
    then:
      - data_template:
          item: "{{ trigger.json.name | capitalize }}"
        target:
          entity_id: todo.shopping_list
        action: todo.add_item
mode: parallel
max: 100
thiagobruch commented 2 months ago

Were you able to try the solution above? If so, did it fix for you?

giakokiko commented 2 months ago

We can try using the HA Automation to capitalize the letters.

I'm not using the Blueprint. I still use the the webhook automation that I created. To capitalize what is coming from Alexa Shopping List, we can use the following:

alias: Shopping List WebHook
description: ""
trigger:
  - platform: webhook
    allowed_methods:
      - POST
      - PUT
    local_only: true
    webhook_id: "<MY_WEBHOOK>"
condition: []
action:
  - action: todo.get_items
    data:
      status:
        - needs_action
        - completed
    response_variable: todo
    target:
      entity_id: todo.shopping_list
  - if:
      - condition: template
        value_template: >-
          {{trigger.json.name | capitalize not in
          todo['todo.shopping_list']['items'] |
                    map(attribute='summary') | list}}
    then:
      - data_template:
          item: "{{ trigger.json.name | capitalize }}"
        target:
          entity_id: todo.shopping_list
        action: todo.add_item
mode: parallel
max: 100

I tested it and it works perfectly. Thanks

metalmarco commented 2 months ago

I can confirm that I edited the Automation as suggest by @thiagobruch and it works perfectly. It would be nice to have this integrated in the repo Blueprint.

thiagobruch commented 1 month ago

@metalmarco The only issue with that is that we would need to add an option in the blueprint to capitalize or not (depending on ones need). I'm not sure we could do that. For now, because it is working using the workaround, I will close this case,

wlucha commented 5 days ago

@thiagobruch Would be awesome if this can be integrated in the blueprint or addon. This project works awesome and I use it to sync Alexa List to Bring via HA. In order that the Bring app is displaying the items correctly, the first letter needs to be capitalized.

Thank you so much for the efforts!

thiagobruch commented 4 days ago

hi @wlucha,

The blueprint with the first letter capitalized would be like this:

blueprint:
  name: Import Alexa shoppinglist
  description: Import Alexa shopping to your Home Assistant shopping list.
  domain: automation
  author: N1c093
  input:
    webhook_trigger:
      name: Webhook Trigger
      description: "Please create a webhook trigger. Other triggers are not supported!"
      selector:
        trigger: {}
    shopping_list:
      name: Shopping List
      description: Which shopping list should receive the entries from the Alexa shopping list?
      selector:
        entity:
          filter:
            domain: todo
mode: parallel
max: 100
variables:
  shopping_list: !input shopping_list
trigger: !input webhook_trigger

action:
  - data: {}
    response_variable: list
    entity_id: !input shopping_list
    action: todo.get_items
  - if:
      - condition: template
        value_template: >-
          {{trigger.json.name | capitalize not in list[shopping_list]["items"] |
          map(attribute="summary") | list }}
    then:
      - entity_id: !input shopping_list
        data:
          item: "{{ trigger.json.name | capitalize }}"
        action: todo.add_item