muenze96
(Sebastian Meinke)
September 3, 2023, 1:39pm
1
I made a template sensor, but I don’t understand why there is always an error when reloading…
sensor.yaml:
# Berechne den verbleibenden NAS-Speicher
- sensor:
- name: freier NAS-Speicher
unique_id: freier_NAS-Speicher
state: {{ '%0.2f' | format((states('sensor.diskstation_volume_1_total_size') | float) - (states('sensor.diskstation_volume_1_used_space') | float)) }}
The error:
Error loading /config/configuration.yaml: while scanning for the next token
found character ‘|’ that cannot start any token
in “/config/template.yaml”, line 5, column 23
NathanCu
(Nathan Curtis)
September 3, 2023, 1:46pm
2
You’re trying to pipe ‘%0.2f’ into a sensor value (invalid action) a pipe is used to push a value into a function and you are instead directing it to a sensor output…
So what are you actually trying to do?
muenze96
(Sebastian Meinke)
September 3, 2023, 1:58pm
3
I would like to subtract the values of the two sensors from each other and output them in a new sensor.
‘%0.2f’ just for format
In the development tools, the template between the curly brackets gives the result that the new sensor is looking for!
123
(Taras)
September 3, 2023, 3:18pm
4
muenze96:
always an error when reloading…
sensor.yaml :
…
cannot start any token
in “/config/template.yaml ”, line 5, column 23
Is that example in sensor.yaml
or template.yaml
?
I will assume it’s in template.yaml
.
You can use the round
filter like this:
# Berechne den verbleibenden NAS-Speicher
- sensor:
- name: freier NAS-Speicher
unique_id: freier_NAS-Speicher
state: >
{{ (states('sensor.diskstation_volume_1_total_size') | float(0) -
states('sensor.diskstation_volume_1_used_space') | float(0)) | round(2) }}
1 Like
muenze96
(Sebastian Meinke)
September 3, 2023, 3:42pm
5
You are right! It‘s in template.yaml…
Your solution work fine! Thanks
1 Like
muenze96
(Sebastian Meinke)
September 3, 2023, 4:06pm
6
I’ve tried a little and the following works as well:
# Berechne den verbleibenden NAS-Speicher
- sensor:
- name: freier NAS-Speicher1
unique_id: freier_NAS-Speicher1
state: >
{{ '%0.2f' | format(states('sensor.diskstation_volume_1_total_size') | float(0) -
states('sensor.diskstation_volume_1_used_space') | float(0) }}