How can show the characters in the field context_id_bin normally?

Enter into configuration directory:

cd /home/homeassistant/.homeassistant$

Enter into sqlite3 console:

sqlite3   home-assistant_v2.db
SQLite version 3.34.1 2021-01-20 14:10:07
Enter ".help" for usage hints.
sqlite> PRAGMA encoding; 
UTF-8

PRAGMA table_info(states);
0|state_id|INTEGER|1||1
1|entity_id|CHAR(0)|0||0
2|state|VARCHAR(255)|0||0
3|attributes|CHAR(0)|0||0
4|event_id|SMALLINT|0||0
5|last_changed|CHAR(0)|0||0
6|last_changed_ts|FLOAT|0||0
7|last_updated|CHAR(0)|0||0
8|last_updated_ts|FLOAT|0||0
9|old_state_id|INTEGER|0||0
10|attributes_id|INTEGER|0||0
11|context_id|CHAR(0)|0||0
12|context_user_id|CHAR(0)|0||0
13|context_parent_id|CHAR(0)|0||0
14|origin_idx|SMALLINT|0||0
15|context_id_bin|BLOB|0||0
16|context_user_id_bin|BLOB|0||0
17|context_parent_id_bin|BLOB|0||0
18|metadata_id|INTEGER|0||0
sqlite> select context_id_bin  from states limit 10;
��$��+�y�솔�9
��$���n�uxJ9
��$�	(�Y���d�%
��$�R��|Z�
��$��8
      �
       �K+	
��$�Èdz"�u��
��$�q��b��
��$��e���l�~o
�:�Zz$S��
���}V������$

How can show the characters in field context_id_bin normally?

Normally?

You would interrogate a trigger’s context in a template like this:

'{{ trigger.to_state.context.id  }}'
'{{ trigger.to_state.context.parent_id }}'
'{{ trigger.to_state.context.user_id }}

Tell us the problem are you trying to solve, rather than how you think you should do it.

https://xyproblem.info/

1 Like

Why they are gibberish characters for some fields ?

They are not gibberish they are unique identifiers.

That field, context_id_bin, specifically, is a binary BLOB in sqlite. So yeah, binary, so gibberish when displayed on the console.

Other fields display just fine

sqlite> select state_id  from states limit 10;
56363600
56389430
56414271
56422559
56424038
56425482
56442520
56464745
56487298
56510676
sqlite> select state  from states limit 10;
2023-08-16T02:11:31+00:00
2023-08-16T02:11:31+00:00
2023-08-16T02:11:31+00:00
2023-08-16T02:11:31+00:00
2023-08-16T02:11:31+00:00
2023-08-16T02:11:31+00:00
2023-08-16T02:11:31+00:00
2023-08-16T02:11:31+00:00
2023-08-16T02:11:23+00:00
2023-08-16T02:11:31+00:00
sqlite> select state  from states order by last_updated_ts DESC limit 10;
in 13:07
above_horizon
1.38
1.1
on
0.33
0.96
15
0.49
0.66