The “1” on the end represents the drive, ie. 1 = C, 2 = D, 3 = E, and so on. The preceding number, ie the 6 and 5 represent the object, so 6 = Used Space and 5 = Total Disk Space.
That’s pretty much the construct.
As far as the sensor goes to calculate percentage:
Thanks, here is my config, finally (in French, but clear enough, I think), with some calculations to have the value in Gb (as they are stored in allocation units). I have left some calculations details instead of a simplified version with parts resolved, just to keep the logic. Some values could be retrieved (units size, etc.), but are not supposed to change, so I hardcoded some.
Newbie here just getting to grips with sensors in configuraion.yaml. I really like the way that you’ve used the variables to make this tidier (my first time with variables) so thought I’d give it a go.
I attempted this as shown below:
ram_free_percentage:
value_template: >-
{% set t = states('sensor.media_pc_total_ram') | int %}
{% set u = states('sensor.media_pc_used_ram') | int %}
{{ ((t - u) / t) x 100 }}
unit_of_measurement: '%'
But when I check configuration it indicates an error:
Invalid config for [sensor.template]: invalid template (TemplateSyntaxError: expected token ‘end of print statement’, got ‘x’) for dictionary value @ data[‘sensors’][‘ram_free_percentage’][‘value_template’]. Got ‘{% set t = states(‘sensor.media_pc_total_ram’) | int %} {% set u = states(‘sensor.media_pc_used_ram’) | int %} “{{ ((t - u) / t) x 100 }}”’. (See ?, line ?).
I’ve looked at the example on the template help page and can’t see any obvious issue when looking at the examples. Do you any guidance or ideas on what may be causing the error?
The scope of a Jinja2 variable is limited to the option where it’s defined. So, no, water_volume isn’t defined outside of value_template.
There are no global Jinja2 variables in Home Assistant.
You can store a value in a Helper (input_number, input_text, etc) or use one of the third party custom_components that implement global variables (by storing them in special entities using the same principle as Helpers).
Really appreciate all the info above. I am having a weird issue. When I enter the below into the developer tools Template section, it returns values as it should. When I add to my sensors.yaml file and reboot, new sensors are not created. Anything obvious standout to anyone? Each grid_usage sensor is a Utility sensor that collects data from other sensor. I don’t think it matters but figured I would mention.
Maybe my current sensors work still because they were created years ago. There aren’t any errors in any of the logs. Will maybe create a new file (template.yaml) and try adding them in the new format there. Then I suspect I need to start migrating all my other template entities.
The Electricity Costs Sensor was a method that I used to group template sensors. I honestly never knew why it didn’t error. In other areas I just use comments now. Below is a larger sample.
Now I need to do some math calculations using days as a numerical parameter in sin(x) function.
(e.g. sin (17771) = 0.8358291413129607)
However, the following syntax: {{ sin (days) }} gives the following error: ValueError: Template error: sin got invalid input '17771 days, 11:59:00.140739' when rendering template.
I tried using various methods and functions to convert this datetime object 17771 days, 11:59:00.140739 into pure integer 17771 but none of them returns the expected result. Now I’m stuck.
Can you please advise?
Hi, I’m struggling to calculate the absolute humidity (i.e. water content) from the relative humidity and temperature. It’s a not a linear relationship so I need to use x ^ y in my calculation but this causes an error. What’s the right syntax for ‘to the power of’. Many thanks