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