From 40b74dff0a1c5661a9a0bd6f353132b41b2ffaaf Mon Sep 17 00:00:00 2001 From: Petro31 <35082313+Petro31@users.noreply.github.com> Date: Mon, 26 May 2025 04:21:47 -0700 Subject: [PATCH] Add fromhex filter (#39096) Co-authored-by: Franck Nijhof --- source/_docs/configuration/templating.markdown | 3 +++ 1 file changed, 3 insertions(+) diff --git a/source/_docs/configuration/templating.markdown b/source/_docs/configuration/templating.markdown index 323786ae9ae..065b5dea224 100644 --- a/source/_docs/configuration/templating.markdown +++ b/source/_docs/configuration/templating.markdown @@ -1174,6 +1174,7 @@ Some examples: - Filter `urlencode` will convert an object to a percent-encoded ASCII text string (e.g., for HTTP requests using `application/x-www-form-urlencoded`). - Filter `slugify(separator="_")` will convert a given string into a "slug". - Filter `ordinal` will convert an integer into a number defining a position in a series (e.g., `1st`, `2nd`, `3rd`, `4th`, etc). +- Filter `value | from_hex` Decodes a hex string to raw bytes. - Filter `value | base64_decode` Decodes a base 64 string to a string, by default utf-8 encoding is used. - Filter `value | base64_decode("ascii")` Decodes a base 64 string to a string, using ascii encoding. - Filter `value | base64_decode(None)` Decodes a base 64 string to raw bytes. @@ -1185,6 +1186,8 @@ Some examples: - `{{ "aG9tZWFzc2lzdGFudA==" | base64_decode }}` - renders as `homeassistant` - `{{ "aG9tZWFzc2lzdGFudA==" | base64_decode(None) }}` - renders as `b'homeassistant'` +- `{{ "0F010003" | from_hex }}` - renders as `b'\x0f\x01\x00\x03'` +- `{{ "0F010003" | from_hex | base64_encode }}` - renders as `DwEAAw==` {% endraw %}