Automation Isn't Triggering. Works when manually Run

This is my first automation. I am trying to trigger an alert when power consumption on my fridge is below 500 watts for 1 hour (once its working I will increase the time period)

alias: Fridge Defrost Alert
description: ""
trigger:
  - platform: numeric_state
    entity_id:
      - sensor.fridge_plug_current_consumption
    for:
      hours: 1
      minutes: 0
      seconds: 0
    below: 500
condition: []
action:
  - service: notify.mobile_app_matt_iphone_11
    metadata: {}
    data:
      title: Fridge Defrost Issue
      message: Check if fridge is defrosting
mode: single

I get the notification if I run the automation manually, but nothing happens otherwise

I can’t figure out what I missed or did wrong?

I confirmed the Entity “Fridge Plug Current consumption” used is correct

I also confirmed the state of the Entity is as expected a simple number value

and that the value is definitely staying below 500 for longer than an hour

Any Ideas?

State of the Entity.

It would have to be above 500 and then drop below 500 to trigger the automation. From your timeline it has been below 500 for quite sometime.

Ok I was wondering if something like that could be the issue. Is there a way to trigger without needing to go above 500 first and wait for it to fall below again?

Are you looking to check it every hour?

If so you can use a time pattern as the trigger and add a condition to verify if the current wattage is above or below 500.

Probably every 12-24 hours but I used 1 hour to test with.
I am trying to get an alert if the defrost cycle isn’t running on my fridge based on the power consumption reported by my energy monitoring system.

The Defrost cycle should run 2-3 times a day. I can see when it runs in the chart as the power usage spikes above 500 watts for a short period while the defrost heater is on, but most of the time that heater is off.

How would that work using the time pattern? the fridge (working correctly) is only briefly above 500 watts 2-3 times per day. It will almost always be below 500. If I use time to check would I not be checking the value at the exact point in time the automation runs?

Sorry this is my first attempt at understanding automations in home assistant

Yes, it would only look at the state when the automation is executed. It’s going to need a template condition that says X was triggered in the last 12 hours.

X can be a binary sensor or another automation. As long as it logs when it goes above 500.

I’m not an automation expert either so others may chime in. I’ll still see what I can come up with.

What the 2nd automation template would look like it you are verifying another automation triggered in the last 12 hours

{{ now() - state_attr('automation.fridge_defrost_alert', 'last_triggered') < timedelta(hours=12) }}

Just to be clear, you only want a notification if it’s above 500 for more than an hour in the past 12 hours, not if it simply spikes similar to the spike in the graph you posted?

I want a notification if the 500 watt spike doesn’t occur.

Sorry that was a typo on my part.

no worries

Extended durations for triggers or conditions don’t survive restart, so they should be avoided… especially with “critical” automations. I would set up a trigger-based template sensor to store a timestamp every time the power goes over the threshold. The automation could then be triggered by template calculation of the time since the last defrost.

template:
  - trigger:
      - platform: numeric_state
        above: 500
        entity_id: sensor.fridge_plug_current_consumption
    sensor:
      - name: Last Defrost
        device_class: timestamp
        state: "{{ now() }}"

automation:
  - id: 'fridge_defrost_warning_0001'
    alias: Excessive time since Fridge Defrost
    description: Send notification if it has been too long since the defrost cycle ran. 
    trigger:
      - platform: template
        value_template: "{{ now() - timedelta(hours=6) > states('sensor.last_defrost') | as_datetime | as_local }}"
      - platform: homeassistant
        event: start
    condition:
      - or: 
          - "{{ trigger.platform == 'template' }}"
          - "{{ now() - timedelta(hours=6) > states('sensor.last_defrost') | as_datetime | as_local }}"
    action:  
      - service: notify.mobile_app_matt_iphone_11
        metadata: {}
        data:
          title: Fridge Defrost Issue
          message: Check if fridge is defrosting
2 Likes

Appreciate the input!! I like the local store option.

Sorry for the delayed reply. I didn’t know I could just declare something to create a sensor and feed in whatever I wanted… Interesting approach.

I after a bunch of Trial and error I had to break up your suggestion into 3 steps.

  1. Edit the configuration.yaml file to create the sensor
sensor:
  - platform: template
    sensors:
      last_defrost:
        friendly_name: "Last Defrost"
        device_class: timestamp
        value_template: "{{ now() }}"
  1. Create an Automation that updates the sensor when the fridge power consumption goes over 500 watts
alias: Update Last Defrost
description: Updates the Sensor Value for Last Defrost when the Fridge runs a Defrost Cycle
trigger:
  - platform: numeric_state
    entity_id:
      - sensor.fridge_plug_current_consumption
    above: 500
condition: []
action:
  - service: homeassistant.update_entity
    target:
      entity_id: sensor.last_defrost
    data: {as_timestamp(now())}
mode: single
  1. Create a Notification Automation
alias: Defrost Notification
description: ""
trigger:
  - platform: time_pattern
    minutes: "5"
condition:
  - condition: template
    value_template: >-
      {{ as_timestamp(now()) - as_timestamp(states.sensor.last_defrost.state) >
      6 * 60 * 60 }}
action:
  - service: notify.mobile_app_matt_iphone_11
    data:
      title: Defrost Alert
      message: The last defrost is more than 6 hours ago.
mode: single

However, something isn’t right with step 2.
I can see my sensor.last_defrost entity is incrementing in 1 minute increments even though my fridge is well below the 500 threshold set.

I am not sure what I did wrong on step 2 that is causing this. That step shouldn’t be triggering at all based on the data I am seeing as the fridge is currently in standby only using 2.3 watts

Ok, I am not sure if Step 2 is the problem or something in the sensor creation.

but the sensor value is incrementing by one minute every minute which it shouldn’t be doing.