You must setup some time source to have real time in ESP device.
Then create binary_sensor which evaluates as true when time is between close & open time.
In sensor automations call required cover actions to close/open it.
3º - Created a Binary Sensor to control the COVER object and also checl the operation mode object that the user can select.
binary_sensor:
- platform: template
name: "Cover Control Time"
id: cover_control_time
lambda: |-
// Check if the operation mode is 'time_based'
if (id(operation_mode).state != "time_based") {
return false; // Do not trigger the cover if mode is not 'time_based'
}
auto now = id(homeassistant_time).now();
int current_time = now.hour * 60 + now.minute; // Current time in minutes since midnight
// Get the open time from datetime component
auto open_time_obj = id(my_open_time).state_as_esptime();
int open_time = (open_time_obj.hour * 60) + open_time_obj.minute;
// Get the close time from datetime component
auto close_time_obj = id(my_close_time).state_as_esptime();
int close_time = (close_time_obj.hour * 60) + close_time_obj.minute;
// Return true if the current time is between open_time and close_time
return (current_time >= open_time && current_time < close_time);
#----------------------------------------------------------------------------------
# Automation to control the cover based on the time
#----------------------------------------------------------------------------------
on_press:
then:
- cover.open: general_cover
on_release:
then:
- if:
condition:
lambda: 'return id(operation_mode).state == "time_based";'
then:
- cover.close: general_cover