Facing issue while changing brightness of light using mqtt

I’m using Osram Dali Pro 2 IOT controller to control lights at my office. I also have a few lights/sensors running on ewelink that I’ve setup on HA. What I want to do is get all the controls on HA and the controller I’m using supports mqtt.
I successfully setup the connection and I’m able to turn on/off lights on my dali controller through HA dashboard, but I’m facing 2 issues, I’m not getting the status of lights updated on HA dashboard and I’m not able to control the brightness level of my lights. Below is code from my configuration file for my conference room.

    - name: "Conference Room"
      unique_id: "cr"
      command_topic: "DALI-PRO-IoT/DALIPRO2-860003FA/groups/1/target/level"
      state_topic: "DALI-PRO-IoT/DALIPRO2-860003FA/groups/1/state/level"
      state_value_template: "{{ value_json.level }}"
      brightness_command_topic: "DALI-PRO-IoT/DALIPRO2-860003FA/groups/1/target/level"
      brightness_state_topic: "DALI-PRO-IoT/DALIPRO2-860003FA/groups/1/state/level"
      brightness_scale: 100
      payload_on: '{"value": 100}'
      payload_off: '{"value": 0}'
      optimistic: true
      qos: 0
      retain: true

I’ve tried everything I could but I’m not able to figure out answers to both of these. During my debugging process I found out that the payload that is being sent when I turn on/off my lights is what my dali controller expects, but when I change the brightness level it is not.
This is how the payload is expected to be, and it works fine with on/off.

DALI-PRO-IoT/DALIPRO2-860003FA/groups/3/target/level
{
    "value": 100
}

But, when I try to alter brightness using HA dashboard, this is what I receive on mqtt.

Message 10 received on DALI-PRO-IoT/DALIPRO2-860003FA/groups/3/target/level at 9:01 PM:
{
    "value": 100
}
Message 9 received on DALI-PRO-IoT/DALIPRO2-860003FA/groups/3/target/level at 9:01 PM:

51

For some reason, I’m receiving 2 messages even though I just turned the slider to 51%. Any help I could get on this would be appreciated.
P.S. I’m new to HA.

you’ll need a brightness_value_template to get the values of the lights.

your state_value_template is also wrong. It should be {{ value }}

This should work out of the box too.

    - name: "Conference Room"
      unique_id: "cr"
      command_topic: "DALI-PRO-IoT/DALIPRO2-860003FA/groups/1/target/level"
      state_topic: "DALI-PRO-IoT/DALIPRO2-860003FA/groups/1/state/level"
      state_value_template: "{{ value_json.value }}"
      brightness_value_template: "{{ value_json.value }}"
      brightness_command_topic: "DALI-PRO-IoT/DALIPRO2-860003FA/groups/1/target/level"
      brightness_state_topic: "DALI-PRO-IoT/DALIPRO2-860003FA/groups/1/state/level"
      brightness_scale: 100
      payload_on: 100
      payload_off: 0
      optimistic: true
      qos: 0
      retain: true

Hi, ty so much for the reply.

I tried your code, the lights didn’t dim, state didn’t get updated moreover the lights have also stopped turning on and off. I think the controller isn’t understanding just the value and is also expecting the full format.
Another thing is that I’m still getting 2 messages on MQTT when I try to set brightness level, one being the level I’m trying to set and other one being 100.

Message 12 received on DALI-PRO-IoT/DALIPRO2-860003FA/groups/1/target/level at 3:22 PM:

100

QoS: 0 - Retain: false

Message 11 received on DALI-PRO-IoT/DALIPRO2-860003FA/groups/1/target/level at 3:22 PM:

59

QoS: 0 - Retain: false

