Help calculating costs multiple 1.5

For a long time I used a template that calculated extra print costs (1 euro) for every 10 pages ( = one block) I printed to much, now my printer cost for extra pages went from 1 euro to 1.5 euro.

The template uses an input number that I set in my lovelace.

  # The cost of each overprint block, in £
  # SET THIS ACCORDING TO YOUR PLAN
  hp_printer_pages_overprint_block_cost:
    name: "HP Printer - Over Print Block Cost"
    min: 0
    max: 50
    step: 0.01
    unit_of_measurement: "EUR"
    icon: "mdi:currency-eur"
    mode: box

I have changes the input from 1 to 1.5, however the calculation keep setting +1 for every 10 pages (1 block) for overprinting instead of + 1.5.

can someone see whats wrong in this template?

      # The cost so far of the pages that have been printed over the standard Available plus Rollover Available
      # Calculated when each page is printed, and at the start of each new Instant Ink period
      # CHANGE THE CURRENCY CODE AS APPROPRIATE
      - name: "HP Printer - Pages Overprint Cost"
        unique_id: "template_hp_printer_pages_overprint_cost"
        unit_of_measurement: "EUR"
        device_class: monetary
        state_class: total
        icon: "mdi:currency-eur"
        state: >
          {% if states('sensor.hp_printer_pages_total_printed') or states('input_datetime.hp_printer_this_period_start_date') %}
            {% if states('sensor.hp_printer_pages_overprint') | int == 0 %}
              0
            {% elif states('sensor.hp_printer_pages_overprint') | int > 0 and ( (states('sensor.hp_printer_pages_overprint') | int - 1) % states('input_number.hp_printer_pages_overprint_block_size') | int == 0 ) %}
              {{ (1 + ((states('sensor.hp_printer_pages_overprint') | int - 1) / states('input_number.hp_printer_pages_overprint_block_size') | int)) | multiply( states('input_number.hp_printer_pages_overprint_block_cost') | int) | int  }}
            {% else %}
              {{ (1 + ((states('sensor.hp_printer_pages_overprint') | int - 1) / states('input_number.hp_printer_pages_overprint_block_size') | int)) | multiply( states('input_number.hp_printer_pages_overprint_block_cost') | int) | int  }}
            {% endif %}    
          {% endif %}
        availability: >
          {{ is_number(states('sensor.hp_printer_pages_total_printed'))
            and has_value('input_datetime.hp_printer_this_period_start_date')
            and is_number(states('sensor.hp_printer_pages_overprint'))
            and is_number(states('input_number.hp_printer_pages_overprint_block_size'))
            and is_number(states('input_number.hp_printer_pages_overprint_block_cost')) }}

Anyone?

I tried Float but this also does not work

Using int definitely won’t work: that’ll turn 1.5 into 1.

Your template is overly long and complicated. Please explain in simple words what each of the entities represents and what the template needs to return.

I think it reduces to something like this, as your {% elif %} and {% else %} templates are identical. You probably don’t need the two branches at all but I cba to figure it out.

        state: >
          {% set printed = states('sensor.hp_printer_pages_total_printed') %}
          {% set start_date = states('input_datetime.hp_printer_this_period_start_date') %}
          {% set overprint = states('sensor.hp_printer_pages_overprint')|int(0) %}
          {% set op_block_size = states('input_number.hp_printer_pages_overprint_block_size')|int(0) %}
          {% set op_block_cost = states('input_number.hp_printer_pages_overprint_block_cost')|float(0) %}

          {% if printed or start_date %}
            {% if overprint == 0 %}
              0
            {% else %}
              (1 + ((overprint - 1) / op_block_size)|int * op_block_cost %}
            {% endif %}
          {% endif %}