How Can I check / wait foe-r an entity state change in an action in Automation?

Hi there,

I have an automaton which waits for my phone to ring to be triggered - fine.
But then in the actions, I need to be able to test an entity state change (either from Ringing to Idle, or from ringing to talking) in order to take certain actions.
I am unable to find anything allowing me to do so …

Would you have any idea ?

See in the code below it is just testing if state is “Idle”, but not if state is changing from Ringing to Idle ;-(

alias: Nouvelle automatisation
description: ""
trigger:
  - platform: state
    entity_id: sensor.fritz_box_7530_ax_call_monitor_repertoire_telephonique
    to: ringing
condition: []
action:
  - service: persistent_notification.create
    data:
      message: Le script démarre car detecte Ringing
  - service: input_text.set_value
    target:
      entity_id: input_text.dernier_appelant_fritzbox
    data:
      value: >-
        {{
        state_attr("sensor.fritz_box_7530_ax_call_monitor_repertoire_telephonique",
        "from")}}
  - if:
      - condition: state
        entity_id: sensor.fritz_box_7530_ax_call_monitor_repertoire_telephonique
        state: idle
    then:
      - service: persistent_notification.create
        metadata: {}
        data:
          message: "-> Idle"
mode: single

wait_for_trigger

Thanks a lot … I had also tested this … and it says in French “Déclenché” that means that the condition was recognized (passing from Ringing to Idle), but then the next action is not executed … Here is my adapted code :

alias: Nouvelle automatisation
description: ""
trigger:
  - platform: state
    entity_id: sensor.fritz_box_7530_ax_call_monitor_repertoire_telephonique
    to: ringing
condition: []
action:
  - service: persistent_notification.create
    data:
      message: Le script démarre car detecte Ringing
  - service: input_text.set_value
    target:
      entity_id: input_text.dernier_appelant_fritzbox
    data:
      value: >-
        {{
        state_attr("sensor.fritz_box_7530_ax_call_monitor_repertoire_telephonique",
        "from")}}
  - wait_for_trigger:
      - platform: state
        entity_id: sensor.fritz_box_7530_ax_call_monitor_repertoire_telephonique
        from: ringing
        to: idle
  - service: persistent_notification.create
    metadata: {}
    data:
      message: Passing to Idle
mode: single

Many Thanks for the help so far

What exactly did you test and how did you test it?

If you are referring to the wait_for_trigger, the only way to test it is by waiting for the fritz box sensor to change from ringing to idle.

It is ok … it is working now, and I share my code below.
I am also incrementing an helper counter to show on the dashboard the missed calls.
I just need now to be able to display the people who called if I click on it.
Many thanks !

- id: '1708016320033'
  alias: Nouvelle automatisation
  description: ''
  trigger:
  - platform: state
    entity_id: sensor.fritz_box_7530_ax_call_monitor_repertoire_telephonique
    to: ringing
  condition: []
  action:
  - service: persistent_notification.create
    data:
      message: 'Le script démarre car detecte Ringing           {{state_attr("sensor.fritz_box_7530_ax_call_monitor_repertoire_telephonique",
        "from")}}      '
  - service: input_text.set_value
    target:
      entity_id: input_text.dernier_appelant_fritzbox
    data:
      value: '{{ state_attr("sensor.fritz_box_7530_ax_call_monitor_repertoire_telephonique",
        "from")}}'
  - wait_for_trigger:
    - platform: state
      entity_id: sensor.fritz_box_7530_ax_call_monitor_repertoire_telephonique
      from: ringing
      to: idle
  - service: persistent_notification.create
    data:
      message: Passing to Idle from {{state_attr("sensor.fritz_box_7530_ax_call_monitor_repertoire_telephonique",     "from")}}
  - service: counter.increment
    metadata: {}
    data: {}
    target:
      entity_id: counter.nombre_d_appels_manques
  mode: single