Automation / Scripting not working for me

Hey All,

I am having a devil of a time with scripting in Home Assistant. I dont know why but I just cannot get it functioning. I am not sure where to put the scripts nor what the format should be. So I kindly ask for some assistance.

I have toggle switches around the house that send to and MQTT topic if the button has pressed once or twice, and if it being held, so you know what the action is. So if the button is pressed once, I am truning on this Tradfri bulb from Ikea, just using their gateway. That works really well. But then I would like to have a double press on the button cycle the brightness of the Bulb, so that it comes on with brightness 1, and if I double press the brightness goes to 127 (50%), and again and the brightness goes to 255 (100%), and when double pressed for the 3rd time I would like it to jump back to 1.

The obvious way to do this is to have a script the checks the current state of the brightness of the bulb and takes action based on that. That requires conditions… I am just at loss how to do it. I have tried a number of things such as:

action:
service: light.turn_on
data_template:
entity_id: light.light.tradfri_bulb_15
brightness: >
{{state_attr(‘light.tradfri_bulb_15’,‘brightness’) |int + 127}}

Now I realize that I am missing the conditional logic to rotate back to 1 but just this gives me an error:

Invalid config for [automation]: expected a dictionary for dictionary value @ data[‘action’][0][‘data_template’]. Got None. (See /home/homeassistant/.homeassistant/configuration.yaml, line 14). Please check the docs at https://home-assistant.io/integrations/automation/

I have looked at the doc, but I am none the wiser.

Many thanks for any help on this. I am pretty sure that