Create custom sensor depending on different inputs

Hi all,

I’m quite new to HA, I’m already able to intergrate some of my home devices (Stiebel WPC / Zehnder ventilation system) but this was mostly copy and paste with some modification.

I now want to create a “Sensor” which supplies the status of a valve “Open, Close or Error”

I have two sensors:
binary_sensor.heating_basement_valve_closed → Sensor is high when valve is closed
binary_sensor.heating_basement_valve_open–> Sensor is high when valve is opened.

In my configuration.yaml i use:
sensor: !include_dir_merge_list sensor/

I’ve created seperate yaml file: sensor/temp.yaml with the following code:

template:
  - sensor:
      - name: "status_basement_valve"
        state: >
          {% if is_state('binary_sensor.heating_basement_valve_closed', 'on') %}
            Closed
          {% elif is_state('binary_sensor.heating_basement_valve_open', 'on') %}
            Open
          {% else %}
            Error
          {% endif %}

I don’t get an error when I restart HA but I can’t find the sensor in when I create a Entities card.

What am I doing wrong?

Thank you all in advance.

I have template sensors setup in just that way.
But my syntax is different:

- platform: template
  sensors:
    sensor_name:

Its in a yaml file in the sensors directory same as the op

Yes, so Template is a seperate integration and i should adjust my sensors made in the legacy way to prevent future problems.
So instead of a sensor having the template platform, its a template with a sensor defined in it.

And this would still work?
template: !include templates.yaml
Or include a directory

Hi all,

Its working now.
I’ve put the template.yaml directly in the config folder.

Used this in my configruation.yaml:
template: !include template.yaml

And the template.yaml:

- sensor:
  - name: "status_basement_valve"
    state: >
      {% if is_state('binary_sensor.verwarming_kelder_klep_uit', 'on') %}
        closed
      {% elif is_state('binary_sensor.verwarming_kelder_klep_aan', 'on') %}
        Open
      {% else %}
        Error
      {% endif %}
`
Thank you all!