Hi all,
i’m analizing a tuya “value”: “DAABAQweAgENAAQBDR4DAQ4ABAEOHgYB”
it is a base64 number.
i used the link Base64 to binary: Encode and decode bytes online - cryptii to convert the number in integer number grouping the number in bytes (see image)
best!
another question
for me each number rappresent an information for my pet feeder device.
for exsample [12, 0, 1, 1,…] 12:00 time, 1 integer meal portion, 1 boolean active/ no active.
if i use
{%- set decoded_bytes = ("DAABAQweAgENAAQBDR4DAQ4ABAEOHgYB" | base64_decode).encode() | map('int') | list -%}
Decoded bytes are {{ decoded_bytes }}
Time is {{ "{0:02d}:{1:02d}".format(*decoded_bytes) }}
Datetime is {{ now().replace(hour=decoded_bytes[0], minute=decoded_bytes[1], second=0, microsecond=0) }}
Meal portion is {{ decoded_bytes[2] }}
Is feeder active? {{ decoded_bytes[3] | bool }}
It looks like the list might have multiple groups? If this is a fixed size, you can process all the groups as well, for example:
slice {{ decoded_bytes | slice(6) | list}}
{% set groups = decoded_bytes | slice(decoded_bytes|length // 4) -%}
{% for group in groups %}
Group {{ loop.index }}
Time is {{ "{0:02d}:{1:02d}".format(*group) }}
Datetime is {{ now().replace(hour=group[0], minute=group[1], second=0, microsecond=0) }}
Meal portion is {{ group[2] }}
Is feeder active? {{ group[3] | bool }}
{% endfor %}