Turn the thermostat on and off

I ask you for help with a “bang ang” type thermostat.
I have implemented the code in ESP01 it is working and is correctly seen by HA. Now I was trying to turn the thermostat on at 09:30 and turn it off at 18:00.
I have tried various ways trying to understand the examples written in ESPHOME but without success.
Here is the piece of code I am attempting to build.

climate:
  - platform: bang_bang
    name: "Bang Bang Climate Controller"
    sensor: temperature_room
    default_target_temperature_low: 25 °C
    default_target_temperature_high: 28 °C

    cool_action:
      - switch.turn_on: esp01_pin_2
    idle_action:
      - switch.turn_off: esp01_pin_2

time:
  - platform: homeassistant
    id: homeassistant_time
    
#time:
#  - platform: sntp
#    on_time:
#    - minutes: 30
#      hours: 9
#      then:
#        - switch.turn_on: hvac_action: cooling
"

#  - platform: sntp
#    on_time:
#    - minutes: 00
#      hours: 18
#      then:
#        - switch.turn_on: hvac_action: off

Basically I would like to be able to put in “hvac_action: cooling” or “hvac_action: off” according to the time.

Is it possible to do this?
thank you

Its not a switch, it is a climate device. Use this action Climate Component — ESPHome

I managed to turn the bang-bang on and off.
I have another question …
In HA I don’t see any entities for the following

time:
  - platform: sntp
    on_time:
    - minutes: 30
      hours: 9
      then:
      - climate.control:
          id: bang_bang_climate_controller
          mode: "COOL"

  - platform: sntp
    on_time:
    - minutes: 00
      hours: 18
      then:
      - climate.control:
          id: bang_bang_climate_controller
          mode: "OFF"

while I need to see them and be able to vary them.
Was I wrong in choosing the platform?

Maybe I didn’t make the question understandable and so I try to explain myself better.
There is the possibility with ESPHOME to show and change the times
“time” in Home assistant?

time:
  - platform: sntp
    on_time:
    - minutes: 30
      hours: 9
      then:
      - climate.control:
          id: bang_bang_climate_controller
          mode: "COOL"

  - platform: sntp
    on_time:
    - minutes: 00
      hours: 18
      then:
      - climate.control:
          id: bang_bang_climate_controller
          mode: "OFF"

I’m trying and looking at other examples but can’t find anything.
Thanks in advance and sorry for the insistence.

You would need to create input numbers in home assistant. 2 for hours and minutes for each action turn on/off, so 4 input numbers all together. Bring them into esphome by using the home assistant component.

  - platform: homeassistant
    id: minutes
    entity_id: input_number.on_minutes

Then in the bang-bang component

time:
  - platform: sntp
    on_time:
    - minutes: !lambda 'return id(minutes).state;'
      hours: 9
      then:
      - climate.control:
          id: bang_bang_climate_controller
          mode: "COOL"

I h

Thank you for the suggestion. I don’t find this mode very manageable.
I prefer to leave fixed times in ESPHOME and create two INPUT_DATATIME in H.A.
So if I lose H.A. the system works the same with a coarse adjustment.

So what you can do is use a global. Then you can set a default value.

globals:
## turn on minutes
  - id: minutes_global
    type: int
    restore_value: yes
    initial_value: '30'

then every time the input number is updated it updates the global

  - platform: homeassistant
    id: minutes
    entity_id: input_number.on_minutes
    on_value:
      - globals.set:
          id: minutes_global

In the lambada call you nee to drop state when using a global value.

time:
  - platform: sntp
    on_time:
    - minutes: !lambda 'return id(minutes_global);' ##<----
      hours: 9
      then:
      - climate.control:
          id: bang_bang_climate_controller
          mode: "COOL"

OK. but anyway I have to create 4 “globals”: 2 for the hours and two for the minutes?

Yes they need to be separate entities.

I need the automation to turn on a fan to cool the solar inverter in the summer. It is not worth changing the hours and minutes on time. I’ll try your advice on hours only. I think that’s enough to run after the temperature.
thank you

I don’t know if my solution will help. I have implemented a thermostat on Sonoff Basic and a Dallas sensor. works properly. here is the code

switch:
  - platform: template                  
    name: "Day/Night"
    icon: 'mdi:theme-light-dark'
    id: deynight_pump1 
    restore_state: true
    optimistic: true

time:
  - platform: sntp
    id: pump1_time
    timezone: "Europe/Kiev" #UTC+3 #Europe/Kiev
    servers:
      - 0.ua.pool.ntp.org
      - 1.ua.pool.ntp.org
      - 2.ua.pool.ntp.org
    on_time_sync:
      then:
        - logger.log: "Время синхронизированно"
    on_time:
      - seconds: /5
        then:
          - if:
              condition:
                - lambda: 'return id(pump1_time).now().hour > 6;'
                - switch.is_on: deynight_pump1
              then:
                - switch.turn_on: time_sync 
                - logger.log: "Выше 7"
                - climate.control:
                    id: pump1_thermostat_controller
                    mode: heat
                    target_temperature: 23°C                 

          - if:
              condition:
                - lambda: 'return id(pump1_time).now().hour > 19;'
                - switch.is_on: deynight_pump1
              then:
                - switch.turn_off: time_sync 
                - logger.log: "Выше 19"
                - climate.control:
                    id: pump1_thermostat_controller
                    mode: heat
                    target_temperature: 20°C

Switch deynight_pump1 enabled: time-based automation with temperature changes is performed Hard And while it is on, the temperature cannot be changed.!

I understand from your code that you only use the hours without the minutes and check with a trigger every 5 seconds.
If I get it right it might be useful.
Tonight I try to adapt it to my needs.
thanks for now.