Hi All, i am wondering if there is a way to use special chars (bytes 0 - 32) in the scripts?
I have a shell command like this:
shell_command:
relay_close_shell: printf "%b" "\x00" > /dev/ttyAMA0
which sends byte ‘0x00’ to serial port. This works fine. However i would like to give the “\x00” string as a parameter to the shell command.
I tried two attempts but failed
Attempt 1:
shell_command:
relay_open_shell: printf "%b" "{{ hex_bytes[0] }}" > /dev/ttyAMA0
and then use it like this:
turn_on:
service: shell_command.relay_open_shell
data_template:
hex_bytes: ["\x00"]
This attempt failed with this exception: Error [1855951272] embedded null byte
I was not able to pass a string with ‘0’ bytes as a parameter
The second attempt was to pass the bytes as an array to the command like this:
turn_on:
service: shell_command.relay_open_shell
data_template:
hex_bytes: [0x00]
And then use it like this:
shell_command:
relay_open_shell: printf "%b" "\x{{ "%02X" | format(hex_bytes[0]) }}" > /dev/ttyAMA0
This attempt also failed because it creates the wrong string. It creates a string containing all of these chars ‘\x00’ and not a string which has only one char - the null byte.
Do you have any idea how could i solve this problem? Either pass somehow the string containing null bytes as a parameter or create the string from null byte in a propper way?
Thank you
Patrik