light:
  - platform: mqtt
    name: "light_hama_1"
    state_topic: "stat/light_hama_1/RESULT"
    state_value_template: "{{ value_json.POWER }}"
    command_topic: "cmnd/light_hama_1/POWER"
    payload_on: "ON"
    payload_off: "OFF"
    availability_topic: "tele/light_hama_1/LWT"
    payload_available: "Online"
    payload_not_available: "Offline"
    on_command_type: "brightness"
    brightness_command_topic: "cmnd/light_hama_1/Dimmer"
    brightness_state_topic: "tele/light_hama_1/STATE"
    brightness_scale: 100
    brightness_value_template: "{{ value_json.Dimmer }}"
    color_temp_command_topic: "cmnd/light_hama_1/CT"
    color_temp_state_topic: "tele/light_hama_1/STATE"
    color_temp_value_template: "{{ value_json.CT }}"
    rgb_command_topic: "cmnd/light_hama_1/Color"
    rgb_state_topic: "tele/light_hama_1/STATE"
    rgb_command_template: "{{ '%02X%02X%02X=' | format(red, green, blue)}}"
    rgb_value_template: "{{ (value_json.Color[0]|int(base=16),value_json.Color[1]|int(base=16),value_json.Color[2]|int(base=16)) | join(',')}}"
    qos: 1
    retain: false

  - platform: mqtt
    name: "light_le_1"
    state_topic: "tele/light_le_1/STATE"
    state_value_template: "{{ value_json.POWER }}"
    command_topic: "cmnd/light_le_1/POWER"
    payload_on: "ON"
    payload_off: "OFF"
    availability_topic: "tele/light_le_1/LWT"
    payload_available: "Online"
    payload_not_available: "Offline"
    on_command_type: "brightness"
    brightness_command_topic: "cmnd/light_le_1/Dimmer"
    brightness_state_topic: "tele/light_le_1/STATE"
    brightness_scale: 100
    brightness_value_template: "{{ value_json.Dimmer }}"
    color_temp_command_topic: "cmnd/light_le_1/CT"
    color_temp_state_topic: "tele/light_le_1/STATE"
    color_temp_value_template: "{{ value_json.CT }}"
    qos: 1
    retain: false

  - platform: mqtt
    name: "light_le_2"
    state_topic: "tele/light_le_2/STATE"
    state_value_template: "{{ value_json.POWER }}"
    command_topic: "cmnd/light_le_2/POWER"
    payload_on: "ON"
    payload_off: "OFF"
    availability_topic: "tele/light_le_2/LWT"
    payload_available: "Online"
    payload_not_available: "Offline"
    on_command_type: "brightness"
    brightness_command_topic: "cmnd/light_le_2/Dimmer"
    brightness_state_topic: "tele/light_le_2/STATE"
    brightness_scale: 100
    brightness_value_template: "{{ value_json.Dimmer }}"
    color_temp_command_topic: "cmnd/light_le_2/CT"
    color_temp_state_topic: "tele/light_le_2/STATE"
    color_temp_value_template: "{{ value_json.CT }}"
    qos: 1
    retain: false

  - platform: mqtt
    name: "light_le_3"
    state_topic: "tele/light_le_3/STATE"
    state_value_template: "{{ value_json.POWER }}"
    command_topic: "cmnd/light_le_3/POWER"
    payload_on: "ON"
    payload_off: "OFF"
    availability_topic: "tele/light_le_3/LWT"
    payload_available: "Online"
    payload_not_available: "Offline"
    on_command_type: "brightness"
    brightness_command_topic: "cmnd/light_le_3/Dimmer"
    brightness_state_topic: "tele/light_le_3/STATE"
    brightness_scale: 100
    brightness_value_template: "{{ value_json.Dimmer }}"
    color_temp_command_topic: "cmnd/light_le_3/CT"
    color_temp_state_topic: "tele/light_le_3/STATE"
    color_temp_value_template: "{{ value_json.CT }}"
    qos: 1
    retain: false

  - platform: mqtt
    name: "light_le_4"
    state_topic: "tele/light_le_4/STATE"
    state_value_template: "{{ value_json.POWER }}"
    command_topic: "cmnd/light_le_4/POWER"
    payload_on: "ON"
    payload_off: "OFF"
    availability_topic: "tele/light_le_4/LWT"
    payload_available: "Online"
    payload_not_available: "Offline"
    on_command_type: "brightness"
    brightness_command_topic: "cmnd/light_le_4/Dimmer"
    brightness_state_topic: "tele/light_le_4/STATE"
    brightness_scale: 100
    brightness_value_template: "{{ value_json.Dimmer }}"
    color_temp_command_topic: "cmnd/light_le_4/CT"
    color_temp_state_topic: "tele/light_le_4/STATE"
    color_temp_value_template: "{{ value_json.CT }}"
    qos: 1
    retain: false

  - platform: mqtt
    name: "light_lohas_2"
    state_topic: "tele/light_lohas_2/STATE"
    state_value_template: "{{ value_json.POWER }}"
    command_topic: "cmnd/light_lohas_2/POWER"
    payload_on: "ON"
    payload_off: "OFF"
    availability_topic: "tele/light_lohas_2/LWT"
    payload_available: "Online"
    payload_not_available: "Offline"
    on_command_type: "brightness"
    brightness_command_topic: "cmnd/light_lohas_2/Dimmer"
    brightness_state_topic: "tele/light_lohas_2/STATE"
    brightness_scale: 100
    brightness_value_template: "{{ value_json.Dimmer }}"
    hs_command_topic: "cmnd/light_lohas_2/HSBColor"
    hs_state_topic: "tele/light_lohas_2/STATE"
    hs_value_template: "{{ value_json.HSBColor.split(',')[0:2]|join(',') }}"
    color_temp_command_topic: "cmnd/light_lohas_2/CT"
    color_temp_state_topic: "tele/light_lohas_2/STATE"
    color_temp_value_template: "{{ value_json.CT }}"
    rgb_command_topic: "cmnd/light_lohas_2/Color"
    rgb_state_topic: "tele/light_lohas_2/STATE"
    rgb_command_template: "{{ '%02X%02X%02X=' | format(red, green, blue)}}"
    rgb_value_template: "{{ (value_json.Color[0:2]|int(base=16),value_json.Color[2:4]|int(base=16),value_json.Color[4:6]|int(base=16)) | join(',')}}"
    qos: 1
    retain: false

  - platform: mqtt
    name: "light_lohas_3"
    state_topic: "tele/light_lohas_3/STATE"
    state_value_template: "{{ value_json.POWER }}"
    command_topic: "cmnd/light_lohas_3/POWER"
    payload_on: "ON"
    payload_off: "OFF"
    availability_topic: "tele/light_lohas_3/LWT"
    payload_available: "Online"
    payload_not_available: "Offline"
    on_command_type: "brightness"
    brightness_command_topic: "cmnd/light_lohas_3/Dimmer"
    brightness_state_topic: "tele/light_lohas_3/STATE"
    brightness_scale: 100
    brightness_value_template: "{{ value_json.Dimmer }}"
    hs_command_topic: "cmnd/light_lohas_3/HSBColor"
    hs_state_topic: "tele/light_lohas_3/STATE"
    hs_value_template: "{{ value_json.HSBColor.split(',')[0:2]|join(',') }}"
    color_temp_command_topic: "cmnd/light_lohas_3/CT"
    color_temp_state_topic: "tele/light_lohas_3/STATE"
    color_temp_value_template: "{{ value_json.CT }}"
    rgb_command_topic: "cmnd/light_lohas_3/Color"
    rgb_state_topic: "tele/light_lohas_3/STATE"
    rgb_command_template: "{{ '%02X%02X%02X=' | format(red, green, blue)}}"
    rgb_value_template: "{{ (value_json.Color[0:2]|int(base=16),value_json.Color[2:4]|int(base=16),value_json.Color[4:6]|int(base=16)) | join(',')}}"
    qos: 1
    retain: false

  - platform: mqtt
    name: "light_lohas_4"
    state_topic: "tele/light_lohas_4/STATE"
    state_value_template: "{{ value_json.POWER }}"
    command_topic: "cmnd/light_lohas_4/POWER"
    payload_on: "ON"
    payload_off: "OFF"
    availability_topic: "tele/light_lohas_4/LWT"
    payload_available: "Online"
    payload_not_available: "Offline"
    on_command_type: "brightness"
    brightness_command_topic: "cmnd/light_lohas_4/Dimmer"
    brightness_state_topic: "tele/light_lohas_4/STATE"
    brightness_scale: 100
    brightness_value_template: "{{ value_json.Dimmer }}"
    hs_command_topic: "cmnd/light_lohas_4/HSBColor"
    hs_state_topic: "tele/light_lohas_4/STATE"
    hs_value_template: "{{ value_json.HSBColor.split(',')[0:2]|join(',') }}"
    color_temp_command_topic: "cmnd/light_lohas_4/CT"
    color_temp_state_topic: "tele/light_lohas_4/STATE"
    color_temp_value_template: "{{ value_json.CT }}"
    rgb_command_topic: "cmnd/light_lohas_4/Color"
    rgb_state_topic: "tele/light_lohas_4/STATE"
    rgb_command_template: "{{ '%02X%02X%02X=' | format(red, green, blue)}}"
    rgb_value_template: "{{ (value_json.Color[0:2]|int(base=16),value_json.Color[2:4]|int(base=16),value_json.Color[4:6]|int(base=16)) | join(',')}}"
    qos: 1
    retain: false

  # - platform: mqtt
  #   name: "light_lohas_5"
  #   state_topic: "tele/light_lohas_5/STATE"
  #   state_value_template: "{{ value_json.POWER }}"
  #   command_topic: "cmnd/light_lohas_5/POWER"
  #   payload_on: "ON"
  #   payload_off: "OFF"
  #   availability_topic: "tele/light_lohas_5/LWT"
  #   payload_available: "Online"
  #   payload_not_available: "Offline"
  #   on_command_type: "brightness"
  #   brightness_command_topic: "cmnd/light_lohas_5/Dimmer"
  #   brightness_state_topic: "tele/light_lohas_5/STATE"
  #   brightness_scale: 100
  #   brightness_value_template: "{{ value_json.Dimmer }}"
  #   hs_command_topic: "cmnd/light_lohas_5/HSBColor"
  #   hs_state_topic: "tele/light_lohas_5/STATE"
  #   hs_value_template: "{{ value_json.HSBColor.split(',')[0:2]|join(',') }}"
  #   color_temp_command_topic: "cmnd/light_lohas_5/CT"
  #   color_temp_state_topic: "tele/light_lohas_5/STATE"
  #   color_temp_value_template: "{{ value_json.CT }}"
  #   rgb_command_topic: "cmnd/light_lohas_5/Color"
  #   rgb_state_topic: "tele/light_lohas_5/STATE"
  #   rgb_value_template: "{{ value_json.Color.split(',')[0:3]|join(',') }}"
  #   qos: 1
  #   retain: false

  - platform: mqtt
    name: "light_lohas_6"
    state_topic: "tele/light_lohas_6/STATE"
    state_value_template: "{{ value_json.POWER }}"
    command_topic: "cmnd/light_lohas_6/POWER"
    payload_on: "ON"
    payload_off: "OFF"
    availability_topic: "tele/light_lohas_6/LWT"
    payload_available: "Online"
    payload_not_available: "Offline"
    on_command_type: "brightness"
    brightness_command_topic: "cmnd/light_lohas_6/Dimmer"
    brightness_state_topic: "tele/light_lohas_6/STATE"
    brightness_scale: 100
    brightness_value_template: "{{ value_json.Dimmer }}"
    hs_command_topic: "cmnd/light_lohas_6/HSBColor"
    hs_state_topic: "tele/light_lohas_6/STATE"
    hs_value_template: "{{ value_json.HSBColor.split(',')[0:2]|join(',') }}"
    color_temp_command_topic: "cmnd/light_lohas_6/CT"
    color_temp_state_topic: "tele/light_lohas_6/STATE"
    color_temp_value_template: "{{ value_json.CT }}"
    rgb_command_topic: "cmnd/light_lohas_6/Color"
    rgb_state_topic: "tele/light_lohas_6/STATE"
    rgb_command_template: "{{ '%02X%02X%02X=' | format(red, green, blue)}}"
    rgb_value_template: "{{ (value_json.Color[0:2]|int(base=16),value_json.Color[2:4]|int(base=16),value_json.Color[4:6]|int(base=16)) | join(',')}}"
    qos: 1
    retain: false

  - platform: mqtt
    name: "light_avatar_small_1"
    availability_topic: "tele/light_avatar_small_1/LWT"
    command_topic: "cmnd/light_avatar_small_1/POWER"
    state_topic: "tele/light_avatar_small_1/STATE"
    state_value_template: "{{ value_json.POWER }}"
    brightness_command_topic: "cmnd/light_avatar_small_1/Dimmer"
    brightness_state_topic: "tele/light_avatar_small_1/STATE"
    brightness_scale: 100
    brightness_value_template: "{{ value_json.Dimmer }}"
    on_command_type: "brightness"
    white_value_command_topic: "cmnd/light_avatar_small_1/WHITE"
    white_value_scale: 100
    white_value_state_topic: "tele/light_avatar_small_1/STATE"
    white_value_template: "{{ value_json.White }}"
    rgb_command_topic: "cmnd/light_avatar_small_1/Color"
    rgb_state_topic: "tele/light_avatar_small_1/STATE"
    rgb_value_template: "{{ value_json.Color.split(',')[0:3]|join(',') }}"
    payload_on: "ON"
    payload_off: "OFF"
    payload_available: "Online"
    payload_not_available: "Offline"
    qos: 1
    retain: false

  - platform: "mqtt"
    name: "ledvance_1"
    state_topic: "z2m_deconz/ledvance_1"
    availability_topic: "z2m_deconz/bridge/state"
    brightness: true
    color_temp: true
    xy: false
    hs: false
    schema: "json"
    command_topic: "z2m_deconz/ledvance_1/set"
    brightness_scale: 254
    max_mireds: 500
    min_mireds: 150

