Help with template: reading attribute to find input_number

Hello there

I would like to read the message of a calendar and convert it into an input_number. The calendar entries and input_numbers are already defined and are following the same nomenclature. For example, the message in the calendar “Low Demand Season - Standard” should be converted to “input_number.low_demand_season_standard”. So it should be possible to do this:

  - variables:
      current_event: "{{ state_attr('calendar.eskom_ruraflex', 'message') }}"
      formatted_event: "{{ current_event | replace(' ', '_') | replace(' - ', '_') | lower }}"
      input_number_entity: "input_number.{{ formatted_event }}"

But all I am getting in the editor is:

action:
  - variables:
      current_event: "Low Demand Season - Standard"
      formatted_event: ""
      input_number_entity: "input_number."

with the error ‘formatted_event’ undefined. I am puzzled, since the event is actually defined.

The big picture: I have a tariff schedule in the calendar, the name of the current entry should be taken to copy the tariff which is given in the input_number to an input_number.current_tariff. This is used to calculate the power bill.

Why are you creating calendars and input numbers when I showed you how to do this easily with one template sensor?

I am sorry for that. I am still new to Jinja and most of its wording.
Well, two reasons: I am already using the calendar to control a water pump which is only pumping during cheap tariffs. It works and I thought I would like to have a central schedule. It can change once a year and for me it convenient to change it in the GUI of the calendar.
Secondly, it is still not clear to me how the price/kWh is finding its way into sensor.current_tariff. In your code I do not see a possibility to let HA know how much a kW in which tariff costs. So I thought to get the current tariff from the calendar, finding its right input_number with the price and putting it in sensor.current_tariff to set with select.select_option.
I should have thought about it before I give my feedback here.