How pass and read the `trigger.to_state` inside a script

Hi I need to pass to script trigger.to_state and trigger.from_state for be able to read it in the script. Currently, I am trying many variations, but none of them work. last of my code is:

alias: Temperature Changed
description: ""
triggers:
  - trigger: state
    entity_id:
      - climate.c686b3d1
      - climate.c67df6bd
      - climate.c686b579
      - climate.c686b3b8
    attribute: current_temperature
conditions: []
actions:
  - action: script.temperature_notification_2
    metadata: {}
    data:
      to_ac_state: "{{ trigger.to_state }} "
      from_ac_state: "{{ trigger.from_state }}"
      # I have default value for the levels and required: false,
      # but I can't run the script without the params, 
      # if someone know how resolve and this issue please help.
      high_temp_level: 26
      low_temp_level: 22
mode: parallel

and

alias: Gree Climat Temperature Notification
description: >-
  Temperature Notification for Gree Climate devices. The entities can be passed
  from automation as `trigger.to_state.entity_id` or
  `trigger.from_state.entity_id`
sequence:
  - variables:
      # HERE: I can't read the state as object, what is wrong?
      test_1: "{{ to_ac_state.state }}"
      test_2: "{{ to_ac_state.friendly_name }}"
      name: "{{ state_attr(to_ac_state,'friendly_name') }}"
      temp: "{{ state_attr(to_ac_state,'current_temperature') }}"
      from_temp: "{{ state_attr(from_ac_state,'current_temperature') }}"
  - if:
      - condition: template
        value_template: >-
          {% if temp > high_temp_level %} true 
          {% elif temp < low_temp_level %} true 
          {% elif from_temp > high_temp_level %} true 
          {% elif from_temp < low_temp_level %} true 
          {% else %} false 
          {% endif %}
    then:
      - variables:
          temp_level: >-
            {% if temp > high_temp_level %} High 
            {% elif temp < low_temp_level%} Low 
            {% else %}
            {% endif %}
          change_direction: >-
            {% if from_temp < temp %} increased to 
            {% elif from_temp > temp %} decreased to 
            {% else %} is 
            {% endif %}
      - data:
          title: šŸŒ”ļø {{ temp_level }} Temp.
          message: >-
            {{ name }}: Temperature {{ change_direction }} {{ temp }}Ā°C {{ from_temp }}
        action: notify.evgen
fields:
  to_ac_state:
    selector:
      object: {}
    name: To AC State
    description: Climat entity
    required: true
  from_ac_state:
    selector:
      object: {}
    name: From AC State
    description: Climat entity
    required: true
  high_temp_level:
    selector:
      number:
        min: 1
        max: 100
    name: High temp level
    description: abowe this value temp is high
    default: 26
  low_temp_level:
    selector:
      number:
        min: 1
        max: 100
    name: Low temp level
    description: below this value temp is low
    default: 22
icon: mdi:air-conditioner

In trace the script ,I can see, I receive the data as

to_ac_state: >-
  {'hvac_modes': [<HVACMode.AUTO: 'auto'>, <HVACMode.COOL: 'cool'>,
  <HVACMode.DRY: 'dry'>, <HVACMode.FAN_ONLY: 'fan_only'>, <HVACMode.HEAT:
  'heat'>, <HVACMode.OFF: 'off'>], 'min_temp': 8, 'max_temp': 30,
  'target_temp_step': 1, 'fan_modes': ['auto', 'low', 'medium low', 'medium',
  'medium high', 'high'], 'preset_modes': ['eco', 'away', 'boost', 'none',
  'sleep'], 'swing_modes': ['off', 'vertical', 'horizontal', 'both'],
  'current_temperature': 28, 'temperature': 26, 'fan_mode': 'low',
  'preset_mode': 'none', 'swing_mode': 'off', 'friendly_name': 'Cabinet AC',
  'supported_features':
  <ClimateEntityFeature.TARGET_TEMPERATURE|FAN_MODE|PRESET_MODE|SWING_MODE|TURN_OFF|TURN_ON:
  441>}

and results for first variables is:

test_1: ''
test_2: ''
name: null
temp: null
from_temp: null

Objects are converted into JSON strings before they are passed as variables. You can use the filter from_json to de-serialize a JSON string back into an object. A good number of those attributes are kind of weird objects that look like static lists. It is often best to only pass the needed values from your automation instead of passing the whole stringified object.

No, in this case in data I will receive just

to_ac_state: 'off'
from_ac_state: 'off'

but I need list of states for state from and to

please can you give me example how I can code to json this object in automation, and then encode it in script? now all my trying to decode has error, for example

Error: JSONDecodeError: unexpected character: line 1 column 1 (char 0)

or code

Error: Error rendering data template: TypeError: Type is not JSON serializable: State
//For
from_ac: '{{ trigger.from_state | to_json }}'

As I mentioned and @Sir_Goodenough stated, just pass the necessary elements, not the entire state object. As you have seen, state objects can contain data that is not JSON serializableā€¦

alias: Temperature Changed
description: ""
triggers:
  - trigger: state
    entity_id:
      - climate.c686b3d1
      - climate.c67df6bd
      - climate.c686b579
      - climate.c686b3b8
    attribute: current_temperature
conditions: []
actions:
  - action: script.temperature_notification_2
    metadata: {}
    data:
      name: "{{ trigger.name }}"
      temp: "{{ trigger.to_state.attributes.current_temperature }}"
      from_temp: "{{ trigger.from_state.attributes.current_temperature }}"
      high_temp_level: 26
      low_temp_level: 22
mode: parallel

I decided I misread, so deleted mine. I had never considered pulling trigger stuff out as an object to pass and when I saw that was the goal on a re-read, I killed my comment.

Thank you @Didgeridrew. Yes I finally make the same

  name: "{{ trigger.to_state.attributes.friendly_name }}"
  current_temp: "{{ trigger.to_state.attributes.current_temperature }}"
  previous_temp: "{{ trigger.from_state.attributes.current_temperature }}"
  high_temp_level: 26
  low_temp_level: 22

Iā€™ve also figured out how to send all attributes.

from_ac_attributes: "{{ trigger.from_state.attributes | to_json }}"

However, in this case, sending only the necessary items is a better approach.
so I choose first variant. Thanks.

but I donā€™t understood why I canā€™t serializable the data to json

I just receive the error