Mqtt dimming

I’m trying to get dimming to work for an mqtt light. All that’s needed for dim/brightness is a number between 0-99 with 0 off and 99 100%. I have off and on working but can’t get any other brightness to work. How to I configure HA to do this? I’m sure this is brightness_value_template related but just can’t crack this.

Here’s an example of my configuration.

  - platform: mqtt
    name: "Family Room Hall Light"
    payload_on: 99
    payload_off: 0
    unique_id: "FamulyRoomallLight"
    brightness_scale: "99"
    brightness_state_topic: homeseer/Family_Room/Light/Family_Room_Hallway
    brightness_command_topic: homeseer/Family_Room/Light/Family_Room_Hallway/Control
    state_topic: homeseer/Family_Room/Light/Family_Room_Hallway
    command_topic: homeseer/Family_Room/Light/Family_Room_Hallway/Control
    optimistic: false
    retain: true

Once again, what MQTT messages are being sent, and what need to be sent to get your light to work?

Apologies I thought I was clear. Looking for HA to send a value between 0-99 which represents off to on in percentage. It seems on further testing HA is indeed sending a dimmer value for my configuration. When I dim my kitchen light to 52% sure enough mqtt reflects the correct value. However 1 second later I seem to get a 99 sent over mqtt. If I use node-red to send a dimmer value, this works perfectly. Seems HA is sending “99” for “on” right after it sends the dimmer value.

2/3/2019, 8:01:51 AM[node: fb16fb8b.1fbcd8]( : msg.payload : string[2]


2/3/2019, 8:01:52 AM[node: fb16fb8b.1fbcd8]( : msg.payload : string[2]


My light configuration:

  - platform: mqtt
    name: "Living Room Lights"
    payload_on: "99"
    payload_off: "0"
    unique_id: "LivingRoomMainLights"
    brightness_scale: "99"
    brightness_state_topic: homeseer/Living_Room/Dimmer/Living_Room_Light
    brightness_command_topic: homeseer/Living_Room/Dimmer/Living_Room_Light/Control
    state_topic: homeseer/Living_Room/Dimmer/Living_Room_Light
    command_topic: homeseer/Living_Room/Dimmer/Living_Room_Light/Control
    optimistic: false
    retain: true

Figured it out.

on_command_type: brightness

1 Like


In this scenario, avoid using retain: true because it will make the MQTT Broker retain a command topic. That’s often a source of unexpected consequences when the target device reboots.

However, Homeseer should publish the light’s state with retain=true. When Home Assistant reboots and re-subscribes to the light’s state_topic, it will receive the light’s current state.

General Rule of Thumb:

  • Controller of a device shouldn’t publish commands with retain=true.
  • Devices publish their status with retain=true.