Template doesn't work

I have hits modbus configuration

modbus:
  - name: victron
    host: 192.168.3.225  #ip from raspberry PI victron gx
    type: tcp
    port: 502
    
    sensors:
      - name: "Smartsolar Battery Current"
        scan_interval: 10
        unit_of_measurement: "A"
        slave: 237
        address: 772
        data_type: int16
        scale: 0.1
        #precision: 2
        device_class: current

      - name: "temp_SCS"
        scan_interval: 10
        slave: 237
        address: 775

And this template

template:
  - sensor:
      - name: "Smartsolar_Charger_State_v2"
        value_template: >-
          {% if is_state('sensor.temp_SCS', '0') %}
            Off
          {% elif is_state('sensor.temp_SCS', '3') %}
            Bulk
          {% elif is_state('sensor.temp_SCS', '2') %}
            Fault 
          {% elif is_state('sensor.temp_SCS', '4') %}
            Absorbtion
          {% elif is_state('sensor.temp_SCS', '5') %}
            Float
          {% elif is_state('sensor.temp_SCS', '6') %}
            Storage
          {% elif is_state('sensor.temp_SCS', '7') %}
            Equalize
          {% elif is_state('sensor.temp_SCS', '11') %}
            Other (Hub-1)
          {% elif is_state('sensor.temp_SCS', '252') %}
            External Control   
          {% else %}
            N/A
          {% endif %}

When I check the config it looks ok. Also the template looks to work in the template checker

The main issue is not the template, it is that you have mixed current and legacy template sensor configuration methods. When done properly, either method will work, but you can’t mix them.

The current method uses template: as the top level header, as you have… so that is what I will use. This method requires you to use state: not value_template:.

template:
  - sensor:
      - name: "Smartsolar_Charger_State_v2"
        state: >-
          {% if is_state('sensor.temp_SCS', '0') %}
            Off
          {% elif is_state('sensor.temp_SCS', '3') %}
            Bulk
          {% elif is_state('sensor.temp_SCS', '2') %}
            Fault 
          {% elif is_state('sensor.temp_SCS', '4') %}
            Absorbtion
          {% elif is_state('sensor.temp_SCS', '5') %}
            Float
          {% elif is_state('sensor.temp_SCS', '6') %}
            Storage
          {% elif is_state('sensor.temp_SCS', '7') %}
            Equalize
          {% elif is_state('sensor.temp_SCS', '11') %}
            Other (Hub-1)
          {% elif is_state('sensor.temp_SCS', '252') %}
            External Control   
          {% else %}
            N/A
          {% endif %}

You can also make this more efficient by using a dictionary instead of a series of if/elifs.

template:
  - sensor:
      - name: "Smartsolar_Charger_State_v2"
        state: >-
          {% set state = states('sensor.temp_SCS') | int %} 
          {% set mapper = {
            0: 'Off',
            3: 'Bulk',
            2: 'Fault',
            4: 'Absorbtion',
            5: 'Float',
            6: 'Storage',
            7: 'Equalize',
            11: 'Other (Hub-1)',
            252: 'External Control'   
            } %}
          {% if state in mapper.keys() %}
          {{ mapper.get(state) }}
          {% else %}
            N/A
          {% endif %}

Thanks a lot. I’m not familiar with templates so picked up some peaces from the forum.
Tested both options and work fine.

You should always go to the official docs first and follow those.

Then if you have issues you can look for other sources of info.