I think what you are seeing on mqtt is the messages you are sending as they seem to match exactly your format as it changes. It looks like your lights are expecting a json value like this (esp as it stopped working when you changed payload on/off. As such, you prob need this config.

- name: "Conference Room"
      unique_id: "cr"
      command_topic: "DALI-PRO-IoT/DALIPRO2-860003FA/groups/1/target/level"
      state_topic: "DALI-PRO-IoT/DALIPRO2-860003FA/groups/1/state/level"
      state_value_template: "{{ value_json.level }}"
      brightness_command_topic: "DALI-PRO-IoT/DALIPRO2-860003FA/groups/1/target/level"
      brightness_command_template: '{"value": {{ value }} }'
      brightness_state_topic: "DALI-PRO-IoT/DALIPRO2-860003FA/groups/1/state/level"
      brightness_scale: 100
      on_command_type: brightness
      optimistic: true
      qos: 0
      retain: true

It is not clear if you are getting any response, so i wonder if this is on a different topic. As such, not sure how you see current state.

Edit: to explain the 2 messages you are seeing, default is to send the on command followed by the setting. You would need to set the below to brightness also.

on_command_type string (optional)

Defines when on the payload_on is sent. Using last (the default) will send any style (brightness, color, etc) topics first and then a payload_on to the command_topic. Using first will send the payload_on and then any style topics. Using brightness will only send brightness commands instead of the payload_on to turn the light on.

The payload needs to match the value returned from the state_value_template, it should work. I have no idea how your version is working when you have no level attribute, yet that’s how you’re pulling the state. Please share the contents of your DALI-PRO-IoT/DALIPRO2-860003FA/groups/1/state/level topic.

The state is now getting updated, for some reason when I tested it in afternoon it wasn’t but now state is getting updated. Though it is not updating the state when home assistant is restarted but I think I can figure that one out.

This method solved the problem of brightness, but now the switch on/off buttons are not working. Also, the state is now getting updated.
This is the current code I’m using -

   - name: "Conference Room"
      unique_id: "cr"
      command_topic: "DALI-PRO-IoT/DALIPRO2-860003FA/groups/1/target/level"
      state_topic: "DALI-PRO-IoT/DALIPRO2-860003FA/groups/1/state/level"
      state_value_template: "{{ value_json.value }}"
      brightness_command_topic: "DALI-PRO-IoT/DALIPRO2-860003FA/groups/1/target/level"
      brightness_command_template: '{"value": {{ value }} }'
      brightness_state_topic: "DALI-PRO-IoT/DALIPRO2-860003FA/groups/1/state/level"
      brightness_scale: 100
      on_command_type: brightness
      optimistic: true
      qos: 0
      retain: true

Please post the contents of this topic DALI-PRO-IoT/DALIPRO2-860003FA/groups/1/state/level. We can’t help create the templates needed for on/off without it. Same for the slider in the UI, which won’t work for you.

I’m not sure why you glossed over my request for this information before.

Sorry, I missed that part. I’m assuming by contents you mean the payload that has to be sent to the controller. Here are the details I got from Osram.

Can you please take as screenshot of the actual topic contents using MQTT explorer or some other software?

This is the content that I got on changing state using DALI mobile app.

Then this should work.

    - name: "Conference Room"
      unique_id: "cr"
      command_topic: "DALI-PRO-IoT/DALIPRO2-860003FA/groups/1/target/level"
      state_topic: "DALI-PRO-IoT/DALIPRO2-860003FA/groups/1/state/level"
      state_value_template: "{{ value_json.value }}"
      brightness_value_template: "{{ value_json.value }}"
      brightness_command_template: '{"value": {{ value }} }'
      brightness_command_topic: "DALI-PRO-IoT/DALIPRO2-860003FA/groups/1/target/level"
      brightness_state_topic: "DALI-PRO-IoT/DALIPRO2-860003FA/groups/1/state/level"
      brightness_scale: 100
      payload_on: 100
      payload_off: 0
      qos: 0
      retain: true

The payload_on and payload_off need to match the output of your state_value_template

Ok, obviously you have to send 100 or 0 for on and off before sending the brightness level. As such, @petro answer in nearly right. As it worked when you had a json value in payload on/off, go back to that. Therefore:

- name: "Conference Room"
      unique_id: "cr"
      command_topic: "DALI-PRO-IoT/DALIPRO2-860003FA/groups/1/target/level"
      state_topic: "DALI-PRO-IoT/DALIPRO2-860003FA/groups/1/state/level"
      state_value_template: "{{ value_json.value }}"
      brightness_value_template: "{{ value_json.value }}"
      brightness_command_template: '{"value": {{ value }} }'
      brightness_command_topic: "DALI-PRO-IoT/DALIPRO2-860003FA/groups/1/target/level"
      brightness_state_topic: "DALI-PRO-IoT/DALIPRO2-860003FA/groups/1/state/level"
      brightness_scale: 100
      payload_on: '{"value": 100}'
      payload_off: '{"value": 0}' 
      qos: 0
      retain: true

No, that’s not how it works. Please pay attention to the verbiage in the documentation.

The state value template is outputting values between 0 and 100 only defined by the template itself. Therefore the payload on and payload off values need to match what the template outputs, not the full json.


This will most likely work the best without modifying payload_on or off so that any value above 0 shows the light being on.

    - name: "Conference Room"
      unique_id: "cr"
      command_topic: "DALI-PRO-IoT/DALIPRO2-860003FA/groups/1/target/level"
      state_topic: "DALI-PRO-IoT/DALIPRO2-860003FA/groups/1/state/level"
      state_value_template: "{{ 'ON' if value_json.value > 0 else 'OFF' }}"
      brightness_value_template: "{{ value_json.value }}"
      brightness_command_template: '{"value": {{ value }} }'
      brightness_command_topic: "DALI-PRO-IoT/DALIPRO2-860003FA/groups/1/target/level"
      brightness_state_topic: "DALI-PRO-IoT/DALIPRO2-860003FA/groups/1/state/level"
      brightness_scale: 100
      qos: 0
      retain: true

Ok, but it is clear from the discussion that sending a payload of 100, instead of {"value": 100} is not working.

The OP originally had payload_on: {"value": 100}, payload_off: {"value": 0} and this worked to turn it on/off. You keep saying set it to just payload: 100 and it does not work.

How is your example sending the correct message. What am I missing?

payload_on & payload_off are matched against the state_value_template.

If they are being sent when turning on, he’s not using the correct configuration.

that would be…

    - name: "Conference Room"
      unique_id: "cr"
      command_topic: "DALI-PRO-IoT/DALIPRO2-860003FA/groups/1/target/level"
      state_topic: "DALI-PRO-IoT/DALIPRO2-860003FA/groups/1/state/level"
      state_value_template: >
        {{ 'ON' if value_json.value > 0 else '{"value": 0}' }}
      brightness_value_template: "{{ value_json.value }}"
      brightness_command_template: '{"value": {{ value }} }'
      brightness_command_topic: "DALI-PRO-IoT/DALIPRO2-860003FA/groups/1/target/level"
      brightness_state_topic: "DALI-PRO-IoT/DALIPRO2-860003FA/groups/1/state/level"
      brightness_scale: 100
      on_command_type: brightness
      off_payload: '{"value": 0}'
      qos: 0
      retain: true

I tried the alterations that you suggested and here’s the update.


    - name: "Conference Room"
      unique_id: "cr"
      command_topic: "DALI-PRO-IoT/DALIPRO2-860003FA/groups/1/target/level"
      state_topic: "DALI-PRO-IoT/DALIPRO2-860003FA/groups/1/state/level"
      state_value_template: "{{ 'ON' if value_json.value > 0 else 'OFF' }}"
      brightness_value_template: "{{ value_json.value }}"
      brightness_command_template: '{"value": {{ value }} }'
      brightness_command_topic: "DALI-PRO-IoT/DALIPRO2-860003FA/groups/1/target/level"
      brightness_state_topic: "DALI-PRO-IoT/DALIPRO2-860003FA/groups/1/state/level"
      brightness_scale: 100
      qos: 0
      retain: true

When I use this code, I’m able to get brightness working but the light on/off is not working. Brightness status is working, on/off status is also getting updated perfectly when I change using dali mobile app.

    - name: "Conference Room"
      unique_id: "cr"
      command_topic: "DALI-PRO-IoT/DALIPRO2-860003FA/groups/1/target/level"
      state_topic: "DALI-PRO-IoT/DALIPRO2-860003FA/groups/1/state/level"
      state_value_template: "{{ 'ON' if value_json.value > 0 else 'OFF' }}"
      brightness_value_template: "{{ value_json.value }}"
      brightness_command_template: '{"value": {{ value }} }'
      brightness_command_topic: "DALI-PRO-IoT/DALIPRO2-860003FA/groups/1/target/level"
      brightness_state_topic: "DALI-PRO-IoT/DALIPRO2-860003FA/groups/1/state/level"
      brightness_scale: 100
      on_command_type: brightness
      payload_off: '{"value": 0}'
      qos: 0
      retain: true

When I use this code, I’m able to get brightness working and light off is also working, light on is not. Brightness status is updating, on/off status is not updating when I turn off the light using the HA dashboard or the mobile app.

Another issue that I’m facing is that the status is not getting updated when I restart the home assistant, so I’m not able to control anything using dashboard unless I change it using app first, which updates that status. This is how the dashboard looks on restart -


3 lights that are on are running on a different system.

You don’t use what I pasted.

See this

Edit and you may have to completely omit the state template when using brightness on command type.

And worse case scenario is to make a template light that handles this logic using mqtt.publish service