Trigger at every numeric change

Hi!

I want a trigger, that fires, when the numeric value changes to 0 and every time, the value changes to a value other than 0, for example at 1, at 2, at 3 and so on, with different ids. My problem is, that the trigger for the value other than zero fires only one time, for example when the value changes to 1. When the value changes to 2 after 1, the event is not fired again. How may i change that? I already found the option to set the for, second 0 option, but this doesn’t work.

{{ states('input_number.debug_nummertest') == '0' }}
id: zero
{{ states('input_number.debug_nummertest') != '0' }}
id: abovezero

Thank you!

trigger:
  - platform: state
    entity_id: input_number.debug_nummertest

Why do you want different ids? You can inspect the value later on if you want. Explain what you’re trying to do.

Because i want it in one automation to do in the same automation the things, that have to be done. Here the complete automation, seeing, that it is a test automation. The values is set, are only for testing. For example, i set the text at values above 0 with the text abovezero, the value of the numeric value and the current time, just for me to see, if the event is fired.

And to explain, what i want to do, i want to do some things, when the value of my home changes from 0 to whatever. But i want to do it everytime, somebody enters the house. Now the event is only fired, if one person enters the home, if nobody was at home. I want to do the things, i want to do, everytime, somebody enters the house.

alias: Numeric State Test
description: ""
trigger:
  - platform: template
    value_template: "{{ states('input_number.debug_nummertest') != '0' }}"
    id: abovezero
  - platform: template
    value_template: "{{ states('input_number.debug_nummertest') == '0' }}"
    id: zero
condition: []
action:
  - choose:
      - conditions:
          - condition: trigger
            id: zero
        sequence:
          - service: input_text.set_value
            data:
              value: zero
            target:
              entity_id: input_text.debug_test
      - conditions:
          - condition: trigger
            id: abovezero
        sequence:
          - service: input_text.set_value
            data:
              value: >-
                abovezero {{ states('input_number.debug_nummertest') }} {{
                now().strftime("%H:%M:%S") }}
            target:
              entity_id: input_text.debug_test
mode: single

Then use the trigger I suggested and use conditions in the action that read the state rather than relying on ids: state, numeric_state or template conditions.

alias: Numeric State Test
trigger:
  - platform: state
    entity_id: input_number.debug_nummertest
action:
  - choose:
      - conditions:
          - condition: state
            entity_id: input_number.debug_nummertest
            state: '0'
        sequence:
          - service: input_text.set_value
            data:
              value: zero
            target:
              entity_id: input_text.debug_test
      - conditions:
          - condition: numeric_state
            entity_id: input_number.debug_nummertest
            above: '0'
        sequence:
          - service: input_text.set_value
            data:
              value: >-
                abovezero {{ states('input_number.debug_nummertest') }} {{
                now().strftime("%H:%M:%S") }}
            target:
              entity_id: input_text.debug_test
mode: single

Thank you, i’ll try that.

Just to say that, i do read at any post, that it is “best pratice” to trigger events depending on the things that happen and in the action part of the automation do the things depending on the event id. But sure, you approach should work, i’ll try that. Thank you!

That can be a good way to work where you have lots of different triggers within one automation: e.g. a temperature change, sunrise, motion detection. You only have one “thing” happening here — you don’t have separate ids for each possible value of that thing.

Ok, i’ll have that in mind from now on :slight_smile:

By the way, it works :slight_smile:

But just to say, for me, seeing that the event fires every value change using the (your) state trigger, my not working way looks like an error at home assistant for me. Maybe i should report that.

trigger:
  - platform: template
    value_template: "{{ states('input_number.debug_nummertest') != '0' }}"
    id: abovezero
  - platform: template
    value_template: "{{ states('input_number.debug_nummertest') == '0' }}"
    id: zero

It isn’t a bug. If you change the input_number from, say, 2 to 3, it is correct that your trigger does not fire. The first template stays true and the second one stays false.

Assume you found the docs on numeric_state trigger? :wink:

If something’s not working, it’s most likely your understanding that it at fault. HA is generally a mature and stable system, with basic core functionality like automation triggers being reliable and well-defined.

No, but i thought about the thing, the event only fires again, if it was previously false!

BUT this is only mentioned at the template trigger, not at the numeric trigger. So in the example below, the trigger should be fired every time, also if changed from 2 to 3?!

  - platform: numeric_state
    entity_id: input_number.debug_nummertest
    above: 0
    id: abovezero
  - platform: numeric_state
    entity_id: input_number.debug_nummertest
    below: 1
    id: zero

I fully agree :slight_smile:

But maybe, i shouldn’t waste your time with the theoretical discussion. I now do have a working way, thats enough :slight_smile:

Thank you!

When it changes from 2 to 3, which of your thresholds is being crossed?

Ok, good point. But so, maybe there should be an optional setting to also trigger the event again on a simple change of the value. But i don’t mind, i take the solution you showed to me. Thanks for that!

That’s exactly what the state trigger does.

image