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
tom_l
April 18, 2022, 3:06am
2
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"
tom_l
April 18, 2022, 3:18am
4
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”
tom_l
April 18, 2022, 3:25am
6
Go to http://192.168.1.125:61208/api/3/uptime
in your web browser, take a screenshot and paste it here.
tom_l
April 18, 2022, 3:26am
8
The template does work, if the result is according to the API document:
tom_l
April 18, 2022, 3:27am
9
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.
tom_l
April 18, 2022, 3:32am
11
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?
tom_l
April 18, 2022, 3:53am
14
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
tom_l
April 18, 2022, 9:43am
16
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.
tom_l
April 18, 2022, 11:30am
18
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.
tom_l
April 18, 2022, 11:33am
20
Are you putting this in a package?
Try it like this:
value_template: >
{{ value|replace('"','') }}
Make sure you copy the template exactly.