204 lines
6.4 KiB
YAML
204 lines
6.4 KiB
YAML
|
|
# values to store within HA
|
|
variable:
|
|
test_schedule_countdown:
|
|
value: 0
|
|
attributes:
|
|
icon: mdi:clock
|
|
test_schedule_next:
|
|
value: 0
|
|
|
|
# input_boolean:
|
|
# test_schedule_enable:
|
|
|
|
input_number:
|
|
test_schedule_base_hour:
|
|
name: "Hour of Day"
|
|
unit_of_measurement: hours
|
|
initial: 6
|
|
min: 0
|
|
max: 24
|
|
step: 1
|
|
icon: mdi:camera-timer
|
|
test_schedule_base_minute:
|
|
name: "Minute of Day"
|
|
unit_of_measurement: minutes
|
|
initial: 0
|
|
min: 0
|
|
max: 45
|
|
step: 15
|
|
icon: mdi:camera-timer
|
|
|
|
# use sensor.test_schedule_repeatin to get corresponding value for option
|
|
input_select:
|
|
test_schedule_repeatin:
|
|
name: Repeat Every
|
|
icon: mdi:repeat
|
|
initial: 12 Hours
|
|
options:
|
|
- 3 Hours
|
|
- 6 Hours
|
|
- 12 Hours
|
|
- Day
|
|
- Every Other Day
|
|
- Every Third Day
|
|
- Every Week
|
|
values:
|
|
- 3
|
|
- 6
|
|
- 12
|
|
- 24
|
|
- 48
|
|
- 72
|
|
- 168
|
|
|
|
sensor:
|
|
- platform: template # Derived variables
|
|
sensors:
|
|
# format the next timestamp for humans
|
|
test_schedule_next:
|
|
friendly_name: Next run to start at
|
|
entity_id: variable.test_schedule_next_timestamp
|
|
value_template: '{{ states.variable.test_schedule_next.state | int | timestamp_custom("%A, %d %h %H:%M") }}'
|
|
test_schedule_countdown:
|
|
friendly_name: Countdown to next run
|
|
entity_id: variable.test_schedule_countdown
|
|
# value_template: '{{ states.variable.test_schedule_countdown.state | int | timestamp_custom("%A, %d %h %H:%M") }}'
|
|
value_template: >-
|
|
{% set time = states.variable.test_schedule_countdown.state | int %}
|
|
{% set minutes = ((time % 3600) / 60) | int %}
|
|
{% set hours = ((time % 86400) / 3600) | int %}
|
|
{% set days = (time / 86400) | int %}
|
|
{{time}} seconds is {{ days }}:{{ hours }}:{{minutes}} (D:H:M)
|
|
test_schedule_delta:
|
|
entity_id: input_select.test_schedule_repeatin
|
|
unit_of_measurement: 'hours'
|
|
value_template: >
|
|
{% for option in state_attr("input_select.test_schedule_repeatin", "options") -%}
|
|
{% if is_state("input_select.test_schedule_repeatin", option) -%}
|
|
{{ state_attr("input_select.test_schedule_repeatin", 'values')[loop.index - 1] }}
|
|
{%- endif %}
|
|
{%- endfor %}
|
|
|
|
|
|
switch:
|
|
- platform: mqtt
|
|
name: "Scheduler Test Solenoid"
|
|
state_topic: "status/irrigation/zone_1"
|
|
command_topic: "set/irrigation/zone_1"
|
|
payload_on: "ON"
|
|
payload_off: "OFF"
|
|
qos: 0
|
|
retain: true
|
|
|
|
|
|
script:
|
|
enable_test_schedule:
|
|
sequence:
|
|
- event: ENABLE_SCHEDULE
|
|
- service: variable.set_variable
|
|
data:
|
|
variable: test_schedule_countdown
|
|
value_template: '{{ states.variable.test_schedule_next_timestamp.state | int - as_timestamp(now()) }}'
|
|
# value_template: "{{ as_timestamp(now()) }}"
|
|
# - service: variable.set_variable
|
|
# data:
|
|
# variable: test_schedule_dummy_device
|
|
# value: 'ON'
|
|
# - service: automation.turn_on
|
|
# entity_id: automation.test_schedule_countdown
|
|
# - service: automation.turn_on
|
|
# data:
|
|
# entity_id: automation.test_timer_zero_trigger
|
|
disable_test_schedule:
|
|
sequence:
|
|
- service: automation.turn_off
|
|
data:
|
|
entity_id: automation.test_schedule_countdown
|
|
- service: variable.set_variable
|
|
data:
|
|
variable: test_schedule_countdown
|
|
value: 0
|
|
|
|
|
|
automation:
|
|
- alias: test_schedule_countdown
|
|
initial_state: false
|
|
trigger:
|
|
platform: time_pattern
|
|
seconds: '/1'
|
|
action:
|
|
- service: variable.set_variable
|
|
data:
|
|
variable: test_schedule_countdown
|
|
value_template: '{{ [((variable.state | int) - 1), 0] | max }}'
|
|
# - alias: test_schedule_changed
|
|
# # initial_state: false
|
|
# trigger:
|
|
# platform: state
|
|
# action:
|
|
# - service: variable.set_variable
|
|
# data:
|
|
# variable: test_schedule_countdown
|
|
# value_template: '{{ states.variable.test_schedule_next_timestamp.state | int - as_timestamp(now()) }}'
|
|
|
|
|
|
# - service: automation.turn_off
|
|
# data:
|
|
# entity_id: automation.test_timer_zero_trigger
|
|
# - service: variable.set_variable
|
|
# data:
|
|
# variable: test_timer_device
|
|
# value: 'OFF'
|
|
|
|
#
|
|
#
|
|
|
|
# - alias: test_timer_zero_trigger
|
|
# initial_state: false
|
|
# trigger:
|
|
# platform: numeric_state
|
|
# entity_id: variable.test_timer_countdown
|
|
# below: 1
|
|
# action:
|
|
# - service: automation.turn_off
|
|
# entity_id: automation.test_timer_countdown
|
|
# - service: variable.set_variable
|
|
# data:
|
|
# variable: test_timer_device
|
|
# value: 'OFF'
|
|
# #
|
|
|
|
|
|
|
|
|
|
|
|
# return corresponding value from input_select option of same name
|
|
# test_schedule_delta:
|
|
# entity_id: input_select.test_schedule_repeatin
|
|
# value_template: >
|
|
# {% for option in state_attr("input_select.test_schedule_repeatin", "options") -%}
|
|
# {% if is_state("input_select.test_schedule_repeatin", option) -%}
|
|
# {{ state_attr("input_select.test_schedule_repeatin", 'values')[loop.index - 1] }}
|
|
# {%- endif %}
|
|
# {%- endfor %}
|
|
# test_schedule_base_timestamp:
|
|
# entity_id: input_datetime.test_schedule_base
|
|
# value_template: >
|
|
# {{
|
|
# as_timestamp(now())
|
|
# - ( now().second + now().minute | int * 60 + now().hour | int * 3600 )
|
|
# + state_attr('input_datetime.test_schedule_base','hour')|int * 3600
|
|
# + state_attr('input_datetime.test_schedule_base','minute') * 60
|
|
# }}
|
|
# value_template: "{{ (state_attr('input_datetime.test_schedule_base','hour')|int * 3600 + state_attr('input_datetime.test_schedule_base','minute')|int * 60) | timestamp_custom('%A, %d %h %H:%M') }}"
|
|
# value_template: >
|
|
# "{{ (state_attr('input_datetime.test_schedule_base','hour')|int * 3600 +
|
|
# state_attr('input_datetime.test_schedule_base','minute')|int * 60 +
|
|
# as_timestamp(now()))
|
|
# | timestamp_custom("%A, %d %h %H:%M") }}"
|
|
|
|
# value_template: "{{ states(input_datetime.test_schedule_base) }}"
|
|
# {{ as_timestamp(now()) + as_timestamp(states.input_datetime.test_schedule_base) }}
|
|
# {{ as_timestamp(now()) + as_timestamp(states.input_datetime.test_schedule_base) }}
|