Automate IR controlled fairy lights with +/- brightness

I’ve been using home assistant for a few years now but have not gotten too deep into the underbelly so am fairly new to templating etc. I have recently bought a couple of Broadlink RM4 mini’s to automate some IR controlled devices. I’ve managed to configure the Broadlink integration and learn the buttons on the IR remote for some fairy lights and can turn them on and off using a light template. However I’d really like to be able to control the brightness too but can’t work out how.

The remote provides +/- buttons which provide 10 steps, but obviously the steps are simple up/down commands that are relative to the current brightness. I figure that what I need to do is determine the difference between the current brightness and the requested brightness, work out how many steps that is and in which direction, then send the appropriate number of commands, but I can’t make it work, here’s what I’ve got so far:

light:
  - platform: template
    lights:
      fairy_lights:
        friendly_name: "Fairy Lights"
        turn_on:
          service: remote.send_command
          target:
            entity_id: remote.ir_remote_remote
          data:
            device: Fairy Lights
            command: Turn On
        turn_off:
          service: remote.send_command
          target:
            entity_id: remote.ir_remote_remote
          data:
            device: Fairy Lights
            command: Turn Off
        set_level:
          service: remote.send_command
          target:
            entity_id: remote.ir_remote_remote
          data:
            device: Fairy Lights
            command: "Brightness {{ 'Up' if (brightness - state_attr('light.fairy_lights', 'brightness')) > 0 else 'Down' }}"
            num_repeats: "{{ (((brightness - state_attr('light.fairy_lights', 'brightness'))|float / 255) * 10)|abs|round|int }}"

Which doesn’t work as the state_attr(‘light.fairy_lights’, ‘brightness’) part is returning None. I was hoping it would be the current brightness level, with ‘brightness’ being the new request. Has anyone successfully tried something similar, or have any ideas?

Thanks,
Jonathan

You need a sensor that shows the current brightness of the light and then udr this in the level_template as describe here.

My problem is I don’t have a sensor to determine the brightness. When turning on I call the commands to set it to maximum so I know where it is, and from there I thought home assistant could keep track of the changes. Obviously controlling it outside of home assistant would mess it up, but I intend not to use the remote again. I have tried adding in level_threshold with a value of 255, but it hasn’t helped.