Skip to content

Instantly share code, notes, and snippets.

@aschamberger
Last active January 2, 2023 19:33
Show Gist options
  • Save aschamberger/585661949b8eb8462f997279a341377a to your computer and use it in GitHub Desktop.
Save aschamberger/585661949b8eb8462f997279a341377a to your computer and use it in GitHub Desktop.
HA Automation Blueprint: Control cover entities from KNX switching and percent (DPT 5.001) telegrams.
blueprint:
name: KNX - cover control
description: Control cover entities from KNX switching and percent
(DPT 5.001) telegrams.
domain: automation
input:
cover:
name: Cover
description: The cover that shall be controled.
selector:
entity:
domain: cover
up_down_address:
name: Cover Up/Down group address
description: >
Group address for cover up and down (DPT 1.008).
Example: '3/1/19'
stop_address:
name: Stop group address
description: >
Group address for stop (DPT 1.010)
Example: '3/2/19'
current_direction_address:
name: Current direction address
description: >
Group address for current direction (DPT 1.008).
Example: '3/4/19'
absolute_position_address:
name: Absolute position group address(es)
description: >
Group address(es) for setting absolute position (DPT 5.001).
Example:
```
- 3/5/19
- ...
```
selector:
object:
absolute_position_state_address:
name: Absolute position state group address
description: >
Group address for absolute position state (DPT 5.001).
Example: '3/6/59'
state_position_top_address:
name: State position top group address
description: >
Group address for absolute position state top. DPT 1.002
Example: '3/6/19'
state_position_down_address:
name: State position down group address
description: >
Group address for absolute position state down (DPT 1.002).
Example: '3/6/39'
source_url: https://gist.github.com/aschamberger/585661949b8eb8462f997279a341377a
mode: parallel
max_exceeded: silent
variables:
cover_entity_id: !input 'cover'
absolute_position_gas: !input 'absolute_position_address'
trigger:
- platform: homeassistant
event: start
id: initialize
- platform: event
event_type: automation_reloaded
id: initialize
# when KNX integration was reloaded
- platform: event
event_type: service_registered
event_data:
domain: knx
service: event_register
id: initialize
- platform: event
event_type: knx_event
event_data:
destination: !input 'up_down_address'
telegramtype: GroupValueWrite
id: up_down
- platform: event
event_type: knx_event
event_data:
destination: !input 'stop_address'
telegramtype: GroupValueWrite
id: stop
- platform: state
entity_id: !input 'cover'
attribute: current_position
id: expose_direction
- platform: event
event_type: knx_event
event_data:
telegramtype: GroupValueWrite
id: absolute_position
- platform: state
entity_id: !input 'cover'
attribute: current_position
id: expose_position
- platform: state
entity_id: !input 'cover'
attribute: current_position
to: 100
id: expose_top
- platform: state
entity_id: !input 'cover'
attribute: current_position
to: 0
id: expose_down
- platform: state
entity_id: !input 'cover'
attribute: current_position
from: 100
id: expose_top_gone
- platform: state
entity_id: !input 'cover'
attribute: current_position
from: 0
id: expose_down_gone
action:
- choose:
# UP
- conditions:
condition: and
conditions:
- condition: trigger
id: up_down
- '{{ trigger.event.data.data == 0 }}'
sequence:
- service: cover.open_cover
entity_id: !input 'cover'
# DOWN
- conditions:
condition: and
conditions:
- condition: trigger
id: up_down
- '{{ trigger.event.data.data == 1 }}'
sequence:
- service: cover.close_cover
entity_id: !input 'cover'
# STOP
- conditions:
condition: and
conditions:
- condition: trigger
id: stop
sequence:
- service: cover.stop_cover
entity_id: !input 'cover'
# EXPOSE CURRENT DIRECTION: 0 up, 1 down
# this is not the same as with KNX where the direction is sent when cover movement is startet
# could be sent above when triggered from KNX, then however state is missing when triggered via UI
- conditions:
condition: and
conditions:
- condition: trigger
id: expose_direction
sequence:
- service: knx.send
data:
address: !input 'current_direction_address'
payload: '{% if trigger.to_state.attributes.current_position - trigger.from_state.attributes.current_position > 0 %}0{% else %}1{% endif %}'
# SET ABSOLUTE POSITION
- conditions:
condition: and
conditions:
- condition: trigger
id: absolute_position
- '{{ trigger.event.data.destination in absolute_position_gas }}'
sequence:
- service: cover.set_cover_position
entity_id: !input 'cover'
data:
position: '{{ (1-trigger.event.data.data[0]/255)*100 }}'
# EXPOSE ABSOLUTE POSITION STATE
- conditions:
condition: and
conditions:
- condition: trigger
id: expose_position
sequence:
- service: knx.send
data:
address: !input 'absolute_position_state_address'
payload: '{% if state_attr(cover_entity_id, "current_position") == None %}0{% else %}{{ 100-state_attr(cover_entity_id, "current_position") }}{% endif %}'
type: percent
# EXPOSE TOP
- conditions:
condition: and
conditions:
- condition: trigger
id: expose_top
sequence:
- service: knx.send
data:
address: !input 'state_position_top_address'
payload: 1
# EXPOSE DOWN
- conditions:
condition: and
conditions:
- condition: trigger
id: expose_down
sequence:
- service: knx.send
data:
address: !input 'state_position_down_address'
payload: 1
# EXPOSE TOP GONE
- conditions:
condition: and
conditions:
- condition: trigger
id: expose_top_gone
sequence:
- service: knx.send
data:
address: !input 'state_position_top_address'
payload: 0
# EXPOSE DOWN GONE
- conditions:
condition: and
conditions:
- condition: trigger
id: expose_down_gone
sequence:
- service: knx.send
data:
address: !input 'state_position_down_address'
payload: 0
# INITIALIZE
- conditions:
condition: trigger
id: initialize
sequence:
- service: knx.event_register
data:
address: !input 'up_down_address'
- service: knx.event_register
data:
address: !input 'stop_address'
- service: knx.event_register
data:
address: !input 'absolute_position_address'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment