Error while executing automation with service_template

I have trouble, my automation with service_temlate not working
In logs i see error: Error while executing automation automation.bedroom_switch_light2: Template rendered invalid service.

- alias: bedroom_switch_light2
  trigger:
    - platform: state
      entity_id: sensor.0x00158d000170d9eb_action
      to: 'single_right'
  action:
    - entity_id: light.xiaomi_philips_smart_led_ceiling_lamp
      service_template: >
        {%- if states('sensor.ph_lamp_bedroom_brightness') | float >=1 and states('sensor.ph_lamp_bedroom_brightness') | float < 56 -%}
          xiaomi_miio_philipslight.light_set_scene
        {% endif %}
      data_template:
         scene: 2

You don’t have an else case for when your if statement is not true. This gives a null service → error.

If you don’t have another service to run when the if test is not true then don’t use a service template.

Put the test as a template condition (or use numeric state conditions) and just put your service in the actions. It won’t run if the conditions don’t pass.

Hm, i have 3 same automation to this lamp

- alias: bedroom_switch_light3
  trigger:
    - platform: state
      entity_id: sensor.0x00158d000170d9eb_action
      to: 'single_right'
  action:
    - entity_id: light.xiaomi_philips_smart_led_ceiling_lamp
      service_template: >
        {%- if states('sensor.ph_lamp_bedroom_brightness') | float == 100  -%}
          xiaomi_miio_philipslight.light_set_scene
        {%- elif states('sensor.ph_lamp_bedroom') | float == 4  -%}
          xiaomi_miio_philipslight.light_set_scene
        {%- elif is_state('light.xiaomi_philips_led_celling', 'off') -%}
          xiaomi_miio_philipslight.light_set_scene
        {% endif %}
      data_template:
         scene: 3
- alias: bedroom_switch_light1
  trigger:
    - platform: state
      entity_id: sensor.0x00158d000170d9eb_action
      to: 'singel_right'
  action:
    - entity_id: light.xiaomi_philips_smart_led_ceiling_lamp
      service_template: >
        {%- if states('sensor.ph_lamp_bedroom_brightness') | float >=56 and states('sensor.ph_lamp_bedroom_brightness') | float < 100 -%}
          xiaomi_miio_philipslight.light_set_scene
        {% endif %}
      data_template:
         scene: 1

It work before i update from 2023.11 version to actual

It check brightnest lamp and night mode

With chat gpt made one automation and it work

- alias: bedroom_switch_light
  trigger:
    - platform: state
      entity_id: sensor.0x00158d000170d9eb_action
      to: 'single_right'
  action:
    - choose:
        - conditions:
            - condition: template
              value_template: "{{ states('sensor.ph_lamp_bedroom_brightness') | float == 100 }}"
          sequence:
            - service: xiaomi_miio_philipslight.light_set_scene
              data:
                entity_id: light.xiaomi_philips_smart_led_ceiling_lamp
                scene: 3
        - conditions:
            - condition: template
              value_template: "{{ states('sensor.ph_lamp_bedroom') | float == 4 }}"
          sequence:
            - service: xiaomi_miio_philipslight.light_set_scene
              data:
                entity_id: light.xiaomi_philips_smart_led_ceiling_lamp
                scene: 3
        - conditions:
            - condition: state
              entity_id: light.xiaomi_philips_smart_led_ceiling_lamp
              state: 'off'
          sequence:
            - service: xiaomi_miio_philipslight.light_set_scene
              data:
                entity_id: light.xiaomi_philips_smart_led_ceiling_lamp
                scene: 3
        - conditions:
            - condition: template
              value_template: "{{ states('sensor.ph_lamp_bedroom_brightness') | float >= 1 and states('sensor.ph_lamp_bedroom_brightness') | float < 56 }}"
          sequence:
            - service: xiaomi_miio_philipslight.light_set_scene
              data:
                entity_id: light.xiaomi_philips_smart_led_ceiling_lamp
                scene: 2
        - conditions:
            - condition: template
              value_template: "{{ states('sensor.ph_lamp_bedroom_brightness') | float >= 56 and states('sensor.ph_lamp_bedroom_brightness') | float < 100 }}"
          sequence:
            - service: xiaomi_miio_philipslight.light_set_scene
              data:
                entity_id: light.xiaomi_philips_smart_led_ceiling_lamp
                scene: 1