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