Can I set the status of a template sensor

Is it somehow possible to set the status of a template sensor, let’s say a binary sensor from an automation?
And if so, can I also set an attribute? Here is an example:

- binary_sensor:
  - platform: template
    sensors:
      testsensor:
        friendly_name: "Test Sensor"
        value_template: >
            {{ states("binary_sensor.something") == 'on' }}
        attributes:
            testvalue: "01987431"
            version: "1.0"

Would result in a binary sensor named testsensor with a value true when binary_sensor.something has the value ‘on’
It also has some attributes: testvalue and version. Now I want to call a service that sets another value to this sensor. Also I want to be able to maiplulate the attribute value… Can this be done without custom components?

Yes, you can switch to a trigger-based template sensor that has multiple triggers. A State trigger will get you similar function to the state-based template sensor. Then add a second trigger to override the value. I would probably go with an Event trigger since they don’t require any extra entities and can be customized by type and event data content.

Could you perhaps give an example for that?

template:
  - trigger:
      - platform: state
        entity_id: binary_sensor.something
        to:
          - 'on'
          - 'off'
      - platform: event
        event_type: custom_test_sensor_manual_set
    binary_sensor:
      - platform: template
          - name: "Test Sensor"
            state: |-
              {% set current = this.state|default('off', 1)%}
              {% if trigger.platform == 'state' or trigger.event.data.state is not defined %}
              {{ is_state('binary_sensor.something', 'on') }}
              {% else %}
                {{ trigger.event.data.state }}
              {% endif %}
            attributes:
              testvalue: |-
                {% set current = this.attributes.testvalue | default(0, 1)%}
                {% if trigger.platform == 'state' or trigger.event.data.testvalue is not defined %}
                  {{ current }}
                {% else %}
                  {{ trigger.event.data.testvalue }}
                {% endif %}
              version: "2.0"

HA Docs: Raise and Consume Custom Events

Thanx a lot!