Automation on state change unless it was or becomes a certain state

I am trying to build an automation which triggers on the state change of our cat flap however it regularly becomes unavailable.

I would like to add a condition that checks the state change hasn’t gone to or from Unavailable but I am really struggling to think how to do it in HA.

I have very little knowledge how to use node red but would consider it if that is a recommended solution.

Is it a binary state - eg open/closed? If so two triggers - from closed to open and from open to closed should exclude any unavailable states. If you want to know when the flap is unavailable a third trigger for that. Then a choose action depending on which trigger fired.

For example:

description: ""
mode: single
trigger:
  - platform: state
    entity_id:
      - binary_sensor.catflap
    to: "on"
    id: open
  - platform: state
    entity_id:
      - binary_sensor.catflap
    to: "off"
    id: closed
  - platform: state
    entity_id:
      - binary_sensor.catflap
    to: unavailable
    id: unavailable
condition: []
action:
  - choose:
      - conditions:
          - condition: trigger
            id:
              - open
        sequence: []
      - conditions:
          - condition: trigger
            id:
              - closed
        sequence: []
      - conditions:
          - condition: trigger
            id:
              - unavailable
        sequence: []

The poor cat must get shut out a lot! :unamused:

Something like this may help:

description: ""
mode: single
trigger:
  - platform: state
    entity_id:
      - binary_sensor.lumi_lumi_sensor_magnet_aq2_opening_2
    not_from: unavailable
condition:
  - condition: not
    conditions:
      - condition: state
        entity_id: binary_sensor.lumi_lumi_sensor_magnet_aq2_opening_2
        state: unavailable
action: []

The not_from isn’t available to select from the UI but is available when the Yaml is edited directly.

1 Like

Thankfully the RFID scanner still works so no issue to the cat, just means I can’t remotely control it.