TheThingsNetwork payload decode base64

I’ve got an LoRa application running on TTN. I already get the value from TTN by MQTT in openHAB displayed, but only the encoded base64 payload. How can i decode the payload so i can display the decoded payload in an item?

You could run a rule using the exec binding. Input would be the payload. Within the shell script use “base64 -d” to decode the payload. Using the REST API from within the same shell script you can set the clear text item value.
Decoding the payload using javascript you may use the function

bota()

@Wolfgang_S
Thank you for your help! I have to say I’m completely new to this topic. I have already configured the input and output item. But how do I use “base64 -d”?

A basic rule using base64 decoding could look like:

rule "echo base64" 
when Time cron "0/60 * * * * ?" //run every 60 seconds
then
  var response = executeCommandLine(Duration.ofSeconds(5), "/etc/openhab/scripts/base64decode.sh", "YmxhZmFzZWw=" );
  logWarn("Rules", "base64 response: " + response)
end

This needs to be put into /etc/openhab/rules.

Besides that you need to have a shell script e.g. in /etc/openhab/scripts that is called /etc/openhab/scripts/base64decode.sh. It needs to be executable and readable ( chmod ugo+rx /etc/openhab/scripts/base64decode.sh )

This is just a proof of concept and not exact what you would like to do.
Every 60 seconds the same base64 encoded string is decoded.
You can have a look into /var/log/openhab/openhab.log and should find the decoded string there.

The above rule needs to adapted that instead of executing the script every 60 seconds it is triggered by a change of your paylog ( item changed ). Instead of the fixed encoded string you need to pass your payload to the script.

Instead of the proposed exec binding I used executeCommandLine here.