11-17-2021, 01:12 AM
follows support turn ON/OFF lamp by click "lamp" ico in home assistant.
light:
- platform: mqtt
name: dimmer1
unique_id: dimmer1
schema: template
command_topic: "dimmer/xxxxxxxxxxxxxxxxxxxxxxxxxxxx/set"
state_topic: "dimmer/xxxxxxxxxxxxxxxxxxxxxxxxxxxx/state"
command_on_template: >
{%- if brightness is defined -%}
,{"dimmer1":{"value":{{(brightness / 255 * 100) | int - 1}}}
{%- else -%}
,'{"dimmer1":{"value":99}}'
{%- endif -%}
command_off_template: '{"dimmer1":{"value":0}}'
state_template: >
{%- if value_json.dimmer1.value == 0 -%}
off
{%- else -%}
on
{%- endif -%}
brightness_template: '{{(value_json.dimmer1.value / 99 * 255)| int}}'
light:
- platform: mqtt
name: dimmer1
unique_id: dimmer1
schema: template
command_topic: "dimmer/xxxxxxxxxxxxxxxxxxxxxxxxxxxx/set"
state_topic: "dimmer/xxxxxxxxxxxxxxxxxxxxxxxxxxxx/state"
command_on_template: >
{%- if brightness is defined -%}
,{"dimmer1":{"value":{{(brightness / 255 * 100) | int - 1}}}
{%- else -%}
,'{"dimmer1":{"value":99}}'
{%- endif -%}
command_off_template: '{"dimmer1":{"value":0}}'
state_template: >
{%- if value_json.dimmer1.value == 0 -%}
off
{%- else -%}
on
{%- endif -%}
brightness_template: '{{(value_json.dimmer1.value / 99 * 255)| int}}'