I have an api which returns the following response (example):
<0;99;99;99;0;0;0;0;0;0;0;0;0;0;0>
This is not a normal json format. Given the above output, what would the best approach be to extracting the second value in the list (99) to a sensor?
VDRainer
(🍻)
2
Copy this into Developer Tools/Template and play with it.
{% set response = '<0;99;99;99;0;0;0;0;0;0;0;0;0;0;0>' %}
{{ response.split(';')[1] }}
1 Like
Great, many thanks for the tip! Btw, this is my final implementation:
- platform: rest
resource: http://172.22.1.171/get/90-b2-e4-09-13-17/all/
method: GET
name: controme_wohnen_oeffnung
value_template: >-
{{ ((value.split(';')[1].replace('<','').replace('>','')) | int +
(value.split(';')[2].replace('<','').replace('>','')) | int +
(value.split(';')[3].replace('<','').replace('>','')) | int) / 3 }}