MQTT Light/Templating Help

Ok, i’m really close but I feel like i’m taking one step forward and two steps back.

Here is the current config:

  - platform: mqtt
    schema: template
    name: Office Level
    command_topic: "homeassistant/light/office_level/set"
    state_topic: "homeassistant/light/office_level/state"
    command_on_template: >
      {"state": "on"
      {%- if brightness is defined -%}
      , "brightness": "{{ brightness }}"
      {%- endif -%}
      {%- if transition is defined -%}
      , "transition": "{{ transition }}"
      {%- endif -%}
      }
    command_off_template: >
      {"state": "off"
      {%- if transition is defined -%}
      , "transition": "{{ transition }}"
      {%- endif -%}
      }
    state_template: "{{ value }}"
    brightness_template:  "{{ value }}"

i KNOW that brightness part is wrong but here’s what’s messed up. I can control the light just fine. Switch it on/off, dim it, everything. It just throws an error of “Invalid brightness value received”. Which is annoying and i want to fix. The state part works 100% fine.

EDIT: I think i see the problem, and I don’t know the solution. The problem is for “brightness_template” it’s trying to find the value in /homeassistant/light/office/state. But the issue is, it’s not there. The value is in /homeassistant/light/office/brightness. But I can’t define brightness_command_topic like I can with the other variants of MQTT Light. So I think i’m stuck either 1) not having transitions and using the “default” light or 2) having transitions/brightness/what I want using the “template” light but getting spammed with errors all the time about how the brightness value isn’t correct. Sigh, damned if I do damned if I don’t.

What is the appearance and content of the data that is published to this topic? For example, does it contain sufficient information to determine the light’s state?

For example, let’s assume the payload is 0 when the light is turned off and an integer value greater than 0 when on. With this information we can create an appropriate state_template that would allow us to use this topic:

homeassistant/light/office_level/brightness

for the state_topic, instead of this one:

homeassistant/light/office_level/state

Therefore the brightness_template would be processing payloads from the brightness-related topic instead of the state-related topic … thereby eliminating the error messages.

Not going to work. The brightness does not get updated when the light gets turned off. IE this is the current output (notice the state is OFF but the brightness value is still 255)

office_level
state = on
last_updated = 2019-07-17T01:15:55.394507+00:00
last_changed = 2019-07-17T01:15:55.394507+00:00
node_id = 50
value_index = 0
value_instance = 1
value_id = "72057594881605633"
friendly_name = "Office"
supported_features = 33
brightness = 255

I think I’m going to take a different path. I realized only a few automations call things involving transitions, and I can move those to scenes. Move the scenes to the zwave instance and invoke them with an MQTT topic/payload. Reverted the MQTT lights to the “default” config and i can turn on/off and control brightness with no errors. I sincerely appreciate all your help though!

Your example shows the state is on.

Screenshot:

Screenshot%20from%202019-07-16%2022-47-34

Yeah sorry. Was tired and lazy and was going to wait it to show how it was when the light was off. But I can confirm the brightness value does not go to 0 when the light goes off.