I searched in the community and googled but I can’t find a way to decode a base64 image from a MQTT payload and saving it as file.
Is it possible?
I searched in the community and googled but I can’t find a way to decode a base64 image from a MQTT payload and saving it as file.
Is it possible?
Yes, it’s possible. AFAICT it is the execution of a command using the command_line platform where the command is constructed from a template and the executed using the actual eval
command, e.g.
- platform: template
sensors:
intranet_iperf_command:
value_template: >-
{%- set s = states('input_text.intranet_iperf_host') -%}
{%- if s is none or s|lower == 'unknown' -%}
{%- set s = states('input_text.motion_mqtt_broker') -%}
{%- if s is none or s|lower == 'unknown' or s|lower == 'null' -%}
{%- set s = '127.0.0.1' -%}
{%- endif -%}
{%- endif -%}
iperf3 -i 0 -t 1 -J -c {{ s }} | jq '{"host":"{{- s -}}","date":.start.timestamp.timesecs,"send":.end.sum_sent.bits_per_second,"receive":.end.sum_received.bits_per_second}'
- platform: command_line
name: intranet_test
scan_interval: !secret intranet-scan-interval
command_timeout: 60
command: "eval {{- states('sensor.intranet_iperf_command') -}}"
json_attributes:
- date
- send
- receive
value_template: >
{%- if value_json is defined -%}True{%- else -%}False{%- endif -%}
This example is for iperf execution, but it should be adaptable to your needs so long as the BASE64 encoded image data can be transferred successfully; that I have not tried.