Counter increase

i have this sensor
sensor.stovsuger_koert_m2
i want to increase this counter
counter.mario_koert with sensor.stovsuger_koert_m2 in an autmation.
how do i do that.
it would be nice if you can show it in the UI

You’ll need to elaborate on what you want. E.g., what do you mean by “i want to increase this counter counter.mario_koert with sensor.stovsuger_koert_m2”?

I Want to set the counter step to the number the sensor show.
So if the sensor show 20 i Want to step Up the counter with 20 and if the sensor shows 15 i Want to step Up with 15

How is the sensor updated ?
If the initially the sensor reads 10, you want the counter to read 10.
Next minute the sensor reads 20, you want the counter to read 30.
The sensor updates again and now reads 15, you want the counter to read 45.
Is this correct ?

That is correct.
The sensor updates Evert time my vaccum cleaner is finish to run

- trigger:
  - platform: state
    entity_id: sensor.stovsuger_koert_m2
  action:
  - service: counter.configure
    data_template:
      entity_id: counter.mario_koert
      value: "{{ states('counter.mario_koert')|int + trigger.to_state.state|int }}"

So do i put this in my automation just before i increase the counter?

That is a complete automation that does what you want. It uses the counter.configure service to set the counter’s value directly rather than using the counter.increment service which would have to be called multiple times for each sensor change.

This Works perfect thanks

1 Like

have try to change the code a little, but i dont work
your code updates every time the sensor change, but i want it only to add when the vuccum is returned to dock, so how do i do this

- id: test
  alias: 00000a tester
  trigger:
  - entity_id: vacuum.xiaomi_vacuum_cleaner
    from: returning
    platform: state
    to: docked
  action:
  - data_template:
      entity_id: counter.mario_koert
      value: '{{ states(''counter.mario_koert'')|int + trigger.to_state.state|int
        }}'
    service: counter.configure
  mode: single

I had a feeling updating every time the sensor change wasn’t what you actually wanted, but since that’s what you asked for…

Well, you’re adding "docked"|int (which will always be zero) to the count. Maybe you should add the sensor’s current value.

I must have misunderstood you :slight_smile: i first want it to update when vaccum is docked :slight_smile:
I have tried to change to this because, sensor.stovsuger_koert_m2, shows the correct number, when my vaccum is docked
but it still not works

- id: test
  alias: 00000a tester
  trigger:
  - entity_id: vacuum.xiaomi_vacuum_cleaner
    from: returning
    platform: state
    to: docked
  action:
  - data_template:
      entity_id: counter.mario_koert
      value: '{{ states(''counter.mario_koert'')|int + sensor.stovsuger_koert_m2|int
        }}'
    service: counter.configure
  mode: single

Did you figure this out yet? If not, you might want to read up on Templating.

This is wrong:

      value: '{{ states(''counter.mario_koert'')|int + sensor.stovsuger_koert_m2|int
        }}'

It should be:

      value: '{{ states(''counter.mario_koert'')|int + states(''sensor.stovsuger_koert_m2'')|int
        }}'

Yes i found out the fail was what you said

1 Like

Hi thank you for your help . My project is counting daily egg on my chicken cole
I use Amazon rekognition , and i use image_scan and résult is on image_rekognition_espcam01.
image_rekognition_espcam01 status is state (if image_rekognition_espcam01 is 4, camera has discovered 4 eggs ) and i will use this result on my daily counter and cumulative counter.
Regards
Giloris