Formatting Byte values as Base64 encoded MQTT payload

Hello and thanks for your interest in the topic.

Goal:

The goal is to take the state of an slider as an INT value, convert that to HEX, combine it with another HEX value and then encode those to Base64 to send of as the payload.

Problem:

Getting the INT value works fine using: testvar: {{states(‘input_number.slider1’) | int }}
Converting that into HEX also seems to work using: (‘%0x’ % testvar)
The problem accurs in the next step when combining the different values.
The first HEX value is always the same “0x0e” and is used to tell the device that it should change the set temperature. The second HEX value changes depending on the temperature you want to set in this case its {{(‘%0x’ % testvar)}}. These now need to be combined and converted to Base64, in a way that it behaves the same as when using this converter:
Base64 encoder/decoder

0e 13 → DhM=

I have only managed to get the same results like this converter:
Second Base64 encoder/decoder

But those won’t work since it seems to interpret them differently.

Alternative:

One alternative I’ve thought about would be using a lookup table, to look up the Payload depending on the INT value, which would have about 30 entries, but that is more of a last resort.

More ideas and help would be greatly appreciated.

Current State:

So I have decided to go with the switch case aproach for now.
This Post will be updated if I ever figure out how to do the conversion.

This is the way I mapped the values of the slider to the Payload messages:

variables:
  testvar: "{{states('input_number.slider_soll_temp_bar') | int }}"
  testvar2: >-
    {% if   testvar == 5  %} DgU=  {% elif testvar == 6  %} DgY=  {% elif
    testvar == 7  %} Dgc=  {% elif testvar == 8  %} Dgg=  {% elif testvar == 9 
    %} Dgk= {% elif testvar == 10 %} Dgo=  {% elif testvar == 11 %} Dgs= {% elif
    testvar == 12 %} Dgw= {% elif testvar == 13 %} Dg0= {% elif testvar == 14 %}
    Dg4= {% elif testvar == 15 %} Dg8= {% elif testvar == 16 %} DhA= {% elif
    testvar == 17 %} DhE= {% elif testvar == 18 %} DhI= {% elif testvar == 19 %}
    DhM= {% elif testvar == 20 %} DhQ= {% elif testvar == 21 %} DhU= {% elif
    testvar == 22 %} DhY= {% elif testvar == 23 %} Dhc= {% elif testvar == 24 %}
    Dhg= {% elif testvar == 25 %} Dhk= {% elif testvar == 26 %} Dho= {% elif
    testvar == 27 %} Dhs= {% elif testvar == 28 %} Dhw= {% elif testvar == 29 %}
    Dh0= {% elif testvar == 30 %} Dh4= {% endif %}

This could most likely also be achieved with just 1 variable.
I hope someone eventually finds this useful.