This repository has been archived on 2023-06-10. You can view files and clone it, but cannot push or open issues or pull requests.
homeassistant-config/packages/button/button_logic.yaml
2022-08-07 20:10:43 +02:00

446 lines
11 KiB
YAML

script:
#----------------------------------------------------------------------------------#
# L/R
#----------------------------------------------------------------------------------#
# Left
pos_left_incr:
alias: pos_left_incr
sequence:
- if:
- condition: numeric_state
entity_id: input_number.pos_right
above: '0'
then:
- service: input_number.set_value
data:
value: 0
target:
entity_id: input_number.pos_right
else:
- if:
- condition: numeric_state
entity_id: input_number.pos_left
above: '3'
then:
- service: input_number.set_value
data:
value: 0
target:
entity_id: input_number.pos_left
else:
- service: input_number.increment
target:
entity_id: input_number.pos_left
# Restart/Start the timer
- service: timer.cancel
target:
entity_id: timer.pos_timer
- service: timer.start
target:
entity_id: timer.pos_timer
mode: single
# Right
pos_right_incr:
alias: pos_right_incr
sequence:
- if:
- condition: numeric_state
entity_id: input_number.pos_left
above: '0'
then:
- service: input_number.set_value
data:
value: 0
target:
entity_id: input_number.pos_left
else:
- if:
- condition: numeric_state
entity_id: input_number.pos_right
above: '2'
then:
- service: input_number.set_value
data:
value: 0
target:
entity_id: input_number.pos_right
else:
- service: input_number.increment
target:
entity_id: input_number.pos_right
# Restart/Start the timer
- service: timer.cancel
target:
entity_id: timer.pos_timer
- service: timer.start
target:
entity_id: timer.pos_timer
mode: single
#----------------------------------------------------------------------------------#
# Up/Down
#----------------------------------------------------------------------------------#
# Up
pos_up:
alias: pos_up
sequence:
# 0,0
- if:
- condition: and
conditions:
- condition: state
entity_id: input_number.pos_left
state: "0.0"
- condition: state
entity_id: input_number.pos_right
state: "0.0"
then:
- service: light.turn_on
target:
entity_id: light.all_lights
# 1,0 Ceiling
- if:
- condition:
- condition: state
entity_id: input_number.pos_left
state: "1.0"
then:
- service: light.turn_on
target:
entity_id: light.ceiling
# 2,0 Bed
- if:
- condition:
- condition: state
entity_id: input_number.pos_left
state: "2.0"
then:
- service: light.turn_on
target:
entity_id: light.bed_ceiling
# 3,0 Indirect
- if:
- condition:
- condition: state
entity_id: input_number.pos_left
state: "3.0"
then:
- service: light.turn_on
target:
entity_id: light.all_indirect
# 4,0 All Lights
- if:
- condition:
- condition: state
entity_id: input_number.pos_left
state: "4.0"
then:
- service: light.turn_on
target:
entity_id: light.all_lights
# 0,1 Adaptive
- if:
- condition:
- condition: state
entity_id: input_number.pos_right
state: "1.0"
then:
- service: scene.turn_on
target:
entity_id: scene.light_adaptive
# 0,2 Night
- if:
- condition:
- condition: state
entity_id: input_number.pos_right
state: "2.0"
then:
- service: scene.turn_on
target:
entity_id: scene.light_night
# 0,3 Bright
- if:
- condition:
- condition: state
entity_id: input_number.pos_right
state: "3.0"
then:
- service: scene.turn_on
target:
entity_id: scene.light_bright
mode: single
# Down
pos_down:
alias: pos_down
sequence:
# 0,0
- if:
- condition: and
conditions:
- condition: state
entity_id: input_number.pos_left
state: "0.0"
- condition: state
entity_id: input_number.pos_right
state: "0.0"
then:
- service: light.turn_off
target:
entity_id: light.all_lights
# 1,0 Ceiling
- if:
- condition:
- condition: state
entity_id: input_number.pos_left
state: "1.0"
then:
- service: light.turn_off
target:
entity_id: light.ceiling
# 2,0 Bed
- if:
- condition:
- condition: state
entity_id: input_number.pos_left
state: "2.0"
then:
- service: light.turn_off
target:
entity_id: light.bed_ceiling
# 3,0 Indirect
- if:
- condition:
- condition: state
entity_id: input_number.pos_left
state: "3.0"
then:
- service: light.turn_off
target:
entity_id: light.all_indirect
# 4,0 All Lights
- if:
- condition:
- condition: state
entity_id: input_number.pos_left
state: "4.0"
then:
- service: light.turn_off
target:
entity_id: light.all_lights
mode: single
#----------------------------------------------------------------------------------#
# Dimming
#----------------------------------------------------------------------------------#
button_brightness_up:
sequence:
- service: light.turn_on
data_template:
entity_id: light.direct
brightness: >-
{% set current = states.light.direct.attributes.brightness|default(0)|int %}
{% set step = 100 %}
{% set next = current + step %}
{% if next > 255 %}
{% set next = 255 %}
{% endif %}
{{ next }}
- delay:
milliseconds: 1
- service: script.turn_on
data:
entity_id: script.button_brightness_up_loop
button_brightness_up_loop:
sequence:
- service: script.turn_on
data:
entity_id: script.button_brightness_up
button_brightness_down:
sequence:
- service: light.turn_on
data_template:
entity_id: light.direct
brightness: >-
{% set current = states.light.direct.attributes.brightness|default(0)|int %}
{% set step = 100 %}
{% set next = current - step %}
{% if next < 1 %}
{% set next = 1 %}
{% endif %}
{{ next }}
- delay:
milliseconds: 1
- service: script.turn_on
data:
entity_id: script.button_brightness_down_loop
button_brightness_down_loop:
sequence:
- service: script.turn_on
data:
entity_id: script.button_brightness_down
#------------------------------------------------------------------------------------#
# Automations
#------------------------------------------------------------------------------------#
automation:
# Timer
- alias: pos_timer_reset
mode: single
trigger:
- platform: event
event_type: timer.finished
event_data:
entity_id: timer.pos_timer
action:
- service: input_number.set_value
data:
value: 0
target:
entity_id:
- input_number.pos_left
- input_number.pos_right
# Pos 1,0 Ceiling
- alias: pos_1_0_flash
mode: single
trigger:
- platform: state
entity_id:
- input_number.pos_left
to: "1.0"
action:
- service: script.light_ceiling_save
- delay:
hours: 0
minutes: 0
seconds: 0
milliseconds: 500
- service: light.turn_on
data:
effect: Twitter
target:
entity_id: light.ceiling
- delay:
hours: 0
minutes: 0
seconds: 1
milliseconds: 0
- service: script.light_ceiling_restore
# Pos 2,0 Ceiling Bed
- alias: pos_2_0_flash
mode: single
trigger:
- platform: state
entity_id:
- input_number.pos_left
to: "2.0"
action:
- service: script.light_ceiling_bed_save
- delay:
hours: 0
minutes: 0
seconds: 0
milliseconds: 500
- service: light.turn_on
data:
effect: Twitter
target:
entity_id: light.bed_ceiling
- delay:
hours: 0
minutes: 0
seconds: 1
milliseconds: 0
- service: script.light_ceiling_bed_restore
# Pos 3,0 Indirect
- alias: pos_3_0_flash
mode: single
trigger:
- platform: state
entity_id:
- input_number.pos_left
to: "3.0"
action:
- service: script.light_indirect_save
- delay:
hours: 0
minutes: 0
seconds: 0
milliseconds: 500
- service: light.turn_on
data:
effect: Twitter
target:
entity_id: light.all_indirect
- delay:
hours: 0
minutes: 0
seconds: 1
milliseconds: 0
- service: script.light_indirect_restore
# Pos 4,0 All Lights
- alias: pos_4_0_flash
mode: single
trigger:
- platform: state
entity_id:
- input_number.pos_left
to: "4.0"
action:
- service: script.light_store_save
- delay:
hours: 0
minutes: 0
seconds: 0
milliseconds: 500
- service: light.turn_on
data:
effect: Twitter
target:
entity_id: light.all_lights
- delay:
hours: 0
minutes: 0
seconds: 1
milliseconds: 0
- service: script.light_store_restore
# Pos 0,1 Adaptive
- alias: pos_0_1_flash
mode: single
trigger:
- platform: state
entity_id:
- input_number.pos_right
to: "1.0"
action:
- service: scene.turn_on
target:
entity_id: scene.light_adaptive
# Pos 0,2
- alias: pos_0_2_flash
mode: single
trigger:
- platform: state
entity_id:
- input_number.pos_right
to: "2.0"
action:
- service: scene.turn_on
target:
entity_id: scene.light_night
# Pos 0,3
- alias: pos_0_3_flash
mode: single
trigger:
- platform: state
entity_id:
- input_number.pos_right
to: "3.0"
action:
- service: scene.turn_on
target:
entity_id: scene.light_bright