####################################################################### ### wymagania: ### 1. variable -> https://github.com/rogro82/hass-variables ### 2. button-card -> https://github.com/custom-cards/button-card ####################################################################### ####################################################################### ### lowelas: ####################################################################### - type: custom:button-card name: > [[[ var temp_name = 'Testowy'; if (states['timer.test_on'].state == 'active') var temp_name = states['sensor.test'].state; if (states['timer.test_delay'].state == 'active') var temp_name = states['sensor.test'].state; return temp_name; ]]] icon: > [[[ var temp_delay = states['timer.test_delay'].state; var temp_icon = 'mdi:toggle-switch'; if (temp_delay == 'active') var temp_icon = 'mdi:toggle-switch-off-outline'; return temp_icon; ]]] entity: switch.test lock: enabled: '[[[ return states["timer.test_delay"].state === "active" ]]]' exemptions: [] styles: lock: - align-items: center - opacity: 0.3 - color: var(--label-badge-red) ####################################################################### ### konfig: ####################################################################### variable: var_testowa: value: 'False' sensor: - platform: template sensors: test: entity_id: - timer.test_on - timer.test_delay value_template: >- {% if is_state('timer.test_on', 'idle') and is_state('timer.test_delay', 'idle') %} 0 {% elif is_state('timer.test_delay', 'active') %} {% set temp_delay = (state_attr('timer.test_delay', 'duration').split(':')[0]|int * 60 * 60)+(state_attr('timer.test_delay', 'duration').split(':')[1]|int * 60)+(state_attr('timer.test_delay', 'duration').split(':')[2]|int) %} {% set temp_now1 = (as_timestamp(now())|int - (states('variable.var_testowa')|int))|int|timestamp_custom('%M:%S') %} {% set temp_now2 = (temp_now1.split(':')[0]|int * 60)+(temp_now1.split(':')[1]|int) %} {{ (temp_delay - temp_now2)|int|timestamp_custom('%M:%S') }} {% else %} {% set temp_delay = (state_attr('timer.test_on', 'duration').split(':')[0]|int * 60 * 60)+(state_attr('timer.test_on', 'duration').split(':')[1]|int * 60)+(state_attr('timer.test_on', 'duration').split(':')[2]|int) %} {% set temp_now1 = (as_timestamp(now())|int - (states('variable.var_testowa')|int))|int|timestamp_custom('%M:%S') %} {% set temp_now2 = (temp_now1.split(':')[0]|int * 60)+(temp_now1.split(':')[1]|int) %} {{ (temp_delay - temp_now2)|int|timestamp_custom('%M:%S') }} {% endif %} timer: test_on: name: test_on duration: '00:05:00' test_delay: name: test_delay duration: '00:45:00' automation: #################### odśwież licznik na przyciku - id: test_refresh alias: test_refresh trigger: - platform: time_pattern seconds: "/2" action: - condition: template value_template: "{{ 'False' if (is_state('timer.test_on', 'idle') and is_state('timer.test_delay', 'idle')) else 'True' }}" - service: homeassistant.update_entity entity_id: - sensor.test - condition: template value_template: "{{ 'True' if (is_state('timer.test_on', 'idle') and is_state('timer.test_delay', 'idle')) else 'False' }}" - service: homeassistant.turn_off entity_id: - automation.test_refresh #################### włącz odświeżanie licznika na przycisku - id: test_refresh_on alias: test_refresh_on trigger: - platform: event event_type: timer.started event_data: entity_id: timer.test_on - platform: event event_type: timer.started event_data: entity_id: timer.test_delay - platform: event event_type: timer.restarted event_data: entity_id: timer.test_on - platform: event event_type: timer.restarted event_data: entity_id: timer.test_delay action: - condition: template value_template: "{{ 'False' if (is_state('timer.test_on', 'idle') and is_state('timer.test_delay', 'idle')) else 'True' }}" - service: homeassistant.turn_on entity_id: - automation.test_refresh #################### wyłącz odświeżanie licznika na przycisku - id: test_refresh_off alias: test_refresh_off trigger: - platform: event event_type: timer.finished event_data: entity_id: timer.test_on - platform: event event_type: timer.finished event_data: entity_id: timer.test_delay action: - condition: template value_template: "{{ 'True' if (is_state('timer.test_on', 'idle') and is_state('timer.test_delay', 'idle')) else 'False' }}" - service: homeassistant.turn_off entity_id: - automation.test_refresh #################### włącz - id: test_on alias: test_on trigger: ## jakiś trigger action: - condition: template value_template: "{{ 'True' if (is_state('timer.test_delay', 'idle') and trigger.to_state.state == 'on') else 'False' }}" - service: timer.start entity_id: timer.test_on - service: variable.set_variable data: variable: var_testowa value_template: "{{ as_timestamp(now())|int }}" - condition: state entity_id: switch.test state: 'off' - service: switch.turn_on entity_id: switch.test #################### wyłącz - id: test_off alias: test_off trigger: - platform: event event_type: timer.finished event_data: entity_id: timer.test_on - platform: event event_type: timer.cancelled event_data: entity_id: timer.test_on action: - condition: state entity_id: switch.test state: 'on' - service: switch.turn_off entity_id: switch.test - service: timer.start entity_id: timer.test_delay - service: variable.set_variable data: variable: var_testowa value_template: "{{ as_timestamp(now())|int }}"