RalfP
(Ralf Pfitzner)
December 12, 2019, 8:39am
1
This is an update to my previous post https://community.home-assistant.io/t/problem-with-setting-up-automation-for-cover/153608/4
I’ve extended my automation to my second Eltako, which is controlling two covers.
- id: '1575468037014'
alias: Schlafzimmer Rollos klein
description: ''
trigger:
- event_data:
id:
- 254
- 242
- 245
- 71
event_type: button_pressed
platform: event
condition: []
action:
- alias: ''
data_template:
entity_id: '{% if trigger.event.data.which == 1 %} cover.qubino_goap_zmnhcdx_flush_shutter_level_2
{% else %} cover.qubino_goap_zmnhcdx_flush_shutter_level_3 {%endif %}'
service_template: >-
{% set button_press = trigger.event.data.onoff %}
{% set power_consumption = state_attr(trigger.action.data.entity_id, 'power_consumption') | float %}
{% if power_consumption > 0 %}
cover.stop_cover
{% elif button_press %}
cover.close_cover
{% else %}
cover.open_cover
{% endif %}
Hopefully the part {% set power_consumption = state_attr(trigger.action.data.entity_id, 'power_consumption') | float %}
will work as expected. Can test only when back home tonight.
Once again, many thanks to all here in the forum that give inspiration to learn :-).
Ralf
Update:
No, the part with trigger.action.data.entity_id did NOT work
Any bright ideas welcome, otherwise I would split in two automations.
You can’t use this on the action part “trigger.action.data.entity_id”, the trigger is only to get data from the trigger part. Try something like this for your data_template:
data_template:
entity_id: >-
{% if trigger.event.data.which == 1 %}
cover.qubino_goap_zmnhcdx_flush_shutter_level_2
{% else %}
cover.qubino_goap_zmnhcdx_flush_shutter_level_3
{% endif %}
service_template: >-
{% set button_press = trigger.event.data.onoff %}
{% set action_entity = 'cover.qubino_goap_zmnhcdx_flush_shutter_level_2' if trigger.event.data.which == 1 else 'cover.qubino_goap_zmnhcdx_flush_shutter_level_3' %}
{% set power_consumption = state_attr(action_entity, 'power_consumption') | float %}
{% if power_consumption > 0 %}
cover.stop_cover
{% elif button_press %}
cover.close_cover
{% else %}
cover.open_cover
{% endif %}
RalfP
(Ralf Pfitzner)
December 18, 2019, 5:33pm
3
Burningstone, thanks for hinting again.
With this
- id: '1575468037014'
alias: Schlafzimmer Rollos klein
description: ''
trigger:
- event_data:
id:
- 254
- 242
- 245
- 71
event_type: button_pressed
platform: event
condition: []
action:
- alias: ''
data_template:
entity_id: '{% if trigger.event.data.which == 1 %} cover.qubino_goap_zmnhcdx_flush_shutter_level_2
{% else %} cover.qubino_goap_zmnhcdx_flush_shutter_level_3 {%endif %}'
service_template: >-
{% set button_press = trigger.event.data.onoff %}
{% if trigger.event.data.which == 1 %}
{% set action_entity = 'cover.qubino_goap_zmnhcdx_flush_shutter_level_2' %}
{% else %}
{% set action_entity = 'cover.qubino_goap_zmnhcdx_flush_shutter_level_3' %}
{% endif %}
{% set power_consumption = state_attr('cover.qubino_goap_zmnhcdx_flush_shutter_level', 'power_consumption') | float %}
{% if power_consumption > 0 %}
cover.stop_cover
{% elif button_press %}
cover.close_cover
{% else %}
cover.open_cover
{% endif %}
I don’t get any error messages when checking the config or when the automation is triggered, but the cover just stops for 1-2 seconds and then resumes the open or close cover command. The right cover is opened or closed.
The same code (if power_consumption > 0 --> Stop cover) is working perfect when I only have one cover linked to the automation.
Have to investigate further.
EDIT: Dumb me, when checking the power consumption of cover 1 I can’t control cover 2 or 3…
This looks solvable though.
Regards
Ralf
RalfP
(Ralf Pfitzner)
December 18, 2019, 5:44pm
4
Magic!!
here is the correct service_template part
service_template: >-
{% set button_press = trigger.event.data.onoff %}
{% if trigger.event.data.which == 1 %}
{% set action_entity = 'cover.qubino_goap_zmnhcdx_flush_shutter_level_2' %}
{% set power_consumption = state_attr('cover.qubino_goap_zmnhcdx_flush_shutter_level_2', 'power_consumption') | float %}
{% else %}
{% set action_entity = 'cover.qubino_goap_zmnhcdx_flush_shutter_level_3' %}
{% set power_consumption = state_attr('cover.qubino_goap_zmnhcdx_flush_shutter_level_3', 'power_consumption') | float %}
{% endif %}
{% if power_consumption > 0 %}
cover.stop_cover
{% elif button_press %}
cover.close_cover
{% else %}
cover.open_cover
{% endif %}