sensor:
  - platform: mqtt
    name: "light_hama_1_wifi"
    availability_topic: "tele/light_hama_1/LWT"
    device_class: signal_strength
    payload_available: "Online"
    payload_not_available: "Offline"
    state_topic: "tele/light_hama_1/STATE"
    unit_of_measurement: "%"
    value_template: "{{ value_json.Wifi.RSSI }}"

  - platform: mqtt
    name: "light_le_1_wifi"
    availability_topic: "tele/light_le_1/LWT"
    device_class: signal_strength
    payload_available: "Online"
    payload_not_available: "Offline"
    state_topic: "tele/light_le_1/STATE"
    unit_of_measurement: "%"
    value_template: "{{ value_json.Wifi.RSSI }}"

  - platform: mqtt
    name: "light_le_2_wifi"
    availability_topic: "tele/light_le_2/LWT"
    device_class: signal_strength
    payload_available: "Online"
    payload_not_available: "Offline"
    state_topic: "tele/light_le_2/STATE"
    unit_of_measurement: "%"
    value_template: "{{ value_json.Wifi.RSSI }}"

  - platform: mqtt
    name: "light_le_3_wifi"
    availability_topic: "tele/light_le_3/LWT"
    device_class: signal_strength
    payload_available: "Online"
    payload_not_available: "Offline"
    state_topic: "tele/light_le_3/STATE"
    unit_of_measurement: "%"
    value_template: "{{ value_json.Wifi.RSSI }}"

  - platform: mqtt
    name: "light_le_4_wifi"
    availability_topic: "tele/light_le_4/LWT"
    device_class: signal_strength
    payload_available: "Online"
    payload_not_available: "Offline"
    state_topic: "tele/light_le_4/STATE"
    unit_of_measurement: "%"
    value_template: "{{ value_json.Wifi.RSSI }}"

  - platform: mqtt
    name: "light_lohas_2_wifi"
    availability_topic: "tele/light_lohas_2/LWT"
    device_class: signal_strength
    payload_available: "Online"
    payload_not_available: "Offline"
    state_topic: "tele/light_lohas_2/STATE"
    unit_of_measurement: "%"
    value_template: "{{ value_json.Wifi.RSSI }}"

  - platform: mqtt
    name: "light_lohas_3_wifi"
    availability_topic: "tele/light_lohas_3/LWT"
    device_class: signal_strength
    payload_available: "Online"
    payload_not_available: "Offline"
    state_topic: "tele/light_lohas_3/STATE"
    unit_of_measurement: "%"
    value_template: "{{ value_json.Wifi.RSSI }}"

  - platform: mqtt
    name: "light_lohas_4_wifi"
    availability_topic: "tele/light_lohas_4/LWT"
    device_class: signal_strength
    payload_available: "Online"
    payload_not_available: "Offline"
    state_topic: "tele/light_lohas_4/STATE"
    unit_of_measurement: "%"
    value_template: "{{ value_json.Wifi.RSSI }}"

  - platform: mqtt
    name: "light_lohas_6_wifi"
    availability_topic: "tele/light_lohas_6/LWT"
    device_class: signal_strength
    payload_available: "Online"
    payload_not_available: "Offline"
    state_topic: "tele/light_lohas_6/STATE"
    unit_of_measurement: "%"
    value_template: "{{ value_json.Wifi.RSSI }}"

  - platform: mqtt
    name: "light_avatar_small_1_wifi"
    availability_topic: "tele/light_avatar_small_1/LWT"
    device_class: signal_strength
    payload_available: "Online"
    payload_not_available: "Offline"
    state_topic: "tele/light_avatar_small_1/STATE"
    unit_of_measurement: "%"
    value_template: "{{ value_json.Wifi.RSSI }}"

  - platform: "mqtt"
    name: "ledvance_1_lqi"
    state_topic: "z2m_deconz/ledvance_1"
    availability_topic: "z2m_deconz/bridge/state"
    value_template: "{{ value_json.linkquality }}"
    unit_of_measurement: "lqi"
    icon: "mdi:signal"

