Implement switches as automations

This commit is contained in:
2020-12-27 17:13:10 +02:00
parent a4beb1d8af
commit db41798544
9 changed files with 488 additions and 467 deletions
@@ -8,12 +8,6 @@ input_number:
icon: mdi:speaker
sensor:
- platform: mqtt
name: "Bathroom switch click"
state_topic: "z2m_deconz/bathroom_switch"
availability_topic: "z2m_deconz/bridge/state"
icon: "mdi:toggle-switch"
value_template: "{{ value_json.click }}"
- platform: mqtt
name: "Bathroom switch battery"
state_topic: "z2m_deconz/bathroom_switch"
@@ -21,12 +15,6 @@ sensor:
unit_of_measurement: "%"
device_class: "battery"
value_template: "{{ value_json.battery }}"
- platform: mqtt
name: "Bathroom switch action"
state_topic: "z2m_deconz/bathroom_switch"
availability_topic: "z2m_deconz/bridge/state"
icon: "mdi:gesture-double-tap"
value_template: "{{ value_json.action }}"
- platform: mqtt
name: "Bathroom switch LQI"
state_topic: "z2m_deconz/bathroom_switch"
@@ -36,37 +24,26 @@ sensor:
value_template: "{{ value_json.linkquality }}"
automation:
- alias: Media · Sonos · Volume up on bathroom switch click
trigger:
platform: mqtt
topic: "z2m_deconz/bathroom_switch"
condition:
- condition: state
entity_id: sensor.bathroom_switch_click
state: 'single'
action:
- service: media_player.volume_set
entity_id: media_player.bathroom
data_template:
volume_level: >-
- alias: Bathroom · Switch
use_blueprint:
path: aqara_switch.yaml
input:
z2m_topic: "z2m_deconz/bathroom_switch"
click:
- service: media_player.volume_set
entity_id: media_player.bathroom
data_template:
volume_level: >-
{% if state_attr('media_player.bathroom', 'volume_level')|float > (states('input_number.bathroom_high_volume')|float - 0.05) %}
0.25
{% else %}
{{ states('input_number.bathroom_high_volume')|float }}
{% endif %}
{% if state_attr('media_player.bathroom', 'volume_level')|float > (states('input_number.bathroom_high_volume')|float - 0.05) %}
0.25
{% else %}
{{ states('input_number.bathroom_high_volume')|float }}
{% endif %}
- alias: Youtube · play latest pds on bathroom switch dobule click
trigger:
platform: mqtt
topic: "z2m_deconz/bathroom_switch"
condition:
- condition: state
entity_id: sensor.bathroom_switch_click
state: 'double'
action:
- service: media_player.volume_set
entity_id: media_player.bathroom
data_template:
volume_level: "{{ states('input_number.bathroom_high_volume')|float }}"
- service: script.youtube_play_latest_pds
double_click:
- service: media_player.volume_set
entity_id: media_player.bathroom
data_template:
volume_level: "{{ states('input_number.bathroom_high_volume')|float }}"
- service: script.youtube_play_latest_pds
@@ -22,155 +22,95 @@ sensor:
automation:
- alias: Bedroom · Opple
mode: queued
trigger:
platform: mqtt
topic: "z2m_deconz/opple_1"
action:
- choose:
- conditions:
- condition: state
entity_id: sensor.bedroom_opple_action
state: 'button_1_single'
sequence:
- service: light.turn_off
use_blueprint:
path: oppo_6_btn_switch.yaml
input:
opple_z2m_name: "z2m_deconz/opple_1"
action_sensor: sensor.bedroom_opple_action
button_1_single:
- service: light.turn_off
entity_id: light.master_bedroom
button_2_single:
- service: light.turn_on
data_template:
entity_id: light.master_bedroom
brightness_pct: >-
- conditions:
- condition: state
entity_id: sensor.bedroom_opple_action
state: 'button_2_single'
sequence:
- service: light.turn_on
data_template:
entity_id: light.master_bedroom
brightness_pct: >-
{% if not is_state('input_select.house_mode', 'day') %}
40
{% else %}
100
{% endif %}
{% if not is_state('input_select.house_mode', 'day') %}
40
{% else %}
100
{% endif %}
button_1_double:
- service: light.turn_off
entity_id: light.master_bedroom_main
- conditions:
- condition: state
entity_id: sensor.bedroom_opple_action
state: 'button_1_double'
sequence:
- service: light.turn_off
button_2_double:
- service: light.turn_on
data_template:
entity_id: light.master_bedroom_main
brightness_pct: >-
- conditions:
- condition: state
entity_id: sensor.bedroom_opple_action
state: 'button_2_double'
sequence:
- service: light.turn_on
data_template:
entity_id: light.master_bedroom_main
brightness_pct: >-
{% if not is_state('input_select.house_mode', 'day') %}
40
{% else %}
100
{% endif %}
{% if not is_state('input_select.house_mode', 'day') %}
40
{% else %}
100
{% endif %}
button_1_triple:
- service: light.turn_off
entity_id:
- light.bedside
- light.bed_led
- conditions:
- condition: state
entity_id: sensor.bedroom_opple_action
state: 'button_1_triple'
sequence:
- service: light.turn_off
button_2_triple:
- service: light.turn_on
data_template:
entity_id:
- light.bedside
- light.bed_led
brightness_pct: >-
- conditions:
- condition: state
entity_id: sensor.bedroom_opple_action
state: 'button_2_triple'
sequence:
- service: light.turn_on
data_template:
entity_id:
- light.bedside
- light.bed_led
brightness_pct: >-
{% if not is_state('input_select.house_mode', 'day') %}
40
{% else %}
100
{% endif %}
{% if not is_state('input_select.house_mode', 'day') %}
40
{% else %}
100
{% endif %}
button_3_single:
- service: media_player.media_play_pause
entity_id: media_player.master_bedroom
- conditions:
- condition: state
entity_id: sensor.bedroom_opple_action
state: 'button_3_single'
sequence:
- service: media_player.media_play_pause
entity_id: media_player.master_bedroom
button_3_double:
- service: script.sonos_join_tv
- conditions:
- condition: state
entity_id: sensor.bedroom_opple_action
state: 'button_3_double'
sequence:
- service: script.sonos_join_tv
button_3_triple:
- service: script.sonos_join_bedroom
- conditions:
- condition: state
entity_id: sensor.bedroom_opple_action
state: 'button_3_triple'
sequence:
- service: script.sonos_join_bedroom
button_3_release:
- service: media_player.play_next
entity_id: media_player.master_bedroom
- conditions:
- condition: state
entity_id: sensor.bedroom_opple_action
state: 'button_3_release'
sequence:
- service: media_player.play_next
entity_id: media_player.master_bedroom
button_4_single:
- service: script.music_play
- conditions:
- condition: state
entity_id: sensor.bedroom_opple_action
state: 'button_4_single'
sequence:
- service: script.music_play
button_4_double:
- service: script.music_play
data:
playlist: 'Starred'
- conditions:
- condition: state
entity_id: sensor.bedroom_opple_action
state: 'button_4_double'
sequence:
- service: script.music_play
data:
playlist: 'Starred'
button_4_triple:
- service: script.music_play
data:
playlist: 'Retro'
- conditions:
- condition: state
entity_id: sensor.bedroom_opple_action
state: 'button_4_triple'
sequence:
- service: script.music_play
data:
playlist: 'Retro'
button_5_single:
- service: fan.turn_off
entity_id: fan.philips_airpurifier
- conditions:
- condition: state
entity_id: sensor.bedroom_opple_action
state: 'button_5_single'
sequence:
- service: fan.turn_off
entity_id: fan.philips_airpurifier
- conditions:
- condition: state
entity_id: sensor.bedroom_opple_action
state: 'button_6_single'
sequence:
- service: fan.turn_on
entity_id: fan.philips_airpurifier
button_6_single:
- service: fan.turn_on
entity_id: fan.philips_airpurifier
@@ -1,10 +1,4 @@
sensor:
- platform: mqtt
name: "Bedside switch click"
state_topic: "z2m_deconz/bedside_switch"
availability_topic: "z2m_deconz/bridge/state"
icon: "mdi:toggle-switch"
value_template: "{{ value_json.click }}"
- platform: mqtt
name: "Bedside switch battery"
state_topic: "z2m_deconz/bedside_switch"
@@ -12,12 +6,6 @@ sensor:
unit_of_measurement: "%"
device_class: "battery"
value_template: "{{ value_json.battery }}"
- platform: mqtt
name: "Bedside switch action"
state_topic: "z2m_deconz/bedside_switch"
availability_topic: "z2m_deconz/bridge/state"
icon: "mdi:gesture-double-tap"
value_template: "{{ value_json.action }}"
- platform: mqtt
name: "Bedside switch LQI"
state_topic: "z2m_deconz/bedside_switch"
@@ -27,55 +15,39 @@ sensor:
value_template: "{{ value_json.linkquality }}"
automation:
- alias: Lighting · Master bedroom · Toggle lights on bedside switch single click
trigger:
platform: mqtt
topic: "z2m_deconz/bedside_switch"
condition:
- condition: state
entity_id: sensor.bedside_switch_click
state: 'single'
action:
- service: light.toggle
data_template:
entity_id: >-
- alias: Bedroom · Bedside Switch
use_blueprint:
path: aqara_switch.yaml
input:
z2m_topic: "z2m_deconz/bedside_switch"
click:
- service: light.toggle
data_template:
entity_id: >-
{% if is_state('input_select.house_mode', 'day') %}
light.master_bedroom_main
{% elif is_state('input_select.house_mode', 'bed') %}
light.bedside, light.bed_led
{% elif is_state('input_select.house_mode', 'night') %}
light.bed_led
{% endif %}
brightness_pct: >-
{% if is_state('input_select.house_mode', 'day') %}
light.master_bedroom_main
{% elif is_state('input_select.house_mode', 'bed') %}
light.bedside, light.bed_led
{% elif is_state('input_select.house_mode', 'night') %}
light.bed_led
{% endif %}
brightness_pct: >-
{% if is_state('input_select.house_mode', 'night') %}
40
{% else %}
100
{% endif %}
{% if is_state('input_select.house_mode', 'night') %}
40
{% else %}
100
{% endif %}
- alias: Lighting · Master bedroom · Toggle ambient lights on bedside switch double click
trigger:
platform: mqtt
topic: "z2m_deconz/bedside_switch"
condition:
- condition: state
entity_id: sensor.bedside_switch_click
state: 'double'
action:
- service: light.toggle
data_template:
entity_id:
- light.bedside
- light.bed_led
brightness_pct: 100
double_click:
- service: light.toggle
data_template:
entity_id:
- light.bedside
- light.bed_led
brightness_pct: 100
- alias: House mode · Toggle on bedside switch hold
trigger:
platform: state
entity_id: sensor.bedside_switch_action
to: 'hold'
action:
- service: input_select.select_next
entity_id: input_select.house_mode
hold:
- service: input_select.select_next
entity_id: input_select.house_mode
@@ -1,10 +1,4 @@
sensor:
- platform: mqtt
name: "Desk switch click"
state_topic: "z2m_deconz/desk_switch"
availability_topic: "z2m_deconz/bridge/state"
icon: "mdi:toggle-switch"
value_template: "{{ value_json.click }}"
- platform: mqtt
name: "Desk switch battery"
state_topic: "z2m_deconz/desk_switch"
@@ -12,12 +6,6 @@ sensor:
unit_of_measurement: "%"
device_class: "battery"
value_template: "{{ value_json.battery }}"
- platform: mqtt
name: "Desk switch action"
state_topic: "z2m_deconz/desk_switch"
availability_topic: "z2m_deconz/bridge/state"
icon: "mdi:gesture-double-tap"
value_template: "{{ value_json.action }}"
- platform: mqtt
name: "Desk switch LQI"
state_topic: "z2m_deconz/desk_switch"
@@ -28,51 +16,35 @@ sensor:
automation:
- alias: Lighting · Living Room · Toggle ceiling lights on desk switch single click
trigger:
platform: mqtt
topic: "z2m_deconz/desk_switch"
condition:
- condition: state
entity_id: sensor.desk_switch_click
state: 'single'
action:
- service: light.toggle
data_template:
entity_id: light.living_room_main
brightness_pct: >-
- alias: Living room · Desk switch
use_blueprint:
path: aqara_switch.yaml
input:
z2m_topic: "z2m_deconz/desk_switch"
click:
- service: light.toggle
data_template:
entity_id: light.living_room_main
brightness_pct: >-
{% if is_state('input_select.house_mode', 'night') %}
40
{% else %}
100
{% endif %}
{% if is_state('input_select.house_mode', 'night') %}
40
{% else %}
100
{% endif %}
- alias: Lighting · Living Room · Toggle ambient lights on desk switch double click
trigger:
platform: mqtt
topic: "z2m_deconz/desk_switch"
condition:
- condition: state
entity_id: sensor.desk_switch_click
state: 'double'
action:
- service: light.toggle
data_template:
entity_id: light.living_room_ambient
brightness_pct: >-
double_click:
- service: light.toggle
data_template:
entity_id: light.living_room_ambient
brightness_pct: >-
{% if is_state('input_select.house_mode', 'night') %}
40
{% else %}
100
{% endif %}
{% if is_state('input_select.house_mode', 'night') %}
40
{% else %}
100
{% endif %}
- alias: Music · Living Room · Play pause on desk switch hold
trigger:
platform: state
entity_id: sensor.desk_switch_action
to: 'hold'
action:
- service: media_player.media_play_pause
entity_id: media_player.living_room
hold:
- service: media_player.media_play_pause
entity_id: media_player.living_room
@@ -22,188 +22,112 @@ sensor:
automation:
- alias: Living room · Opple
mode: queued
trigger:
platform: mqtt
topic: "z2m_deconz/opple_2"
action:
- choose:
- conditions:
- condition: state
entity_id: sensor.living_room_opple_action
state: 'button_1_single'
sequence:
- service: light.turn_off
entity_id: light.living_room
use_blueprint:
path: oppo_6_btn_switch.yaml
input:
opple_z2m_name: "z2m_deconz/opple_2"
action_sensor: sensor.living_room_opple_action
- conditions:
- condition: state
entity_id: sensor.living_room_opple_action
state: 'button_2_single'
sequence:
- service: light.turn_on
entity_id: light.living_room
button_1_single:
- service: light.turn_off
entity_id: light.living_room
- conditions:
- condition: state
entity_id: sensor.living_room_opple_action
state: 'button_1_double'
sequence:
- service: light.turn_off
entity_id: light.living_room_main
button_2_single:
- service: light.turn_on
entity_id: light.living_room
- conditions:
- condition: state
entity_id: sensor.living_room_opple_action
state: 'button_2_double'
sequence:
- service: light.turn_on
entity_id: light.living_room_main
button_1_double:
- service: light.turn_off
entity_id: light.living_room_main
- conditions:
- condition: state
entity_id: sensor.living_room_opple_action
state: 'button_1_triple'
sequence:
- service: light.turn_off
entity_id: light.living_room_ambient
button_2_double:
- service: light.turn_on
entity_id: light.living_room_main
- conditions:
- condition: state
entity_id: sensor.living_room_opple_action
state: 'button_2_triple'
sequence:
- service: light.turn_on
entity_id: light.living_room_ambient
button_1_triple:
- service: light.turn_off
entity_id: light.living_room_ambient
- conditions:
- condition: state
entity_id: sensor.living_room_opple_action
state: 'button_2_release'
sequence:
- service: script.scene_living_room_ambient_neon
button_2_triple:
- service: light.turn_on
entity_id: light.living_room_ambient
- conditions:
- condition: state
entity_id: sensor.living_room_opple_action
state: 'button_3_single'
sequence:
- service: media_player.media_play_pause
entity_id: media_player.living_room
button_2_release:
- service: script.scene_living_room_ambient_neon
- conditions:
- condition: state
entity_id: sensor.living_room_opple_action
state: 'button_3_double'
sequence:
- service: script.sonos_join_tv
button_3_single:
- service: media_player.media_play_pause
entity_id: media_player.living_room
- conditions:
- condition: state
entity_id: sensor.living_room_opple_action
state: 'button_3_triple'
sequence:
- service: script.sonos_join_bedroom
button_3_double:
- service: script.sonos_join_tv
- conditions:
- condition: state
entity_id: sensor.living_room_opple_action
state: 'button_3_release'
sequence:
- service: media_player.play_next
entity_id: media_player.living_room
button_3_triple:
- service: script.sonos_join_bedroom
- conditions:
- condition: state
entity_id: sensor.living_room_opple_action
state: 'button_4_single'
sequence:
- service: script.music_play
button_3_release:
- service: media_player.play_next
entity_id: media_player.living_room
- conditions:
- condition: state
entity_id: sensor.living_room_opple_action
state: 'button_4_double'
sequence:
- service: script.music_play
data:
playlist: 'Starred'
button_4_single:
- service: script.music_play
- conditions:
- condition: state
entity_id: sensor.living_room_opple_action
state: 'button_4_triple'
sequence:
- service: script.music_play
data:
playlist: 'Retro'
button_4_double:
- service: script.music_play
data:
playlist: 'Starred'
- conditions:
- condition: state
entity_id: sensor.living_room_opple_action
state: 'button_5_single'
sequence:
- service: climate.turn_off
entity_id: climate.toshiba_ac
button_4_triple:
- service: script.music_play
data:
playlist: 'Retro'
- conditions:
- condition: state
entity_id: sensor.living_room_opple_action
state: 'button_5_double'
sequence:
- service: climate.set_temperature
entity_id: climate.toshiba_ac
data_template:
temperature: "{{ state_attr('climate.toshiba_ac', 'temperature') | int -1}}"
button_5_single:
- service: climate.turn_off
entity_id: climate.toshiba_ac
- conditions:
- condition: state
entity_id: sensor.living_room_opple_action
state: 'button_6_single'
sequence:
- service: script.toshiba_ac_on_cool
button_5_double:
- service: climate.set_temperature
entity_id: climate.toshiba_ac
data_template:
temperature: "{{ state_attr('climate.toshiba_ac', 'temperature') | int -1}}"
- conditions:
- condition: state
entity_id: sensor.living_room_opple_action
state: 'button_6_double'
sequence:
- service: climate.set_temperature
entity_id: climate.toshiba_ac
data_template:
temperature: "{{ state_attr('climate.toshiba_ac', 'temperature') | int +1}}"
button_6_single:
- service: script.toshiba_ac_on_cool
- conditions:
- condition: state
entity_id: sensor.living_room_opple_action
state: 'button_6_triple'
sequence:
- service: automation.turn_off
entity_id: automation.tv_sonos_join_tv_on_google_cast
button_6_double:
- service: climate.set_temperature
entity_id: climate.toshiba_ac
data_template:
temperature: "{{ state_attr('climate.toshiba_ac', 'temperature') | int +1}}"
- service: script.tv_fireplace
button_6_triple:
- service: automation.turn_off
entity_id: automation.tv_sonos_join_tv_on_google_cast
- service: sonos.join
entity_id:
- media_player.kitchen
- media_player.bathroom
data:
master: media_player.master_bedroom
- service: script.tv_fireplace
# Music play, without the join
- service: media_player.volume_set
entity_id: media_player.master_bedroom
data:
volume_level: 0.2
- service: media_player.shuffle_set
entity_id: media_player.master_bedroom
data:
shuffle: true
- service: media_player.select_source
entity_id: media_player.master_bedroom
data:
source: "Evening Chill"
- service: sonos.join
entity_id:
- media_player.kitchen
- media_player.bathroom
data:
master: media_player.master_bedroom
- delay: 00:01:00
- service: automation.turn_on
entity_id: automation.tv_sonos_join_tv_on_google_cast
# Music play, without the join
- service: media_player.volume_set
entity_id: media_player.master_bedroom
data:
volume_level: 0.2
- service: media_player.shuffle_set
entity_id: media_player.master_bedroom
data:
shuffle: true
- service: media_player.select_source
entity_id: media_player.master_bedroom
data:
source: "Evening Chill"
- delay: 00:01:00
- service: automation.turn_on
entity_id: automation.tv_sonos_join_tv_on_google_cast