Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ###########################################################
- ##
- ## Counter
- ##
- ###########################################################
- counter:
- click_times:
- initial: 0
- step: 1
- ###########################################################
- ##
- ## Timer
- ##
- ## if switch over how long times no action it will reset
- ## to default state is 0
- ###########################################################
- timer:
- click_times_timer:
- duration: '00:05:00'
- ###########################################################
- ##
- ## Switch
- ##
- ###########################################################
- switch:
- - platform: template
- switches:
- ########### if need click once
- light_odd: #entity name that you want
- unique_id: "light_odd" #same as entity name
- value_template: >
- {{ ((states("counter.click_times")| int % 2) == 1) and is_state('switch.AAAAAAAA','on') }}
- turn_on:
- - alias: "Set variables"
- variables:
- entities:
- - switch.AAAAAAAA
- delay_times: 500
- - choose:
- # if click times only click once
- - conditions: >
- {{ (states("counter.click_times")| int % 2) == 1 }}
- sequence:
- # off -> on once
- - service: switch.turn_off
- target:
- entity_id: "{{ entities }}"
- - delay:
- milliseconds: "{{ delay_times }}"
- - service: switch.turn_on
- target:
- entity_id: "{{ entities }}"
- - delay:
- milliseconds: "{{ delay_times }}"
- # off -> on twice
- - service: switch.turn_off
- target:
- entity_id: "{{ entities }}"
- - delay:
- milliseconds: "{{ delay_times }}"
- - service: switch.turn_on
- target:
- entity_id: "{{ entities }}"
- # if click times already click twice
- - conditions: >
- {{ (states("counter.click_times")| int % 2) == 0 }}
- sequence:
- # reset counter
- - service: counter.reset
- target:
- entity_id: counter.click_times
- # off -> on once
- - service: switch.turn_off
- target:
- entity_id: "{{ entities }}"
- - delay:
- milliseconds: "{{ delay_times }}"
- - service: switch.turn_on
- target:
- entity_id: "{{ entities }}"
- turn_off:
- service: switch.turn_off
- target:
- entity_id: switch.AAAAAAAA
- ########### if need click twice
- - platform: template
- switches:
- light_even: #entity name that you want
- unique_id: "light_even" #same as entity name
- value_template: >
- {{ ((states("counter.click_times")| int % 2) == 0) and is_state('switch.AAAAAAAA','on') }}
- turn_on:
- - alias: "Set variables"
- variables:
- entities:
- - switch.AAAAAAAA
- delay_times: 500
- - choose:
- # if click times already click twice
- - conditions: >
- {{ (states("counter.click_times")| int % 2) == 0 }}
- sequence:
- # reset counter
- - service: counter.reset
- target:
- entity_id: counter.click_times
- # off -> on once
- - service: switch.turn_off
- target:
- entity_id: "{{ entities }}"
- - delay:
- milliseconds: "{{ delay_times }}"
- - service: switch.turn_on
- target:
- entity_id: "{{ entities }}"
- - delay:
- milliseconds: "{{ delay_times }}"
- # off -> on twice
- - service: switch.turn_off
- target:
- entity_id: "{{ entities }}"
- - delay:
- milliseconds: "{{ delay_times }}"
- - service: switch.turn_on
- target:
- entity_id: "{{ entities }}"
- # if click times only click once
- - conditions: >
- {{ (states("counter.click_times")| int % 2) == 1 }}
- sequence:
- # off -> on once
- - service: switch.turn_off
- target:
- entity_id: "{{ entities }}"
- - delay:
- milliseconds: "{{ delay_times }}"
- - service: switch.turn_on
- target:
- entity_id: "{{ entities }}"
- turn_off:
- service: switch.turn_off
- target:
- entity_id: switch.AAAAAAAA
- ###########################################################
- ##
- ## Automation
- ##
- ###########################################################
- automation:
- - id: click_times_count
- alias: click_times_count
- trigger:
- platform: state
- entity_id: switch.AAAAAAAA
- to: 'on'
- action:
- service: counter.increment
- target:
- entity_id: counter.click_times
- - id: click_times_timer_start
- alias: click_times_timer_start
- trigger:
- platform: state
- entity_id: switch.AAAAAAAA
- action:
- - service: timer.start
- entity_id: timer.click_times_timer
- - id: click_times_reset
- alias: click_times_reset
- initial_state: true
- trigger:
- - platform: event
- event_type: timer.finished
- event_data:
- entity_id: timer.click_times_timer
- action:
- - service: counter.reset
- target:
- entity_id: counter.click_times
- - service: timer.cancel
- entity_id: timer.click_times_timer
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement