KNX Integration does not use latest values within automation

Hello,
I am using the Home Assistant since a few months together with the KNX Integration to work hand in hand with the existing KNX system in the house. It works very well.

Recently I wanted to add an automation for the covers.
I have configured them like this in yaml:

# Jalousien
cover:
  - name: "Jalousie Küche"
    move_long_address: "8/4/10"      
    stop_address: "8/4/11"
    position_address: "8/4/13"
    position_state_address: "8/4/12"
    travelling_time_down: 32.1
    travelling_time_up: 34.1

Now I have created an automation that uses a few conditions (sun position, temperatures, current day weather forecast) to determine, whether to move the blinds down (40% which is 60% in KNX notation) or up (value:100%).
This also works quite well.

This automation triggers every 10 minutes. It works, but it sends the position to the KNX system even if the blinds are already at that position. It’s not a big problem, but it’s unnessary:

Idea
Therefore I wanted to check the current position of the blinds and only if it’s different than the new target actually send the move command to KNX:

if:
  - condition: numeric_state
    entity_id: cover.jalousie_kuche
    below: 100
    attribute: current_position
then:
  - service: cover.open_cover
    data: {}
    target:
      entity_id: cover.jalousie_kuche
enabled: true

And the problem is that the “current_position” attribute of the cover.jalousie_kuche does apparently not update in HA. When I use the developer tools to check the state it still shows value 15 from some time ago (outdated) (- in the screenshot for illustration it shows 100 (correct) because I took it later, but you get the idea). Why does it not update itself automatically when used within an automation IF criterium?

Then I even tried to force the update by adding those actions to the automation

service: homeassistant.update_entity
data: {}
target:
  entity_id: cover.jalousie_kuche
enabled: true

or

service: knx.read
data:
  address: 8/4/12

and i see that this triggers a read command on the KNX side and the KNX system responds correctly. However still the current_position value is still wrong in HA and the automation not working therefore. Does anyone know how to make sure HA is using the current state from KNX and not an old value when used within an automation?

PS: Attaching the complete yaml automation for completeness

Summary
alias: Jalousie Küche
description: ""
trigger:
  - platform: time_pattern
    minutes: /10
condition:
  - condition: state
    entity_id: binary_sensor.workday_sensor
    state: "on"
action:
  - choose:
      - conditions:
          - condition: and
            conditions:
              - condition: and
                conditions:
                  - condition: numeric_state
                    entity_id: sensor.kuche_sensor_temperatur
                    above: 23.5
                  - condition: numeric_state
                    entity_id: sensor.home_hours_of_sun_0d
                    above: 6
                  - condition: numeric_state
                    entity_id: sensor.sun_solar_elevation
                    below: 80
                alias: Baseconditions
              - condition: or
                conditions:
                  - condition: and
                    conditions:
                      - condition: numeric_state
                        entity_id: sensor.sun_solar_azimuth
                        above: 100
                        below: 140
                      - condition: numeric_state
                        entity_id: sensor.sun_solar_elevation
                        above: 50
                    alias: Sector1
                  - condition: and
                    conditions:
                      - condition: numeric_state
                        entity_id: sensor.sun_solar_azimuth
                        above: 140
                        below: 160
                      - condition: numeric_state
                        entity_id: sensor.sun_solar_elevation
                        above: 40
                    alias: Sector2
                  - condition: and
                    conditions:
                      - condition: numeric_state
                        entity_id: sensor.sun_solar_azimuth
                        above: 160
                        below: 180
                      - condition: numeric_state
                        entity_id: sensor.sun_solar_elevation
                        above: 30
                    alias: Sector3
                  - condition: and
                    conditions:
                      - condition: numeric_state
                        entity_id: sensor.sun_solar_azimuth
                        above: 180
                        below: 264
                      - condition: numeric_state
                        entity_id: sensor.sun_solar_elevation
                        above: 25
                    alias: Sector4
                alias: Test Any Sector
            alias: Test if Baseconditions and Any Sector is True
        sequence:
          
          # Here also I suspect it is not using the latest "current_position"
          - if:
              - condition: not
                conditions:
                  - condition: state
                    entity_id: cover.jalousie_kuche
                    attribute: current_position
                    state: "40"
                alias: Position is different than 40
            then:
              - service: cover.set_cover_position
                data:
                  position: 40
                target:
                  entity_id: cover.jalousie_kuche
                alias: Set Position to 40
            alias: Position to 40
            enabled: true
            
          # Temporary Workaround: This just sends telegram to KNX even if the cover is already at right position
          - service: cover.set_cover_position
            data:
              position: 40
            target:
              entity_id: cover.jalousie_kuche
            alias: Set Position to 40
            enabled: false
    default:
      
      # Here I noticed the "current_position" is outdated.
      # It does not pull the latest values from KNX. --> Automation is not working correctly therefore.
      - if:
          - condition: numeric_state
            entity_id: cover.jalousie_kuche
            below: 100
            attribute: current_position
        then:
          - service: cover.open_cover
            data: {}
            target:
              entity_id: cover.jalousie_kuche
        enabled: true
        
      # Temporary Workaround: This just sends telegram to KNX even if the cover is already at right position
      - service: cover.open_cover
        data: {}
        target:
          entity_id: cover.jalousie_kuche
        enabled: false
mode: single

The issue is within the codelines 102 -114

If a telegram from the actuator to position_state_address is not handled in HA, it may be there is something wrong with your interface configuration or other line couplers filter tables. Do you see the response telegram appearing in HAs group monitor?

Hello farmio! Thanks for your reply!
Although I’m not sure what the HA group monitor is I think your reply helps me quite a lot as written below. With HA group monitor you mean I should look in the history view like http://192.168.0.36:8123/history?entity_id=cover.jalousie_kuche ?
There I can only see the “main state” of the knx “cover” item which is the “open” value. I cannot see the “current_position” attribute.

But… I think your comment hints me the a possible solution:
Instead of using this attribute of the cover to check the cover position within my automation like:

- condition: numeric_state
    entity_id: cover.jalousie_kuche
    below: 100
    attribute: current_position

the right thing to do would probably be to create a knx sensor within the yaml configuration of HA which uses the KNX group address of the position_state_address: (“8/4/12”) and use this sensor to get the position instead of relying on the “current_position” attribute of the knx cover … Correct?
(–> By using KNX percent values directly I should ask if it is >0 to check if it is (partly) closed and not check if it is <100 like I did with the HA internal current_position value.)

That should be the same.

If you updated to 2023.6 you have a Knx panel in your sidebar - there you’ll find the group monitor.

Ah, nice! Ok I will upload the knxproj file and check with the group monitor.

Furthermore I will test if the idea described above yields the same results as before or not.
I’ll come back with the results.

I did not upload the knxproj file yet but I noticed that adding another sensor for the position_state_address: (“8/4/12”) and using this when checking position within the automation definitely works and solved my problem.

Using the current_position attribute of the knx cover within the automation seems definetely not reliable / buggy.