Hello Home Assistant Community,
I’m new to Home Assistant and have been working on an automation to manage a “Restmüll” (waste) todo item using an NFC tag scan. My goal is to be able to scan the trash bin when it is full. Then a todo is beeing added to the wohnung_verlassen todo list. With another automation I read out all the open todos from this list when I leave the house. When I’ve emptied the trash, I want to re-scan the tag and set the todo back to completed. Despite several attempts, I keep running into issues, and I need your help to figure out what I’m doing wrong.
So what I’m Trying to Achieve:
- Scan an NFC Tag: When I scan a specific NFC tag (ID: 20d0ad4f-7b0a-485c-881d-828bbdae4af8), it should:
- Check if the “Restmüll” todo item exists in todo.wohnung_verlassen.
- If it exists, toggle its status between needs_action and completed.
- Send notifications about the actions taken.
What I’ve Tried
Here’s the current version of my automation:
alias: Restmüll Management
description: "Toggle Restmüll task based on NFC tag scan"
trigger:
- platform: tag
tag_id: 20d0ad4f-7b0a-485c-881d-828bbdae4af8
condition: []
action:
- service: notify.mobile_app_pixel_5
data:
message: "NFC Tag scanned: {{ trigger.event.data.tag_id }}"
- service: todo.get_items
target:
entity_id: todo.wohnung_verlassen
data:
status: needs_action
response_variable: mylist
- variables:
restmuell_exists: "{{ 'Restmüll' in mylist['todo.wohnung_verlassen']['items'] | map(attribute='summary') | list }}"
- choose:
- conditions:
- condition: template
value_template: "{{ restmuell_exists }}"
sequence:
- service: todo.get_items
target:
entity_id: todo.wohnung_verlassen
data:
status: needs_action
response_variable: item_status
- variables:
current_status: "{{ item_status['todo.wohnung_verlassen']['items'] | selectattr('summary', 'eq', 'Restmüll') | map(attribute='status') | first }}"
- choose:
- conditions:
- condition: template
value_template: "{{ current_status == 'needs_action' }}"
sequence:
- service: todo.update_item
target:
entity_id: todo.wohnung_verlassen
data:
item: Restmüll
status: completed
- service: notify.mobile_app_pixel_5
data:
message: "Restmüll completed"
- conditions:
- condition: template
value_template: "{{ current_status != 'needs_action' }}"
sequence:
- service: todo.update_item
target:
entity_id: todo.wohnung_verlassen
data:
item: Restmüll
status: needs_action
- service: notify.mobile_app_pixel_5
data:
message: "Restmüll set to needs action"
- conditions:
- condition: template
value_template: "{{ not restmuell_exists }}"
sequence:
- service: todo.add_item
target:
entity_id: todo.wohnung_verlassen
data:
summary: Restmüll
status: needs_action
- service: notify.mobile_app_pixel_5
data:
message: "Restmüll item created and set to needs_action"
- service: notify.mobile_app_pixel_5
data:
message: "End of automation reached with tag: {{ trigger.event.data.tag_id }}"
mode: single
Issues I’m Facing:
Invalid Keys Error:
When trying to update the todo item, I receive the error: extra keys not allowed @ data[‘summary’].
Toggling Status:
Setting the status to completed works, but setting it back to needs_action doesn’t work, and I get the error: extra keys not allowed @ data[‘summary’].
What I’ve Tried
- Ensuring that summary is only included when creating a new todo item.
- Checking and updating the status based on conditions to toggle between needs_action and completed.
Can someone please help me understand why the todo.update_item service call is failing when I try to set the status to needs_action? Any guidance or suggestions on how to properly structure this automation would be greatly appreciated.
Thank you for your assistance!