Hi,
While taking a look at intents docs i noticed the use of ‘service_template’ for the first time and I really like it, surprised me how powerful HA is once again.
I’ve implemented it into automation and merged two existing rules into one, their purpose is to toggle the entrance light on a single click (xiaomi round buttons), however i was wondering if this could be less efficient (on resource usage and most importantly, latency) than having two separate rules?
Thank you.
Old set of rules:
- alias: 'Entrance Light On (Round Button, Single)'
trigger:
- platform: event
event_type: click
event_data:
entity_id: binary_sensor.switch_158d000183c7d5
click_type: single # options: single, double, long_click_press
condition:
condition: and
conditions:
- condition: state
entity_id: light.entrance
state: 'off'
- condition: state
entity_id: group.portable_devices
state: 'home'
action:
service: scene.turn_on
entity_id: scene.light_soft
- alias: 'Entrance Light Off (Round Button Single)'
trigger:
- platform: event
event_type: click
event_data:
entity_id: binary_sensor.switch_158d000183c7d5
click_type: single # options: single, double, long_click_press
condition:
condition: and
conditions:
- condition: state
entity_id: light.entrance
state: 'on'
- condition: state
entity_id: group.portable_devices
state: 'home'
action:
service: light.turn_off
entity_id: light.entrance
Merged:
- alias: 'Entrance Light On Round Button (Single)'
trigger:
- platform: event
event_type: click
event_data:
entity_id: binary_sensor.switch_158d000183c7d5
click_type: single # options: single, double, long_click_press
condition:
- condition: state
entity_id: group.portable_devices
state: 'home'
action:
service_template: >
{%- if is_state('light.entrance', 'off') -%}
scene.turn_on
{%- else -%}
light.turn_off
{%- endif -%}
data_template:
entity_id: >
{%- if is_state('light.entrance', 'off') -%}
scene.light_soft
{%- else -%}
light.entrance
{%- endif -%}