Help with automation to control climate

I want to create a homeassistant script which can be activate by pressing a virtual switch “A”

The HA checks if the “temp_hum_living_room_temperature” sensor is reporting temperature of > 19.5 then it switches off TRV “climate.trv_living_room_front_thermostat” and “climate.trv_living_room_back_thermostat”. Automation then turns up the thermostat “climate.boiler_verstile” to 2 degree C above the current value. If the sensor “temp_hum_living_room_temperature” is reporting temperature of < 19.5 then it increases the temperature of TRV “climate.trv_living_room_front_thermostat” and “climate.trv_living_room_back_thermostat” to 2 degree above their current value and turns on HVAC mode on these two TRVs to Heat and when the “temp_hum_living_room_temperature” sensor is reporting temperature of > 19.5 then it switches off TRV “climate.trv_living_room_front_thermostat” and “climate.trv_living_room_back_thermostat”. The automation ends when the sensor “sensor.atc4_store_temperature” reports temperature of >19C"

Being a noob I asked chatGPT the above. It came up with the following code

# configuration.yaml

# Define the virtual switch "A"
input_boolean:
  virtual_switch_a:
    name: Virtual Switch A
    icon: mdi:light-switch

# Define the automation
automation:
  - id: temperature_automation
    alias: Temperature Control Automation
    trigger:
      platform: state
      entity_id: input_boolean.virtual_switch_a
      to: "on"
    action:
      service: script.temperature_control

# Define the script
script:
  temperature_control:
    sequence:
      - condition: numeric_state
        entity_id: sensor.temp_hum_living_room_temperature
        above: 19.5
      - service: climate.set_hvac_mode
        target:
          entity_id: climate.trv_living_room_front_thermostat
        data:
          hvac_mode: "off"
      - service: climate.set_hvac_mode
        target:
          entity_id: climate.trv_living_room_back_thermostat
        data:
          hvac_mode: "off"
      - service: climate.set_temperature
        target:
          entity_id: climate.boiler_verstile
        data:
          temperature: "{{ state_attr('climate.boiler_verstile', 'temperature') + 2 }}"
      - wait_template: "{{ states('sensor.temp_hum_living_room_temperature') | float > 19.5 }}"

      - condition: numeric_state
        entity_id: sensor.temp_hum_living_room_temperature
        below: 19.5
      - service: climate.set_temperature
        target:
          entity_id: climate.trv_living_room_front_thermostat
        data:
          temperature: "{{ state_attr('climate.trv_living_room_front_thermostat', 'temperature') + 2 }}"
      - service: climate.set_temperature
        target:
          entity_id: climate.trv_living_room_back_thermostat
        data:
          temperature: "{{ state_attr('climate.trv_living_room_back_thermostat', 'temperature') + 2 }}"
      - service: climate.set_hvac_mode
        target:
          entity_id: climate.trv_living_room_front_thermostat
        data:
          hvac_mode: "heat"
      - service: climate.set_hvac_mode
        target:
          entity_id: climate.trv_living_room_back_thermostat
        data:
          hvac_mode: "heat"
      - wait_template: "{{ states('sensor.temp_hum_living_room_temperature') | float > 19.5 }}"

      - service: climate.set_hvac_mode
        target:
          entity_id: climate.trv_living_room_front_thermostat
        data:
          hvac_mode: "off"
      - service: climate.set_hvac_mode
        target:
          entity_id: climate.trv_living_room_back_thermostat
        data:
          hvac_mode: "off"

However when i save this in HA i get error “Message malformed: extra keys not allowed @ data[‘script’”. Any ideas and any help with this automation?

Don’t use ChatGPT if you don’t know Home Assistant well. It was trained on out of date data and just makes up gibberish.

Try reading the official documentation instead.

Also just so you know, it is also against the forum rules to use AI to help others on this forum.