toband
(Tobias)
1
My plan is to use a Aqara Vibration Sensor to act as a garage door sensor for status Open/Closed.
The idea is to use the orientation. If someone has a better way please share both idea and code please. 
So far I have managed to get a template sensor for the orientation that returns the value: [0, 1, -89]
- platform: template
sensors:
vibration_6_orientation:
value_template: '{{ states.binary_sensor.vibration_6.attributes.orientation }}'
friendly_name: 'Vibration Sensor Orientation'
Now I am trying to split the value template and just get -89 back but I can’t seem to get it correct with the syntax.
Any help would be appreciated? 
1 Like
tom_l
2
what does this give you in the template editor:
value_template: "{{ state_attr('binary_sensor.vibration_6', 'orientation')[2] }}"
I suspect it won’t be as simple as extracting the 3rd element of the list as it is a string that looks like a list.
In which case you could use:
value_template: >
{{ state_attr('binary_sensor.vibration_6', 'orientation')|regex_findall_index(find="-?\d+", index=2 }}
toband
(Tobias)
3
Thanks for the quick feedback and help.
The template editor do returns back:
value_template: “-89”
so it seems to work.
The second suggestion works also after a little correction. 
Thanks a lot!!
tom_l
4
I’m curious to know what this was. I don’t see it.
toband
(Tobias)
5
Just a missing ) at the end of the regex part
value_template: >
{{ state_attr('binary_sensor.vibration_6', 'orientation')|regex_findall_index(find="-?\d+", index=2 )}}
1 Like