How to Accurately Track Shutter Position with Aqara T2 Double Relay Module (LLKZMK12LM)

I recently installed an Aqara T2 double relay module (model LLKZMK12LM) to control my window shutters, and I’m struggling to implement an automation that accurately tracks the shutter position. Knowing the exact position is crucial for me, especially when I’m away from home, so I can adjust them remotely as needed.

The Problem

The Aqara module doesn’t natively provide shutter position feedback, so I tried creating an automation that calculates the position based on the time the relay is active. I know that a full cycle (fully open or fully closed) takes exactly 23 seconds. However, my automation doesn’t seem to update the position continuously, and I’m unsure what I’m doing wrong.

My Automation Attempt

Here’s the YAML for the automation I created:


alias: Track Shutter Position
description: ""
triggers:
  - entity_id:
      - switch.0x54ef441000cdeb7a_l1
    from: "off"
    to: "on"
    trigger: state
conditions: []
actions:
  - data:
      value: |
        {% if trigger.to_state.state == 'on' %}
          {% set duration = 23 %} 
          {% set position = (duration - states('timer.elapsed_time') | float(0)) / duration  %}
          {{ position | round(0) }}
        {% else %}
          0
        {% endif %}
    target:
      entity_id: input_number.shutter_position
    action: input_number.set_value
mode: single

This automation is supposed to calculate the shutter position based on how long the relay has been active. However, it only updates the position once when triggered and doesn’t continuously record the position as the relay operates.

What I’ve Tried

  • Confirmed the timing for a full cycle (23 seconds) is accurate.
  • Verified the Aqara relay status updates correctly in Home Assistant.
  • Looked into using timer entities to calculate elapsed time but couldn’t figure out how to make it work seamlessly.

What I Need

  • Is there a way to track the shutter position continuously while the relay is active?
  • Has anyone managed to achieve a similar setup with the Aqara T2 or a similar module?
  • Is there a better approach to solve this problem? Should I consider a different module or sensor to achieve this functionality?

Any insights, guidance, or examples of working configurations would be greatly appreciated! Thank you in advance for your help.