Shelly color bulb over MQTT in Home Assistant 2023

Here is a configuration that works with Shelly Color bulb firmware v1.14.0 and Home Assistant v2023.10.1.

mqtt:
  - light:
      name: "Office light RGB"
      schema: template
      qos: 1
      max_mireds: 333
      min_mireds: 154
     
      # replace <deviceid> with an actual device ID
      state_topic: "shellies/shellycolorbulb-<deviceid>/color/0/status"
      command_topic: "shellies/shellycolorbulb-<deviceid>/0/set"

      brightness_template: "{{ value_json.brightness | float | multiply(2.55) | round(0) }}"
      color_temp_template: "{{ 1000000 | multiply(1/(value_json.temp | float)) | round(0) }}"
      command_off_template: '{"effect": 0,"turn":"off"}'
      command_on_template: >-
        {
          "turn": "on",
          
          {%- if red is defined and green is defined and blue is defined -%}
            "mode": "color",
            "red": {{ red }},
            "green": {{ green }},
            "blue": {{ blue }},
          {%- endif -%}
          
          {%- if brightness is defined -%}
            "gain": {{brightness | float | multiply(0.3922) | round(0)}},
            "brightness": {{brightness | float | multiply(0.3922) | round(0)}},
          {%- endif -%}

          {%- if effect is defined -%}
            {%- if effect == 'Meteor Shower' -%}
              "effect": 1,
            {%- elif effect == 'Gradual Change' -%}
              "effect": 2,
            {%- elif effect == 'Breath' -%}
              "effect": 3,
            {%- elif effect == 'Flash' -%}
              "effect": 4,
            {%- elif effect == 'On/Off Gradual' -%}
              "effect": 5,
            {%- elif effect == 'Red/Green Change' -%}
              "effect": 6,
            {%- else -%}
              "effect": 0,
            {%- endif -%}
          {%- else -%}
            "effect": 0,
          {%- endif -%}

          {% if color_temp is defined %}
            "mode": "white",
            "temp":{{ (1/(color_temp | float)) | multiply(1000000) | round(0) }},
          {% endif %}
        }

      red_template: "{{ value_json.red }}"
      green_template: "{{ value_json.green }}"
      blue_template: "{{ value_json.blue }}"
      effect_template: "{{ value_json.effect }}"

The following syntax is deprecated and does not work:

light:
  - platform: mqtt
...

If I specified state_template in this form, the state of the bulb was not reported to Home Assistant. Everything works after removing it.

    state_template: "{% if value_json.ison %}on{% else %}off{% endif %}"

Inspired by MQTT Config for Shelly Duo Light Bulb - Share your Projects! - Home Assistant Community.