[Cover]how to customise states for automation (opening/closing)

I have a Z2M roller shutter Wiser module Schneider Electric S520567 control via MQTT | Zigbee2MQTT
Unfortunately it does not report the “Opening”/“Closing” state, only Open/Closed with its percentage.

Do you have any idea how I could generate/simulate these states? The idea is to be able to stop closing cover if I open my window.

I’m using the following automation to avoid trouble with my Ikea roller blind in the bedroom:


automation:

- id: rolloschutz
  alias: Rolloschutz # blind protection 
  mode: restart
  description: /packages/automationen/schlafzimmer/rollo_schlafzimmer.yaml

  trigger:
    - platform: numeric_state
      entity_id: cover.tradfri_blind
      attribute: current_position
      below: '95'

  condition:
    - condition: state
      entity_id: binary_sensor.schlafzfenster # window sensor
      state: 'on'

  action:
    - service: cover.set_cover_position
      target:
        entity_id: cover.tradfri_blind
      data:
        position: 95


what happen if your cover is already under 95% and you open your window ? Nothing ?

Correct. If you want to cover that case, you can either use a state trigger without defining a state and add a numeric state condition. Such a state trigger will react on all entity changes incl. its attributes.


trigger:
  - platform: state
    entity_id: cover.tradfri_blind

condition:
  - condition: state
    entity_id: binary_sensor.schlafzfenster
    state: "on"

  - condition: numeric_state
    entity_id: cover.tradfri_blind
    attribute: current_position
    below: 95

action:
  - service: cover.set_cover_position
    target:
      entity_id: cover.tradfri_blind
    data:
      position: 95

You can also use the window sensor as trigger:


trigger:
  - platform: state
    entity_id: cover.tradfri_blind ## this trigger is optional

  - platform: state
    entity_id: binary_sensor.my_window
    from: 'off'
    to: 'on'

condition:
  - condition: numeric_state
    entity_id: cover.tradfri_blind
    attribute: current_position
    below: 95

action:
  - service: cover.set_cover_position
    target:
      entity_id: cover.tradfri_blind
    data:
      position: 95