Automation problem work one day and not the other day

Hello, I created an automation for a project to validate the consumption and then send a notification to Gmail.
the problem is that last night it seemd to work fine and this morning doesn’t work anymore.

Here’s the code:

- id: '1704409344154'
  alias: Stop energy recording
  description: ''
  trigger:
  - platform: numeric_state
    entity_id: sensor.0xa4c1381879e51abd_power_a
    below: 0.02
  action:
  - service: recorder.disable
    entity_id: sensor.0xa4c1381879e51abd_power_a
    
  - service: notify.gmail
    data_template:
        message: "La consommation d'énergie enregistrée est {{ (states(sensor.0xa4c1381879e51abd_power_a) | float / 1000) | round(4) }} KWh"
  mode: single

and here’s the HA log error message:

This in the Automation (Trace Timeline):

But When a go in the Jinja2 template to teste de code it dosent give me any error:

I tried several functions and research but couldn’t find anything:(
im still a beginner

You have supplied an entity id here:

  action:
  - service: recorder.disable
    entity_id: sensor.0xa4c1381879e51abd_power_a

This service does not support dissabling per entity. You can only disable all entities from being recorded.

https://www.home-assistant.io/integrations/recorder/#service-disable

Ok but still dont understand :frowning:

Here Is the code frome the beginning in automation

Step one record data when above 0.020w
code:

- id: 2c4389600f1c4c689e120e615e5f5981
  alias: Start energy recording
  trigger:
  - platform: numeric_state
    entity_id: sensor.0xa4c1381879e51abd_power_a
    above: 0.02
  action:
  - service: recorder.enable
    entity_id: sensor.0xa4c1381879e51abd_power_a

step tow when sensor get reading below 0.020w stop recording data and send notification with consumption in KWh.
Code:

- id: '1704484524071'
  alias: Stop energy recording
  trigger:
  - platform: numeric_state
    entity_id: sensor.0xa4c1381879e51abd_power_a
    below: 0.02
  action:
  - service: recorder.disable
    entity_id: sensor.0xa4c1381879e51abd_power_a
  - service: notify.gmail
    data_template:
      message: "La consommation d énergie enregistrée est {{ (states('sensor.0xa4c1381879e51abd_power_a') | float / 1000) | round(4) }} KWh"
      title: Consommation

This is the code that a have in configuration.yaml for the recorder

recorder:
  db_url: sqlite:////home-assistant_v2.db  
  purge_keep_days: 3

If this dosent work what could a do to make it work ?

Why does the code in the error message not match the code in the automation you posted?

image

(states(sensor.0xa4c1381879e51abd_power_a) | float / 1000) | round(4)

The code referenced in the error message is clearly wrong.

You cant do this:

  action:
  - service: recorder.disable
    entity_id: sensor.0xa4c1381879e51abd_power_a  ### <- NOT ALLOWED

There is no entity id option for this service. This is all you can do:

  action:
  - service: recorder.disable

This disables recording all entities. You can not stop recording a single entity.

Same for the enable service.

is there a way to calculat consumption when the entity is in usage ?

Sure, use a riemann sum helper.

This will calculate the energy used from your power sensor.

Do not confuse power and energy. They are very different things.

ok one thimg work

But if the Riemann sum integral, is there a way to flush the info to go back to zero ?

because it always go up but dosent go to zero or reset ?

Thanks for your help

No there is no way to reset the Riemann Sum sensor. If you want hourly/daily/weekly/monthly/yearly resetting sensors feed your Riemann Sum energy sensor to Utility Meter helpers: