Problem Using Function and Passing arguments in Floorplan

Hello everyone.
I want to create a function that evaluates the position of a roller shutter (cover entity in HA) as input and returns a rounded value as output (for example given 6 as position return 0, instead given 40 return 50). I have no difficulty writing the function in JS but I can’t use it. Or rather I can’t pass it the value of the current_position status attribute to make it work from the function.
Can anyone help me?

Things works great if I don’t use the function and put a constant value of 0 or 50 or 100.
Instead with function I mistake something that I can’t figure out.

This is what I write:

    functions: |
      >
      return {
      position_calculation: (number) {
          if (number< 5) {
              return 0;
          } else if (number >= 5 && number < 17.5) {
              return 10;
          } else if (number >= 17.5 && number < 37.5) {
              return 25;
          } else if (number >= 37.5 && number < 62.5) {
              return 50;
          } else if (number >= 62.5 && number < 87.5) {
              return 75;
          } else if (number >= 87.5 && number <= 100) {
              return 100;
          } else {
              console.error("number has to be between 0 e 100.");
              return null;
          }
      }
                - entities:
                    - entity: cover.tapparella_bagno_finestrato
                      element: cover.tapparella_bagno_finestrato
                  tap_action: false
                  state_action:
                    action: call-service
                    service: floorplan.style_set
                    service_data:
                      element: |
                        >
                        return (entity.entity_id.replace ('cover.', 'cover_overlay.')).concat("_", functions.position_calculation(entity.state.attributes.current_position));
                      style: |
                        >
                        return "display: block;";

Thank You in advance.
Regards

Im away from my PC but at first glance it might be your use of entity.entity_id

If this is the only place you are using the function then just put the JavaScript in the service_data and delete the function

And it should be entity.attributes not entity.state.atttributes

Solved! Thank You very much for the tips!

Regards