## Switch

switch:
  - platform: mqtt
    name: "light_hama_1_fade"
    availability_topic: "tele/light_hama_1/LWT"
    command_topic: "cmnd/light_hama_1/FADE"
    icon: mdi:gradient
    payload_available: "Online"
    payload_not_available: "Offline"
    qos: 1
    state_topic: "stat/light_hama_1/RESULT"
    value_template: "{{ value_json.Fade }}"

  - platform: mqtt
    name: "light_le_1_fade"
    availability_topic: "tele/light_le_1/LWT"
    command_topic: "cmnd/light_le_1/FADE"
    icon: mdi:gradient
    payload_available: "Online"
    payload_not_available: "Offline"
    qos: 1
    state_topic: "stat/light_le_1/RESULT"
    value_template: "{{ value_json.Fade }}"

  - platform: mqtt
    name: "light_le_2_fade"
    availability_topic: "tele/light_le_2/LWT"
    command_topic: "cmnd/light_le_2/FADE"
    icon: mdi:gradient
    payload_available: "Online"
    payload_not_available: "Offline"
    qos: 1
    state_topic: "stat/light_le_2/RESULT"
    value_template: "{{ value_json.Fade }}"

  - platform: mqtt
    name: "light_le_3_fade"
    availability_topic: "tele/light_le_3/LWT"
    command_topic: "cmnd/light_le_3/FADE"
    icon: mdi:gradient
    payload_available: "Online"
    payload_not_available: "Offline"
    qos: 1
    state_topic: "stat/light_le_3/RESULT"
    value_template: "{{ value_json.Fade }}"

  - platform: mqtt
    name: "light_le_4_fade"
    availability_topic: "tele/light_le_4/LWT"
    command_topic: "cmnd/light_le_4/FADE"
    icon: mdi:gradient
    payload_available: "Online"
    payload_not_available: "Offline"
    qos: 1
    state_topic: "stat/light_le_4/RESULT"
    value_template: "{{ value_json.Fade }}"

  - platform: mqtt
    name: "light_lohas_2_fade"
    availability_topic: "tele/light_lohas_2/LWT"
    command_topic: "cmnd/light_lohas_2/FADE"
    icon: mdi:gradient
    payload_available: "Online"
    payload_not_available: "Offline"
    qos: 1
    state_topic: "stat/light_lohas_2/RESULT"
    value_template: "{{ value_json.Fade }}"

  - platform: mqtt
    name: "light_lohas_3_fade"
    availability_topic: "tele/light_lohas_3/LWT"
    command_topic: "cmnd/light_lohas_3/FADE"
    icon: mdi:gradient
    payload_available: "Online"
    payload_not_available: "Offline"
    qos: 1
    state_topic: "stat/light_lohas_3/RESULT"
    value_template: "{{ value_json.Fade }}"

  - platform: mqtt
    name: "light_lohas_4_fade"
    availability_topic: "tele/light_lohas_4/LWT"
    command_topic: "cmnd/light_lohas_4/FADE"
    icon: mdi:gradient
    payload_available: "Online"
    payload_not_available: "Offline"
    qos: 1
    state_topic: "stat/light_lohas_4/RESULT"
    value_template: "{{ value_json.Fade }}"

  - platform: mqtt
    name: "light_lohas_6_fade"
    availability_topic: "tele/light_lohas_6/LWT"
    command_topic: "cmnd/light_lohas_6/FADE"
    icon: mdi:gradient
    payload_available: "Online"
    payload_not_available: "Offline"
    qos: 1
    state_topic: "stat/light_lohas_6/RESULT"
    value_template: "{{ value_json.Fade }}"

  - platform: mqtt
    name: "light_avatar_small_1_fade"
    availability_topic: "tele/light_avatar_small_1/LWT"
    command_topic: "cmnd/light_avatar_small_1/FADE"
    icon: mdi:gradient
    payload_available: "Online"
    payload_not_available: "Offline"
    qos: 1
    state_topic: "stat/light_avatar_small_1/RESULT"
    value_template: "{{ value_json.Fade }}"

