Tom’s solution will always get the 2nd digit, I.E. The digit after the word state. If the shape of the object changes, that won’t work. If you wan’t to ensure that you always get the state…
{% set value = my_test_json | regex_findall_index('\"state\" : \d+', index=0) %}
{{ value.split(':')[-1].strip() }}
This is finding the first instance of the phrase "state" : <number>. Then, we split the returned value on the colon. Select the last value (the number), and remove the extra white space.
EDIT: This of course assumes that the state is a string. If you change your rest sensor… you can have it just plop out that value.
This should put the whole object as a 0 attribute. Don’t know if that portion will work, never tried it. If it does work, your attributes will be accessible as json object too.
Last EDIT: I think we need a PR that depreciates json_attributes and replaces it with json_attributes_template, like MQTT sensors. There are too many of these topics that return a list of objects and that would require a template to extract.
What I don’t understand… in Tom’s example he used index 1 and you use index 0 - this is very fuzzy… both work but I’m not 100% sure I understand why… (well I’m 100% sure I don’t understand actually)