Pet vibration sensor alert if my dog eat

Hi
I have next automation
The problem i get 5-6-7 notification in the raw
What I need to do to get 1 notification in 10 minutes ?

- id: '1584303212158'
  alias: Someone Eating
  trigger:
  - event_data:
      entity_id: binary_sensor.vibration_158d0002c4c833
      movement_type: vibrate
    event_type: xiaomi_aqara.movement
    platform: event
  action:
  - data:
      message: Someone eating !
    service: notify.mobile_app1
  - data:
      message: Someone eating !
    service: notify.mobile_app2

Have a look at the alert integration

You could also have a condition that checks whether the last time the automation fired was longer than X minutes ago. I’m not sure about the template syntax for that though.

Add a condition:

  condition:
  - condition: template # only notify once every 10 minutes at most
    value_template: "{{ ( as_timestamp(now()) - as_timestamp(state_attr('automation.someone_eating', 'last_triggered')) |int(0) ) > 600 }}"
1 Like

Hi
Its not work… you maybe know why ?

- id: '1584303212158'
  alias: Someone Eating
  trigger:
  - event_data:
      entity_id: binary_sensor.vibration_158d0002c4c833
      movement_type: vibrate
    event_type: xiaomi_aqara.movement
    platform: event
  condition:
  - condition: template
    value_template: 'value_template: "{{ ( as_timestamp(now()) - as_timestamp(state_attr(''automation.someone_eating'',
      ''last_triggered'')) |int(0) ) > 600 }}"'
  action:
  - data:
      message: Someone eating !
    service: notify.mobile_app1
  - data:
      message: Someone eating !
    service: notify.mobile_app2

Edit: formatting

The value_template is wrong, should be

"{{ ( as_timestamp(now()) - as_timestamp(state_attr(''automation.someone_eating'', ''last_triggered'')) |int(0) ) > 600 }}"

It is not work my friend

image

So many quotes!

Also, it should all be on a single line. The forum is making it multiple lines due to word wrap and formatting. Make sure you have it all on a single line.

As for the quotes…that’s just how the built-in editor does things…so that part is ok, even if it looks weird.

"{{ ( as_timestamp(now()) - as_timestamp(state_attr('automation.someone_eating', 'last_triggered')) |int(0) ) > 600 }}"

Hi @jocnnor @Skye @tom_l
Your solution work great
But in after 1 month i have issue when i fill the pet food

I not want notify if the vibration alert 1 times
Only from 3 and up

I try to add

- id: '1584303212158'
  alias: someone_eating
  trigger:
  - event_data:
      entity_id: binary_sensor.vibration_158d0002c4c833
      movement_type: vibrate
    event_type: xiaomi_aqara.movement
    platform: event
  condition:
  - condition: template
    value_template: '{{ ( as_timestamp(now()) - as_timestamp(state_attr(''automation.someone_eating'',''last_triggered''))
      |int(0) ) > 600 }}'
  - condition: and
    conditions:
    - above: '3 '
      condition: numeric_state
      entity_id: binary_sensor.vibration_158d0002c4c833
  action:
  - data:
      message: Someone is eating!
    service: notify.mobile_app1
  - data:
      message: Someone is eating!
    service: notify.mobile_app_mi2

But its not work for me
You know maybe why ?

A binary_sensor is only ever ‘on’, or ‘off’. It can’t ever be “above 3”.

I guess, make an input_number and increment it, then only alert if the number is > 3.

# In configuration.yaml
input_number:
  food_eat_counter:
    min: 0
    max: 10
# In automations
- alias: reset_food_counter
  trigger:
    platform: time
    at: "00:00:00"
  action:
    service: input_number.set_value
    data:
      entity_id: input_number.food_eat_counter
      value: 0

- id: '1584303212158'
  alias: someone_eating
  trigger:
  - event_data:
      entity_id: binary_sensor.vibration_158d0002c4c833
      movement_type: vibrate
    event_type: xiaomi_aqara.movement
    platform: event
  condition:
  - condition: template
    value_template: '{{ ( as_timestamp(now()) - as_timestamp(state_attr(''automation.someone_eating'',''last_triggered'')) |int(0) ) > 600 }}'
  action:
  # Increment the counter
  - service: input_number.set_value
    data_template:
      entity_id: input_number.food_eat_counter
      value: "{{ states('input_number.food_eat_counter') | int + 1}}"
  # Only continue if the counter > 3
  - condition: template
    value_template: "{{ states('input_number.food_eat_counter') | int > 3 }}"
  - data:
      message: Someone is eating!
    service: notify.mobile_app1
  - data:
      message: Someone is eating!
    service: notify.mobile_app_mi2

Thanks

The food_eat_counter not work good
food_eat_counter going up by one only after 10 minute (600 sec)

For exapmple , if i trigger the vibration motion
18:08 - trigger the vibration 7 times - the counter up by one
18:13 - trigger the vibration -3 times - the counter not up
18:19 -trigger the vibration 5 times - the counter now is two

After all iiterattion the counter not back to zero

I want the final result be
"in 10 minutes if the vibration was on 3 times or more - send push message "
after 10 minute from the last vibration was on. the timer need to init back to 0

# In configuration.yaml
input_number:
  food_eat_counter:
    min: 0
    max: 10

# Also in configuraiton.yaml
timer:
  food_eat_timer:
    duration: "00:10:00"


# In automations
# Reset this counter after the 10 minute timer expires.
- alias: reset_food_counter
  trigger:
  - platform: event
    event_type: timer.finished
    event_data:
      entity_id: timer.food_eat_timer
  action:
    - service: input_number.set_value
      data:
        entity_id: input_number.food_eat_counter
        value: 0

- id: '1584303212158'
  alias: someone_eating
  trigger:
  - event_data:
      entity_id: binary_sensor.vibration_158d0002c4c833
      movement_type: vibrate
    event_type: xiaomi_aqara.movement
    platform: event
  action:
  # Start (or reset) the 10 minute timer
  - service: timer.start
    data:
      entity_id: timer.food_eat_timer
      duration: "00:10:00"
  # Increment the counter
  - service: input_number.set_value
    data_template:
      entity_id: input_number.food_eat_counter
      value: "{{ states('input_number.food_eat_counter') | int + 1}}"
  # Only continue if the counter > 3
  - condition: template
    value_template: "{{ states('input_number.food_eat_counter') | int > 3 }}"
  - data:
      message: Someone is eating!
    service: notify.mobile_app1
  - data:
      message: Someone is eating!
    service: notify.mobile_app_mi2

This will notify you every time after 3 until the 10 minutes is up. If you don’t want that, change the

  # Only continue if the counter > 3
  - condition: template
    value_template: "{{ states('input_number.food_eat_counter') | int > 3 }}"

To

  # Only continue if the counter = 3
  - condition: template
    value_template: "{{ states('input_number.food_eat_counter') | int == 3 }}"

Now you will only be notified once until the timer finishes and resets the counter.

When i do restart to HA
The value on “food eat counter” start from 10
I guess need initial the counter to 0 after restart HA
How i add it to configuration yaml ?
image

If you don’t specify an initial, it will remember the last value it was.

You just need to add

initial: 0.0

after min or max in the input_number.