Hi,
I am using the Our Groceries integration and basically want to receive a notification only when the number of itmes on a shopping list reduces.
The state_changed event data, when adding/deleting an item to/from the shopping list, looks as follows:
event_type: state_changed
data:
entity_id: sensor.our_groceries
old_state:
entity_id: sensor.our_groceries
state: "2"
attributes:
recipes: []
shopping_lists:
- activeCount: 5
name: Test_1
id: JVzC0LxkYgxA52S5OUOJkd
- activeCount: 5
name: Test_2
id: NBugC7PTU0xIy5vnWZBZPd
icon: mdi:format-list-bulleted
friendly_name: our_groceries
last_changed: "2022-09-18T16:09:17.507057+00:00"
last_updated: "2022-09-27T06:46:58.298137+00:00"
context:
id: 01GDYV5QZTXN9KS8MSRDCYD9AS
parent_id: null
user_id: null
new_state:
entity_id: sensor.our_groceries
state: "2"
attributes:
recipes: []
shopping_lists:
- activeCount: 4
name: Test_1
id: JVzC0LxkYgxA52S5OUOJkd
- activeCount: 5
name: Test_2
id: NBugC7PTU0xIy5vnWZBZPd
icon: mdi:format-list-bulleted
friendly_name: our_groceries
last_changed: "2022-09-18T16:09:17.507057+00:00"
last_updated: "2022-09-27T06:54:28.310660+00:00"
context:
id: 01GDYVKFEPG5AABSA79MD9PT4K
parent_id: null
user_id: null
origin: LOCAL
time_fired: "2022-09-27T06:54:28.310660+00:00"
context:
id: 01GDYVKFEPG5AABSA79MD9PT4K
parent_id: null
user_id: null
For my template condition I want to compare the number of the attribute “activeCount” within old_state and new_state but I have no idea how to access this data. At the moment, my (non working) condition template looks like this:
- id: '1664202964250'
alias: Benachrichtigung Einkaufsliste
description: ''
trigger:
- platform: state
entity_id:
- sensor.our_groceries
attribute: shopping_lists
condition:
- condition: template
value_template: "{{ trigger.event.data.old_state_attributes.shopping_lists.name == 'Test_1' }}"
- condition: template
value_template: "{{ trigger.event.data.old_state_attributes.shopping_lists.activeCount > trigger.event.data.old_state_attributes.shopping_lists.activeCount }}"
action:
- service: notify.mobile_app_iphone
data:
message: Item on shopping list was removed
title: Shopping List
mode: single
Could anybody point me in the right direction?