Changing a ‘select’ function based on heating being on

Hi all,
I’m wanting to stop my home battery from discharging while my air source heat pump is in operation during the day (it drains it so quickly that it becomes almost worthless). I don’t want to turn the whole system off as this stops any solar that is being produced from being used as well as the battery.

What I am hoping to achieve is to change:
Select. solax_discharger_end_time_1
From whatever time it is set to to the nearest 15 minute window (it can only be changed to :00 :15, :30 or :45 past the hour)

I’d also want to change
Select. solax_discharger_start_time_2
The same conditions apply, but I’d want to set that to a time a few hours in advance.

I’d also want the battery to kick back in when the heating reaches the target temperature; so essentially reverse the above process.

How would I go about this? I’m assuming I’ll need scripting and I don’t know where to start on that one.

Your description is a little sparse, so this might not be exactly what you need…

trigger:
  - platform: state
    entity: climate.EXAMPLE
    attribute: hvac_mode
    to:
      - cooling
      - heating
    id: active
  - platform: state
    entity: climate.EXAMPLE
    attribute: hvac_mode
    to:
      - idle
      - off
    from:
      - cooling
      - heating
condition: []
action:
  - variables:
      end_select: 'select.solax_discharger_end_time_1'
      start_select: 'select.solax_discharger_start_time_2'
  - service: select.select_option
    target:
      entity_id: "{{end_select if trigger.id == 'active' else start_select}}"
    data:
      option: |
        {% set next_quarter = now().minute % 15 %}
        {{ (now() + timedelta(minutes = 15 - next_quarter)).strftime('%H:%M') }}
  - service: select.select_option
    target:
      entity_id: "{{start_select if trigger.id == 'active' else end_select}}"
    data:
      option: |
        {{ (now() + timedelta(hours = 3)).strftime('%H:00') }}

Thanks for that, I’ll see how I get on.