Updated a3pool to use the new datetime template picker in HA

This commit is contained in:
Nicolas Bachschwell 2024-05-13 10:44:42 +02:00
parent 3d7e80154a
commit 01548813dc
Signed by: NBSgamesAT
GPG Key ID: 2D73288FF7AEED2F

View File

@ -27,47 +27,21 @@ binary_sensor:
pullup: true pullup: true
id: pump_state id: pump_state
number: datetime:
- platform: template - platform: template
name: "Start Hour" name: Pool Pump Start Time
id: start_h id: pool_start
type: time
optimistic: true optimistic: true
min_value: 0
max_value: 23
restore_value: true restore_value: true
initial_value: 8 initial_value: "08:00:00"
mode: box
step: 1
- platform: template - platform: template
name: "Start Minute" name: Pool Pump End Time
id: start_m id: pool_end
type: time
optimistic: true optimistic: true
min_value: 0
max_value: 59
initial_value: 0
restore_value: true restore_value: true
mode: box initial_value: "20:00:00"
step: 1
- platform: template
name: "End Hour"
id: end_h
optimistic: true
min_value: 0
max_value: 23
restore_value: true
initial_value: 20
mode: box
step: 1
- platform: template
name: "End Minute"
id: end_m
optimistic: true
min_value: 0
max_value: 59
restore_value: true
initial_value: 0
mode: box
step: 1
button: button:
- platform: template - platform: template
@ -75,25 +49,25 @@ button:
on_press: on_press:
then: then:
- lambda: |- - lambda: |-
int startMins = (int) (id(start_h).state * 60) + id(start_m).state; int startSec = (int) (id(pool_start).hour * 3600) + (id(pool_start).minute * 60) + id(pool_start).second;
int endMins = (int) (id(end_h).state * 60) + id(end_m).state; int endSec = (int) (id(pool_end).hour * 3600) + (id(pool_end).minute * 60) + id(pool_end).second;
int nowMins = (id(a3poolTime).now().hour * 60) + id(a3poolTime).now().minute; int nowSec = (id(a3poolTime).now().hour * 3600) + (id(a3poolTime).now().minute * 60) + id(a3poolTime).now().second;
if(!id(control).state){ if(!id(control).state){
// Make sure wierd error or whatever // Make sure wierd error or whatever
return; return;
} }
if(startMins < endMins){ if(startSec < endSec){
if(startMins < nowMins && nowMins < endMins){ if(startSec < nowSec && nowSec < endSec){
id(pump).turn_on(); id(pump).turn_on();
} }
else{ else{
id(pump).turn_off(); id(pump).turn_off();
} }
} }
else if(startMins > endMins){ else if(startSec > endSec){
if(endMins < nowMins && nowMins < startMins){ if(endSec < nowSec && nowSec < startSec){
id(pump).turn_off(); id(pump).turn_off();
} }
else{ else{
@ -146,20 +120,18 @@ time:
id: a3poolTime id: a3poolTime
platform: sntp platform: sntp
on_time: on_time:
- seconds: 0 - months: 4-10
months: 4-10
then: then:
- if: - if:
condition: condition:
lambda: 'return id(a3poolTime).now().hour == (int) id(start_h).state && id(a3poolTime).now().minute == (int) id(start_m).state && id(control).state;' lambda: 'return id(a3poolTime).now().hour == id(pool_start).hour && id(a3poolTime).now().minute == id(pool_start).minute && id(a3poolTime).now().second == id(pool_start).second && id(control).state;'
then: then:
- switch.turn_on: pump - switch.turn_on: pump
- seconds: 0 - months: 4-10
months: 4-10
then: then:
- if: - if:
condition: condition:
lambda: 'return id(a3poolTime).now().hour == (int) id(end_h).state && id(a3poolTime).now().minute == (int) id(end_m).state && id(control).state;' lambda: 'return id(a3poolTime).now().hour == id(pool_end).hour && id(a3poolTime).now().minute == id(pool_end).hour && id(a3poolTime).now().second == id(pool_end).second && id(control).state;'
then: then:
- switch.turn_off: pump - switch.turn_off: pump