Fade light with long button preset

Hello,

I’m trying to fade a light when I press and hold a button but I can’t get it to work.

This is my configuration:

Light:

light:
  - platform: mqtt
    schema: json
    name: mqtt_json_light_1
    state_topic: "home/ESP_LED_ESPEJO"
    command_topic: "home/ESP_LED_ESPEJO/set"
    brightness: true
    effect: true
    effect_list: [flash]
    optimistic: false
    qos: 0

Sensor:

- platform: mqtt
    state_topic: "wemos/pulsacionlarga"
    name: "touch_espejo_larga"
    payload_on: "LONG_ON"
    payload_off: "LONG_OFF"

Script:

fade_the_light:
  Alias: Kitchen Brightness Decrease Button
  sequence:
  - service: light.turn_on
    entity_id: light.mqtt_json_light_1
    data_template:
      transition: '1'
      brightness_pct:>
       {% set n = states.light.mqtt_json_light_1.attributes.brightness + 5%}
       {% if n> 100%}
         100
       {% else%}
         {{n}}
       {% endif%}

Automation:

- id: '1623086575946'
  alias: Fade luz espejo
  description: ''
  trigger:
  - platform: state
    entity_id: binary_sensor.touch_espejo_larga
    from: 'off'
    to: 'on'
  condition: []
  action:
  - service: script.turn_on
    target:
      entity_id: script.fade_the_light
  mode: single

If I try the data template in the templates section, it tells me the following:

UndefinedError: ‘mappingproxy object’ has no attribute 'brightness’

greetings

I think the problem is that the brightness attribute only seems to be available when the light is on, according to this:

{{states.light.mqtt_json_light_1.attributes}}

With light off it returns:

{'effect_list': ['flash'], 'supported_color_modes': ['brightness'], 'friendly_name': 'mqtt_json_light_1', 'supported_features': 45}

and with light on it returns:

{'effect_list': ['flash'], 'supported_color_modes': ['brightness'], 'color_mode': 'brightness', 'brightness': 5, 'effect': 'null', 'friendly_name': 'mqtt_json_light_1' , 'supported_features': 45}

Therefore I suppose that by not finding the attribute when it is off, it cannot execute the script associated with the automation.

Any way to solve it?

Greetings