Energy calculation based on formula

I am trying to calculate energy consumption for my Philips hue (mathematical calculation based on brightness)
I have formula ready but how can I add this as a state or extra sensor to each bulb?

Say Bulb 1 is on and this formula should compute energy usage

{{ 8.3* state_attr(light.entity_id, 'brightness')/255 | round(2) }}

You need to define a Template Sensor for each light entity.

An alternative is to use a custom integration that does most of the work for you: