I have a light entity defined in MQTT:
- light:
name: "Occhio Light Desk Left"
unique_id: "occhio_light_desk_left"
# ===== STATE =====
state_topic: "casambi/0/get/poll_device/6/values"
state_value_template: >
{% set lvl = value_json.level | int(0) %}
{% set last = value_json.last_level | default(0) | int %}
{{ 'ON' if (lvl > 0 or last > 0) else 'OFF' }}
#{{ 'ON' if (value_json.level | int(0)) > 0 else 'OFF' }}
brightness_state_topic: "casambi/0/get/poll_device/6/values"
brightness_value_template: >
{{ value_json.level | default(0) | int(0) }}
color_temp_state_topic: "casambi/0/get/poll_device/6/values"
color_temp_value_template: >
{{ ((1 - ((value_json.cct_level | default(0)) | int(0) / 254)) * (500-153) + 153) | round(0) }}
json_attributes_topic: "casambi/0/get/poll_device/6/values"
# ===== COMMAND =====
command_topic: "casambi/0/set/target_level"
brightness_command_topic: "casambi/0/set/target_level"
color_temp_command_topic: "casambi/0/set/target_tc"
# 🔆 Helligkeit setzen
brightness_command_template: >
{{
{
"level": value | int(0),
"targetid": 6,
"targettype": 1
} | tojson
}}
# 🌡️ Farbtemperatur setzen
color_temp_command_template: >
{% set mired = (value | int) %}
{% set m = [500, [153, mired]|max]|min %}
{% set cct = (((500 - m) / (500 - 153)) * 254) | round(0) %}
{% set level = state_attr('light.occhio_light_desk_left', 'brightness') | int(254) %}
{{
{
"level": level,
"tc": cct | int,
"targetid": 6,
"targettype": 1
} | tojson
}}
# 🔴 EIN/AUS über kompletten Payload
#command_topic: "casambi/0/set/target_level"
on_command_type: "brightness"
payload_off: '{"targetid": 6, "level": 0, "targettype": 1}'
brightness_scale: 254
qos: 1
optimistic: false
device:
name: "Casambi Gateway 0"
identifiers: ["casambi_Gateway_0"]
manufacturer: "Lithernet"
model: "Casambi MQTT Gateway"
sw_version: "4.56"
But it makes problems because the state of the entity will not switch off. That’s because of the payload_off definition. If I switch the luminaire OFF the payload_off command is send. An answer is send back so the level is set to 0. Because brightness will not be set to 0 (seems to be a function in home assistant) the brightness still have the last value. And it’s fixed inside homeasisstant that brightness > 0 the state of the entity is set to ON.
If I delete the payload_off definition the state is set correctly. But then other defined lights are switched off also because a broadcast is send to MQTT.
Does anyone have a solution for this problem?
Thanks a lot
Stefan