Not JSON RESTful Sensor?

Are a few days that I discovered HASS, and suddenly I was falled in love!
So… now I would like to gather data from my Blynk server via RESTful API.
The problem is that my Blynk server answer with a simple unformatted (not JSON) string like

["17.300"]

for a float value.

My configuration,yaml is

sensor:
  - platform: rest
    resource: https://192.168.1.189:9443/2affa38aa6f245d39dff7ff0ff2ec4c7/pin/V8
    verify_ssl: false
    name: tHome_med
    value_template: '{{ value }}'
    unit_of_measurement: °C

The HASS display the entiere string that my server return… how I can elimiate the brackets and the quotes to display a true float number?

@Fulvi_Igor,

try '{{ value[0] }}' since its a list. And can use the float filter | float to ensure its a number.

Regards

… using
value_template: '{{ value[0] | float }}'
… I got:
0.0°C

… and using
value_template: '{{ value[0] }}'
… I got:
[

… unespected result!

@Fulvi_Igor, can you post the entire feedback from the sensor you have?

Regards

Typing:

curl -k -X GET https://192.168.1.189:9443/2affa38aa6f245d39dff7ff0ff2ec4c7/pin/V8

answer is:

["17.200"]

@Fulvi_Igor, Well one crude way I think to solve it, will be to turn it into a string first.

I will try ""join(value), this will output a string, which you can then turn into a float. I am no expert, but I think this should work.

Regards

It’s not pretty, but try {{ value | replace('"','') | replace("[","") | replace("]","") | float }}.

Using your “formula” in the Developer Tools - Templates it works, but using the same string in the configuration.yaml it return me a error! :sweat:

This is my code:

  - platform: rest
    resource: https://192.168.1.189:9443/2affa38aa6f245d39dff7ff0ff2ec4c7/pin/V8
    verify_ssl: false
    name: tHome_med
    value_template: '{{ value | replace('"','') | replace("[","") | replace("]","") | float }}'
    unit_of_measurement: °C

And this is the error I get:

ERROR (SyncWorker_0) [homeassistant.util.yaml] while parsing a block mapping                               
  in "/config/configuration.yaml", line 105, column 5                                                                          
expected <block end>, but found '<scalar>'

The problem is the template has single and double quotes already. Try it like this:

- platform: rest
    resource: https://192.168.1.189:9443/2affa38aa6f245d39dff7ff0ff2ec4c7/pin/V8
    verify_ssl: false
    name: tHome_med
    value_template: >-
      {{ value | replace('"','') | replace("[","") | replace("]","") | float }}
    unit_of_measurement: °C
1 Like

@NotoriousBDG YESSSA! it works! the “>-” solve the problem! really many thanks!

1 Like