Automation for change in numerical state (item added - not removed)

Hey guys,

Im trying to setup an automation that sends a message whenever an item is added.

alias: Film toegevoegd
description: ''
trigger:
  - platform: state
    entity_id: sensor.raspberry_pi_4_plex_library_films
condition: []
action:
  - device_id: xxx
    domain: mobile_app
    type: notify
    title: 
    message: test
mode: single

This works as intended, with one problem, it now also sends a message whenever there is an item removed from the folder.
Anyone knows how to trigger this automation only when an item is added, not removed.

Thanks!

If the state value of sensor.raspberry_pi_4_plex_library_films is a number, representing the quantity of films, you can use a condition to check if the previous value is less than the new value.

The following example uses a Template Condition in shorthand notation:

alias: Film toegevoegd
description: ''
trigger:
  - platform: state
    entity_id: sensor.raspberry_pi_4_plex_library_films
condition: "{{ trigger.to_state.state | int > trigger.from_state.state | int }}"
action:
  - device_id: xxx
    domain: mobile_app
    type: notify
    title: 
    message: test
mode: single

Now it will execute the action only if the new quantity is greater than the previous quantity.

Awesome, that’s it!
Thanks a lot!

1 Like