You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
78 lines
1.9 KiB
78 lines
1.9 KiB
3 months ago
|
substitutions:
|
||
|
hostname: heating-upstairs
|
||
|
friendly_name: Heating Upstairs
|
||
|
relay_on_action: turn_on_action
|
||
|
relay_off_action: turn_off_action
|
||
|
|
||
|
wifi:
|
||
|
use_address: 192.168.10.17
|
||
|
|
||
|
packages:
|
||
|
device: !include devices/sonoff-basic.yaml
|
||
|
|
||
|
globals:
|
||
|
- id: total_minutes
|
||
|
type: int
|
||
|
initial_value: "0"
|
||
|
- id: minutes_passed
|
||
|
type: int
|
||
|
initial_value: "0"
|
||
|
|
||
|
# Give the user a graphical control over the timeout
|
||
|
# See: https://esphome.io/components/number/template.html
|
||
|
number:
|
||
|
- name: "${friendly_name} Timeout"
|
||
|
id: timeout_length
|
||
|
platform: template
|
||
|
# TODO: maybe it's a better UX to do this in hours and minutes and do the conversion in esphome
|
||
|
unit_of_measurement: minutes
|
||
|
# Min 5 minutes
|
||
|
min_value: 10
|
||
|
# Never want it on for more than 3 hours
|
||
|
# 3*60 = 180
|
||
|
max_value: 180
|
||
|
initial_value: 10
|
||
|
step: 10
|
||
|
optimistic: true
|
||
|
|
||
|
sensor:
|
||
|
- name: "${friendly_name} Total Time"
|
||
|
platform: template
|
||
|
lambda: !lambda 'return id(total_minutes);'
|
||
|
unit_of_measurement: 'minutes'
|
||
|
accuracy_decimals: 0
|
||
|
- name: "${friendly_name} Elapsed Time"
|
||
|
platform: template
|
||
|
lambda: !lambda 'return id(minutes_passed);'
|
||
|
unit_of_measurement: 'minutes'
|
||
|
accuracy_decimals: 0
|
||
|
|
||
|
|
||
|
script:
|
||
|
- id: turn_on_action
|
||
|
then:
|
||
|
- logger.log: "Turn On"
|
||
|
- lambda: |-
|
||
|
id(total_minutes) = id(timeout_length).state;
|
||
|
id(minutes_passed) = 0;
|
||
|
id(tick).execute();
|
||
|
- id: turn_off_action
|
||
|
then:
|
||
|
- logger.log: "Turn Off"
|
||
|
- lambda: |-
|
||
|
id(relay).turn_off();
|
||
|
id(minutes_passed) = 0;
|
||
|
id(total_minutes) = 0;
|
||
|
- id: tick
|
||
|
mode: queued
|
||
|
then:
|
||
|
- delay: 1min
|
||
|
- logger.log: "Tick"
|
||
|
- lambda: |-
|
||
|
id(minutes_passed) += 1;
|
||
|
if (id(minutes_passed) >= id(total_minutes) ) {
|
||
|
id(turn_off_action).execute();
|
||
|
} else {
|
||
|
id(tick).execute();
|
||
|
}
|