Climate: Target temperature changing erratically

I have 11 Avatto TRVs that I have connected through Z2M.

I am controlling the target temperature of each of these TRVs through automations in 3 time periods during a 24 hour period, and another for when we are away. The idea is to set a baseline temperature for each TRV, and have a temperature offset for each period of the day:

  • Home: +0oC
  • Night: -3oC
  • Comfort: +3oC
  • Away: -10oC

The Comfort periods are morning and evenings. Home and Night as self explanatory. From the diagram below you can see the history of the offset sensor.

Below is the Template sensor that sets the heating period.

    thermostat_mode:
      unique_id: "thermostat_mode"
      friendly_name: "Thermostat Mode"
      value_template: >-
        {% set day_trigger = states('input_number.day_trigger') | float(0) %}
        {% set day_time_trigger = states('input_datetime.heating_trigger_morning') %}
        {% set night_trigger = states('input_number.night_trigger') | float(0) %}
        {% set night_time_trigger = states('input_datetime.heating_trigger_night') %}
        {% set morning_trigger = states('input_number.morning_trigger') | float(0) %}
        {% set elevation = states.sun.sun.attributes.elevation | float(0) %}
        {% if states('input_boolean.vacation_mode') == 'On' %}
          {{ 'away' }}
        {% elif elevation > day_trigger %}
          {{ 'home' }}
        {% elif elevation < night_trigger and states('sensor.time') > night_time_trigger %}
          {{ 'sleep' }}
        {% elif elevation < morning_trigger and states('sensor.time') < day_time_trigger %}
          {{ 'sleep' }}
        {% else %}
          {{ 'comfort' }}
        {% endif %}

Below is the Template sensor that sets the heating offset

    thermostat_offset:
      unique_id: "thermostat_offset"
      friendly_name: "Thermostat Offset"
      unit_of_measurement: '°C'
      value_template: >-
        {% if states('sensor.thermostat_mode') == 'away' %}
          {{ states('input_number.away_offset') | float(0) }}
        {% elif states('sensor.thermostat_mode') == 'home' %}
          {{ states('input_number.day_offset') | float(0) }}
        {% elif states('sensor.thermostat_mode') == 'sleep' %}
          {{ states('input_number.night_offset') | float(0) }}
        {% else %}
          {{ states('input_number.twilight_offset') | float(0) }}
        {% endif %}

These sensors operate as I expect them to, as is shown in the graph above.

The Automation below sets the target temperature for the basement TRVs. All TRVs are controlled using the same approach.

- id: '1686539561087'
  alias: Set Basement Heating
  description: ''
  trigger:
  - platform: state
    entity_id:
    - input_boolean.heating_on_off
    - input_boolean.manage_radiator_heating
    - input_number.basement_baseline
    - sensor.thermostat_offset
  condition: []
  action:
  - if:
    - condition: state
      entity_id: input_boolean.heating_on_off
      state: 'on'
    then:
    - if:
      - condition: state
        entity_id: input_boolean.manage_radiator_heating
        state: 'on'
      then:
      - service: climate.set_temperature
        data:
          temperature: '{{ states(''input_number.basement_baseline'') | float(0) +
            states(''sensor.thermostat_offset'') | float(0) }}'
          hvac_mode: auto
        target:
          entity_id: climate.trv_basement
      else:
      - service: climate.set_temperature
        data:
          temperature: '{{ states(''input_number.basement_baseline'') | float(0) }}'
          hvac_mode: auto
        target:
          entity_id: climate.trv_basement
    else:
    - service: climate.set_temperature
      data:
        temperature: '{{ state_attr(''climate.trv_basement'',''min_temp'') | float(0)
          }}'
        hvac_mode: 'off'
      target:
        entity_id: climate.trv_basement
  mode: single

Below is are two graphs that show the thermostat period, thermostat offset, and the target temperature for the basement and guest bedroom TRVs.

What is happening to the TRV target temperatures? They should be following the baseline and offset.

I used to control the TRV using a much more complex automation that took into consideration the outside temperature and the cloud cover. When I select “Choose entity” on the History graph I can see the name of the old automation script, but it is greyed out. But when I go to the Automations tab and search for the automation it doesn’t show up.

How can I determine what is changing the TRV target temperatures?