Condition not to match a state of an entity

Hi,

I’m stuck with setting up a notification automation.
I want the notification only to be send when the new state of the external ip is not the same as the one before. I set up a helper input text entity and configured it to update the external ip at the end of the automation to save the last state.

In the conditions i set the state to not match the helpers entity state. Only then i want to receive the notification.

the yaml of the condition:

condition: not
conditions:
  - condition: state
    entity_id: sensor.fritzbox21_external_ip
    state: "{{states('input_text.saved_external_home_ip')}}"
    enabled: false
  - condition: state
    entity_id: input_text.saved_external_home_ip
    state: "{{states('sensor.fritzbox21_external_ip')}}"

I’ve tried both ways, of checking. It always says the state does not match and then fires the notification.

Is there anything I am not thinking of here?

Here is the complete yaml of the automation:

alias: Notify when IP changes
description: ""
trigger:
  - platform: state
    entity_id:
      - sensor.fritzbox21_external_ip
    attribute: state
condition:
  - condition: not
    conditions:
      - condition: state
        entity_id: sensor.fritzbox21_external_ip
        state: unavailable
  - condition: not
    conditions:
      - condition: state
        entity_id: input_text.saved_external_home_ip
        state: "{{states('sensor.fritzbox21_external_ip')}}"
  - condition: not
    conditions:
      - condition: state
        entity_id: sensor.fritzbox21_external_ip
        state: unknown
action:
  - service: notify.wolfgangs_notification_devices
    data_template:
      title: IP Adresse
      message: "Neue IP Adresse ist: {{states('sensor.fritzbox21_external_ip')}}"
  - service: input_text.set_value
    data:
      value: "{{states('sensor.fritzbox21_external_ip')}}"
    target:
      entity_id: input_text.saved_external_home_ip
mode: single

Would appreciate any help and hints :slight_smile:
Thank you!

You cannot use templates in a State condition. However, you can use just the entity ID of input helpers:

condition: not
conditions:
  - condition: state
    entity_id: sensor.fritzbox21_external_ip
    state: input_text.saved_external_home_ip

OR you could use a template condition… your choice:

condition: template
value_template: |
  {{ trigger.to_state.state != states('input_text.saved_external_home_ip') }}

Also, in State triggers or conditions you should not specify an attribute if you are using the state of the entity.

alias: Notify when IP changes
description: ""
trigger:
  - platform: state
    entity_id:
      - sensor.fritzbox21_external_ip
    not_to: 
      - unavailable
      - unknown
condition:
  - condition: not
    conditions:
      - condition: state
        state: input_text.saved_external_home_ip
        entity_id: sensor.fritzbox21_external_ip
action:
  - service: notify.wolfgangs_notification_devices
    data_template:
      title: IP Adresse
      message: "Neue IP Adresse ist: {{ trigger.to_state.state }}"
  - service: input_text.set_value
    data:
      value: "{{ trigger.to_state.state }}"
    target:
      entity_id: input_text.saved_external_home_ip
mode: single
1 Like

That’s very useful! Thank you!