Counting a trigger

Hello all.

I am new here and am trying out all sorts of things to learn from HA.
I have a printer ink level trigger.

This works ok, but would like to keep track of how many times each entity is triggered.

It is possible for HA to automatically use trigger.entity_id
maintain a couter that counts this per entity.

All reactions are very welcome, that’s how I learn the most.

Here my code.

code

In the future, please post code as formatted text and not as a screenshot (see guideline #14 in the FAQ).

You can create a Counter for each entity then enhance your automation so it also increments the entity’s counter.

For example, assuming you create these counters:

counter.printer_keuken_zaak_color
counter.printer_keuken_zaak_black
counter.printer_bureau_black
counter.printer_bureau_color

You can then add the following service call to your automation’s action.

  - service: counter.increment
    target:
      entity_id: "counter.{{trigger.to_state.object_id}}"

If sensor.printer_bureau_color triggers the automation, then counter.printer_bureau_color will be incremented.

Thank you for your response!

In the future, please post code as formatted text and not as a screenshot (see [guideline #14 in the FAQ]

Will read this tip carefully!

And will certainly try out your solution.
:innocent: :grinning:

Thank you again for your response.

Does this also work with “input_text …”?

Before I can answer your question, I will need you to explain how and where you are using an input_text entity. For example, is it used in a State Trigger?

As I said, I am very new to HA.
I try to test as much as possible to understand a little bit better how it works.

I mean so if a certain trigger, eg sensor.printer_keuken_zaak_color, is activated from above, is it possible that I can put a certain value in eg “input_text.printer_keuken_zaak_color”?

Sorry,
but another question.
How can I read this value if necessary?

Yes.

For example, let’s say you want to use the input_text as a counter and sensor.printer_keuken_zaak_color triggered the automation. The following service call will take the existing value of input_text.printer_keuken_zaak_color and increment it by one.

    action:
      - variables:
          x: "input_text.{{trigger.to_state.object_id}}"
      - service: input_text.set_value
        target:
          entity_id: "{{ x }}"
        data:
          value: "{{ states(x) | int + 1 }}"

If you only want to set it to a specific value, like Hello World or 250 or whatever else you want, then you can use this simpler version:

    action:
      - service: input_text.set_value
        target:
          entity_id: "input_text.{{trigger.to_state.object_id}}"
        data:
          value: "Hello World"

Thank you very much, now I am getting a little further. Been searching all day! Try to understand all of this, but it is not so obvious. Would you be so kind as to tell me how I can read these values ​​in the future.

You may also know where to find out how HA works. Preferably in Dutch

I don’t know where to find reference material for Home Assistant in Dutch. However, I do know there are native Dutch speakers who are members of this forum. Perhaps one of them will read this discussion and help you with that.

Most of what I have shown can be found in the official documentation, specifically here:

Would you be so kind as to tell me how I can read these values ​​in the future.

I’m sorry but I don’t understand the question. What do you mean by reading the values in the future?

Ok, thank you again for helping me out. Yet I still hang somewhere!

I now have the counter “counter.printer_keuken_zaak_color” which has a certain value. How can I approach this value now. Have already tried several things but really can’t figure it out !!

If you want to get the counter’s value you can use the states function in a template:

{{ states ('counter.printer_keuken_zaak_color') }}

That’s described in the Templating documentation.

OK thank you.
I understood that to that extent.

But if I want to forward this value eg in my example to eg mobile phone how should I access it?
device_id: 0b463d7317e2bbc5ebf2d713aa5aae89
domain: mobile_app
type: notify
title: Inktniveau Printers
message: >-
{{ state_attr(trigger.entity_id, ‘friendly_name’) }}
{{states(‘input_text.printer_woord’)}} {{states(trigger.entity_id)}} % {{
{{states(counter.{{trigger.to_state.object_id}}}}

Have already tried this but can’t get it to work!