States not showing for a template sensor

I created a template sensor with a few states that I was hoping to use in automations. I’m no pro at this, so all was done by researching online, looking for some kind of examples, but I cat get the states of the template sensor to show as options when setting an automation.
The code below creates an entity that I can use in automations, but the only options as states are: available or unavailable. Fechado (Closed), Aberto (Open), A abrir/fechar (Opening/closing) do not show up.
Can someone point me in the right direction?

- platform: template
    sensors:
      portao_exterior_abrir_fechar:
        icon_template: mdi:gate-alert 
        friendly_name: "Portão exterior estado"
        value_template: >-
          {% if is_state('binary_sensor.portao_exterior_portao_exterior_estado', 'off') and is_state('binary_sensor.portao_exterior_portao_exterior_movimento', 'off') %}
            Fechado
          {% elif is_state('binary_sensor.portao_exterior_portao_exterior_estado', 'on') and is_state('binary_sensor.portao_exterior_portao_exterior_movimento', 'off') %}
            Aberto
          {% elif is_state('binary_sensor.portao_exterior_portao_exterior_estado', 'on') and is_state('binary_sensor.portao_exterior_portao_exterior_movimento', 'on') %}
            A abrir/fechar
          {% endif %}

Are you sure you have the binary_sensor entity IDs correct? Do they really have portao_exterior repeated like that?

Have you included this YAML under sensor: (correct) or binary_sensor: (incorrect)?

You also have no state defined when estado is off and movimento is on.

Would recommend using the modern configuration for template sensors: you have used legacy format.

EDIT: having read @FPro’s response: it hadn’t occurred to me that the sensor might be working fine. Does it correctly show the states you want elsewhere in the system?

Just enter the desired state in the field. The drop down doesn’t know the different states of your sensor.

2 Likes

Yep, thats how the sensor ID is. Dont know why it’s repeated. And yes, the template is under sensor in the yaml configuration file.
I have no state for when estado is off and movimento is on because if the state (estado) is off it means the gate (reed switch) is closed . With movement (movimento) on the reed switch is open.

In the states tab under programing tools the correct states do show up according to the template sensor. I will enter manually and see if the automation works.