Making a conditional Template Sensor work

template:
- sensor:
    - name: "Inverted Power"
      unique_id: inverted_power_from_template
      unit_of_measurement: W
      device_class: power
      state: >
        {% if is_state('binary_sensor.multiplus_ii_24_3000_70_32_id_276_connected_2', 'On') %}
          {{ states('sensor.multiplus_ii_24_3000_70_32_id_276_0_line_1_output_power_2') }}
        {% else %}
          0
        {% endif %}

I have the above in configuration.yaml and have rebooted after adding it. I have other working template sensors, but after reboot, my sensor 'sensor.inverted_power_from_template' does not exist. Basically I want it to return either the inverter power or zero where the state of a different (binary) sensor indicates that the inverter has been turned off.

Any idea's what I have got wrong?

Based on the provided config the entity ID would be sensor.inverted_power, not sensor.inverted_power_from_template.

The variable default_entity_id will override the automatically created entity ID based on the name. The entity ID is only based on unique_id when neither of those variables are assigned a value.

If, in fact, the entity wasn't created that points to a YAML problem. Make sure you only have 1 top-level template key in configuration.yaml.

Other issues:

  1. The state of a binary sensor will never be "On"... it will be "on"... states are case-sensitive.
  2. Any time you have assigned a unit of measurement you need to either set an availability or assign a numeric default to avoid the sensor state being unknown.
template:
  - sensor:
      - name: "Inverted Power"
        default_entity_id: sensor.inverted_power_from_template
        unique_id: inverted_power_from_template
        unit_of_measurement: W
        state_class: measurement
        device_class: power
        state: >
          {% if is_state('binary_sensor.multiplus_ii_24_3000_70_32_id_276_connected_2', 'on') %}
            {{ states('sensor.multiplus_ii_24_3000_70_32_id_276_0_line_1_output_power_2') | default(0, true) }}
          {% else %}
            0
          {% endif %}

Thanks. Issue now sorted. I think it was a combo of my assuming that the entity ID was what I stated in my default and also the 'on' vs 'On'. Working now, anyways so thanks!