I’ve been trying to do what is mentioned here: Getting difference between value of two sensors
but I cant seem to get a successful config check. I’m using the visual studio code editor to check indents etc. and this appears valid in there:
- platform: template
sensors:
value_template: >-
{% set masterbed = states.sensor.master_ensuite_sensor_2.state|float %}
{% set ensuite = states.sensor.master_bedroom_sensor_2.state| float %}
{{ (masterbed - ensuite)|round(1) }}
But I get this:
Invalid config for [sensor.template]: expected dictionary for dictionary value @ data[‘sensors’][‘value_template’]. Got ‘{% set masterbed = states.sensor.master_ensuite_sensor_2.state|float %} {% set ensuite = states.sensor.master_bedroom_sensor_2.state| float %} {{ (masterbed - ensuite)|round(1) }}’. (See ?, line ?).
What am I missing? I tried pasting the example in the top link and updating the entities etc but it wouldn’t validate either.
What I don’t understand is what goes above the -platform line, do I need to list the entities the template is reading states from, and if I put Sensor: above - platform it errors. So I call it sensor ensuite_diff_humidity: but then when i set some_name: lower as suggested which one does HA see?
If I apply the above mentioned fixes Check config times out.
You don’t have a - platform: line in that example.
If you have the template sensor definition in your configuration.yaml file the only thing above it should be sensor: and that should only appear once.
If you have split your configuration by putting sensor: !include sensors.yaml once in your configuration.yaml file and your template sensor definition is in the sensors.yaml file then nothing goes above -platform:.
No. That is no longer supported.
Because you either have sensor: more than once in your configuration.yaml file or you put it in the !include file (which actually resolves to having declared sensor: more than once).
This is valid:
- platform: template
sensors:
some_name:
value_template: >
{% set masterbed = states('sensor.master_ensuite_sensor_2') | float %}
{% set ensuite = states('sensor.master_bedroom_sensor_2') | float %}
{{ (masterbed - ensuite) | round(1) }}
See the example here:
Note how the very first comment (light grey) says it is an example for including in configuration.yaml. If it is going in your sensors.yaml file, drop the sensor: line.
One follow up question: I didn’t split my files with an include, so I have items like light one: etc to make each entry unique. Is that label for them completely irrelevant? As in if I move to an include file will it change anything?
You can split it the same way for each light x: definition and have multiple files, or paste them all into the one file as in the first example above and remove all the light x: definitions.
I assumed as much but are you saying the word “one” isn’t really used so if I drop all the iterations of light one: light two: etc and put them all in the light: !include lights.yaml there will be no change to the entities names?
Hello! I’ve been trying to create my first sensor, following your examples, and now it works.
I have created a split configuration.
My sensors.yaml file is:
It computes the difference between my grid energy and the solar panels.
How could I add the following information:
icon
a friendly name
unity of measurement
If i browse the entities from the interface, it says that i cannot modify it because it is not unique: is that a normal behavior or is it an error?
Thank you,
Fabio