Dynamic sensor

Sensor dinâmico para card pôr do sol com nome condicional

sensor:
  - platform: template
    sensors:
      sun_dynamic_sensor:
        friendly_name: >
          {% if is_state('sun.sun', 'below_horizon') %}
            "Nascer do Sol"
          {% else %}
            "Pôr do Sol"
          {% endif %}
        value_template: >
          {% if is_state('sun.sun', 'below_horizon') %}
            {% if state_attr('sun.sun', 'next_rising') %}
              {{ state_attr('sun.sun', 'next_rising') | as_timestamp | timestamp_custom('%d-%m-%Y %H:%M') }}
            {% else %}
              "Unknown"
            {% endif %}
          {% else %}
            {% if state_attr('sun.sun', 'next_dusk') %}
              {{ state_attr('sun.sun', 'next_dusk') | as_timestamp | timestamp_custom('%d-%m-%Y %H:%M') }}
            {% else %}
              "Unknown"
            {% endif %}
          {% endif %}
        device_class: timestamp
        attribute_templates:
          next_rising: >
            {% if state_attr('sun.sun', 'next_rising') %}
              {{ state_attr('sun.sun', 'next_rising') | as_timestamp | timestamp_custom('%d-%m-%Y %H:%M') }}
            {% else %}
              "Unknown"
            {% endif %}
          next_dusk: >
            {% if state_attr('sun.sun', 'next_dusk') %}
              {{ state_attr('sun.sun', 'next_dusk') | as_timestamp | timestamp_custom('%d-%m-%Y %H:%M') }}
            {% else %}
              "Unknown"
            {% endif %}

I need that sensor shows me the exactly time of sunrise and sun dusk but now for me shows unknown
better I sayng after sunrise show me Por do sol and exactly time of sun dusk after the sun dusk shows me nascer do show and exactly time of sunrise
but on the time shows me unknown

What is this condition supposed to accomplish? If you check Developer Tools > Template it does not seem to evaluate as truthy:

{{ state_attr('sun.sun', 'next_rising') is true }} => False

Personally I’d just skip that if / else entirely. But if you are concerned about the value being missing, make your condition is not none:

{{ state_attr('sun.sun', 'next_rising') is not none }}

You probably can also skip your as_timestamp filters as what you get out of those attribute should already be datetime objects.