automation:
  - alias: Lighting · Sync Tasmota states on start-up
    initial_state: true
    trigger:
      platform: homeassistant
      event: start
    action:
      - service: mqtt.publish
        data:
          topic: "cmnd/tasmotas/STATE"
          payload: ""

  - alias: Lighting · Sync Zigbee states on start-up
    initial_state: true
    trigger:
      platform: homeassistant
      event: start
    action:
      - service: mqtt.publish
        data:
          topic: "z2m_deconz/hue_white_1/get"
          payload: ""
      - service: mqtt.publish
        data:
          topic: "z2m_deconz/hue_white_2/get"
          payload: ""
      - service: mqtt.publish
        data:
          topic: "z2m_deconz/hue_white_3/get"
          payload: ""
      - service: mqtt.publish
        data:
          topic: "z2m_deconz/hue_white_4/get"
          payload: ""
      - service: mqtt.publish
        data:
          topic: "z2m_deconz/hue_ambiance_1/get"
          payload: ""
      - service: mqtt.publish
        data:
          topic: "z2m_deconz/hue_ambiance_2/get"
          payload: ""
      - service: mqtt.publish
        data:
          topic: "z2m_deconz/hue_ambiance_3/get"
          payload: ""
      - service: mqtt.publish
        data:
          topic: "z2m_deconz/hue_ambiance_4/get"
          payload: ""
      - service: mqtt.publish
        data:
          topic: "z2m_deconz/hue_1/get"
          payload: ""
      - service: mqtt.publish
        data:
          topic: "z2m_deconz/hue_2/get"
          payload: ""
      - service: mqtt.publish
        data:
          topic: "z2m_deconz/hue_3/get"
          payload: ""
      - service: mqtt.publish
        data:
          topic: "z2m_deconz/hue_4/get"
          payload: ""
      - service: mqtt.publish
        data:
          topic: "z2m_deconz/hue_5/get"
          payload: ""
      - service: mqtt.publish
        data:
          topic: "z2m_deconz/ledvance_1/get"
          payload: ""
      - service: mqtt.publish
        data:
          topic: "z2m_deconz/neo_1/get"
          payload: ""
      - service: mqtt.publish
        data:
          topic: "z2m_deconz/neo_2/get"
          payload: ""
      - service: mqtt.publish
        data:
          topic: "z2m_deconz/light_hallway_main/get"
          payload: ""
      - service: mqtt.publish
        data:
          topic: "z2m_deconz/light_hallway_entrance/get"
          payload: ""
      - service: mqtt.publish
        data:
          topic: "z2m_deconz/light_kitchen_main/get"
          payload: ""
      - service: mqtt.publish
        data:
          topic: "z2m_deconz/light_kitchen_secondary/get"
          payload: ""
