homeassistant/packages/zone1.yaml

205 lines
5.7 KiB
YAML

sensor:
- platform: template
sensors:
# values used for run
zone_1_base_time:
value_template: '{{ "{:02d}".format(states.input_number.zone_1_timer_hours.state|int) }}:{{ "{:02d}".format(states.input_number.zone_1_timer_minutes.state|int) }}'
friendly_name: "Base TOD HH:MM"
zone_1_duration:
value_template: '{{states.input_number.zone_1_duration.state | int}}mins'
friendly_name: "Duration"
zone_1_repeat:
value_template: '{{ "{:02d}".format(states.input_number.zone_1_repeat.state|int)}} hrs'
friendly_name: "Repeat in"
# run computed/state values
zone_1_time_delta:
friendly_name: "Next Run (secs)"
value_template: '{{states.input_number.zone_1_repeat.state|int * 3600}}'
zone_1_next_run:
friendly_name: "Next Run"
value_template: '{{states.sensor.zone_1_timer_next.state}}'
zone_1_last_run:
friendly_name: "Last Run"
value_template: '{{ (as_timestamp(states.switch.zone_1.last_changed)) | timestamp_custom("%A, %d %h %H:%M") }}'
# zone_1_rain_sensor:
# friendly_name: "Rainfall Threshold Sensitivity"
# value_template: >-
# {% if states.sensor.pws_precip_1d.state <= states.input_number.pws_precip_1d_sensitivity.state and states.sensor.pws_precip_today_metric.state <= states.input_number.pws_precip_today_metric_sensitivity.state %}
# dry
# {% else %}
# too wet
# {% endif %}
input_number:
zone_1_timer_minutes:
name: "Minutes"
initial: 0
min: 0
max: 55
step: 5
icon: mdi:timer
zone_1_timer_hours:
name: "Hour"
initial: 6
min: 0
max: 23
step: 1
icon: mdi:timer
zone_1_duration:
name: "Duration"
initial: 3
min: 1
max: 15
step: 1
icon: mdi:camera-timer
zone_1_repeat:
name: "Repeat Every - HH"
initial: 24
min: 0
max: 48
step: 6
icon: mdi:repeat
# #
# #
group:
zone_1_status:
icon: mdi:clock
entities:
- sensor.zone_1_last_run
- sensor.zone_1_next_run
# - sensor.zone_1_duration
# - sensor.zone_1_repeat
zone_1_set:
icon: mdi:settings
entities:
- sensor.zone_1_base_time
- input_number.zone_1_timer_hours
- input_number.zone_1_timer_minutes
- input_number.zone_1_duration
- input_number.zone_1_repeat
#- input_boolean.zone_1_reset_zone
# Zone switch, trigger, and run script
sensor mqtt:
- platform: mqtt
name: "Zone 1 Timer Next"
state_topic: "run/irrigation/zone1"
input_boolean:
zone_1_reset_zone:
name: Reset Next Run Timer
initial: off
icon: mdi:lock-reset
switch mqtt:
- platform: mqtt
name: "Zone 1"
state_topic: "status/irrigation/zone_1"
command_topic: "set/irrigation/zone_1"
payload_on: "ON"
payload_off: "OFF"
qos: 0
retain: true
switch:
- platform: mqtt
name: "Zone 1 Timer"
state_topic: "status/irrigation/timer/zone_1"
command_topic: "set/irrigation/timer/zone_1"
state_on: "enabled"
state_off: "disabled"
payload_on: "enable"
payload_off: "disable"
icon: mdi:timer
automation zone_1_trigger:
alias: "Trigger Zone 1 Run"
trigger:
- platform: time_pattern
minutes: '/1'
condition:
condition: and
conditions:
- condition: template
value_template: '{{(as_timestamp(now()) | timestamp_custom("%A, %d %h %H:%M")) == states.sensor.zone_1_next_run.state}}'
# - condition: state
# entity_id: sensor.rain_sensor
# state: 'dry'
action:
- service: script.turn_on
entity_id: script.zone_1_run
script:
zone_1_run:
sequence:
- alias: "Switch on Zone 1"
service: switch.turn_on
entity_id: switch.zone_1
- delay: '00:{{ states.input_number.zone_1_duration.state | int }}:00'
- alias: "Switch off Zone 1"
service: switch.turn_off
entity_id: switch.zone_1
- alias: "Update Next Run Time"
service: mqtt.publish
data:
topic: "run/irrigation/zone1"
retain: 1
payload_template: '{{ (as_timestamp(states.switch.zone_1.last_changed) + states.sensor.zone_1_time_delta.state | int) | timestamp_custom("%A, %d %h %H:%M") }}'
# automation zone_1_2:
# alias: "Zone 1 Active Notification"
# hide_entity: False
# trigger:
# - platform: state
# entity_id: switch.zone_1
# from: 'off'
# to: 'on'
# action:
# - service: notify.pushbullet
# data:
# title: "Irrigation Zone 1"
# message: "Watering has started"
#
# automation zone_1_3:
# alias: "Zone 1 Completed Notification"
# hide_entity: False
# trigger:
# - platform: state
# entity_id: switch.zone_1
# from: 'on'
# to: 'off'
# action:
# - service: notify.pushbullet
# data:
# title: "Irrigation Zone 1"
# message: "Watering has completed"
#
# automation zone_1_4:
# alias: "Zone 1 Timer Reset"
# trigger:
# - platform: state
# entity_id: input_boolean.reset_zone_1
# from: 'off'
# to: 'on'
# action:
# - service: mqtt.publish
# data:
# topic: "cmnd/zone_1_control/TIMER"
# retain: 1
# payload_template: >-
# {%if now().strftime("%H:%M") > states.sensor.zone_1_timer.state %}
# {{(as_timestamp(now() )+24*3600 ) | timestamp_custom("%A, %d %h ")}}{{states.sensor.zone_1_timer.state}}
# {%else%}
# {{(as_timestamp(now() ) ) | timestamp_custom("%A, %d %h ")}}{{states.sensor.zone_1_timer.state}}
# {%endif%}
# - delay:
# seconds: 1
# - service: input_boolean.turn_off
# data:
# entity_id: input_boolean.reset_zone_1
#