Cannot get rest to work

I installed the glances. I try to get the information of the time server running. I tried all sorts of things and I can not get the right information.

I open the link http://192.168.1.1.61208/api/3/uptime through the browser I get the result of time.

I will be happy to help how to get the information under the HA area developers under Template

sensor:
  - platform: rest
    name: Glances - SERVER - Uptime
    value_template: '{{ value_json }}'
    resource: http://192.168.1.125:61208/api/3/uptime

Looking at the glances API reference for get uptime https://glances.readthedocs.io/en/latest/api.html#get-uptime it is reported like this {'seconds': 1178914} so you want:

sensor:
  - platform: rest
    name: "Glances - SERVER - Uptime"
    resource: http://192.168.1.125:61208/api/3/uptime
    value_template: "{{ value_json.seconds }}"
    unit_of_measurement: "s"

thank you for the answer

Still no result.

The template editor does not run the rest sensor platform to get the information, it only evaluates templates. So value_json in undefined in the editor. You have to paste the code into your config, restart then check the seonsor’s state in Developer Tools → States.

Good progress - it shows the uptime but it does not show the real uptime

“5 days, 13:50:15”

Go to http://192.168.1.125:61208/api/3/uptime in your web browser, take a screenshot and paste it here.

The template does work, if the result is according to the API document:

Ok, that is not what the API document says. Just do this:

sensor:
  - platform: rest
    name: "Glances - SERVER - Uptime"
    resource: http://192.168.1.125:61208/api/3/uptime
    value_template: "{{ value }}"

Thank you very much - I helped me very much. Thanks.

I think if you want it just as a value in seconds you would have to do this:

sensor:
  - platform: rest
    name: "Glances - SERVER - Uptime"
    resource: http://192.168.1.125:61208/api/3/uptime
    headers:
      Content-Type: application/json
    value_template: "{{ value_json.seconds }}"
    unit_of_measurement: "s"

If you are happy with how it reports in human readable format you can ignore this.

Thank you very much - I’ll check what the right for me.

Is it possible to remove the quotation marks?

Sure:

sensor:
  - platform: rest
    name: "Glances - SERVER - Uptime"
    resource: http://192.168.1.125:61208/api/3/uptime
    value_template: "{{ value|replace('"','') }}"
1 Like
Error loading /config/configuration.yaml: while scanning a quoted scalar in "/config/packages/unraid/unraid.yaml", line 5, column 41 found unexpected end of stream in "/config/packages/unraid/unraid.yaml", line 5, column 50

That does not look like it has anything to do with this.

He walks because of the code - I asked whether it was possible to lower the quotation marks.

And I showed you how.

value_template: "{{ value|replace('"','') }}"

Apparently you did not understand me-I copied your code, I put it and made a test through Ha. Then he shouted that the code was improper.

Are you putting this in a package?

Try it like this:

value_template: >
  {{ value|replace('"','') }}

Make sure you copy the template exactly.