Replace data in an MQTT Payload (DALI light)


I have a DALI light connected via the Mosquitto MQTT Broker.
I created a light entity in HA and would like to sync the state of the DALI Device (ON/OFF & Brightness) to this entity whenever it changes.

I configured a topic on the DALI Controller side that periodically publishes the status of the light and the brightness. The Payload is:
{"state": <light status>, "brightness": <light brightness>}

The brighness is updated fine in the entity but the on/off is not because the DALI controller uses 4 for “ON” and 0 for “OFF”.
I need a way to replace 4 with “ON” and 0 with “OFF” and the DALI Controller (ADF HD67941) does not seem to have that ability.

Does anyone have any suggestion?

Thank you.

How do you define the light in HA?
If you do it yourself, rather than through discovery, it’s pretty trivial to have it working in HA without “replacing data” in MQTT

Hi Chris,

This is how I defined the light:
{"~": "homeassistant/light/smarli_dali_44", "name": "Light 1", "unique_id": "smarli_dali_44", "cmd_t": "~/set", "stat_t": "~/state", "schema": "json", "brightness": true}

Ok, so that’s a discovery topic.
I’m pretty sure you can also use templates in discovery, but I have not practical examples.

what would have been your suggestion If I would define the light myself?

Using payload_on/ payload_off to redefines the states meaning

Actually, the same is likely doable in the discovery topic…


Thank you. That looks very promising. I will try it tonoght.
Can you send me the source of that screenshot?

Ok thanks for the help. Got it working.
Now I have a different problem. I tried to define a brightness_command_template.

    - light:
        name: "Manual DALI Light"
        unique_id: "samrli44"
        state_topic: "DALI/light/status"
        command_topic: "DALI/light/switch"
        brightness_state_topic: 'DALI/light/brightness'
        brightness_command_topic: 'DALI/light/brightness/set'
        brightness_command_template: '{"channel":44,"value": {{ value_json.brightness }}}'
        qos: 0
        payload_on: '4'
        payload_off: '0'
        optimistic: false

but when I change the brightness in the HASS Front end I get the following error:
Failed to call service light/turn_on. UndefinedError: 'value_json' is undefined

Any idea?

No help needed: this is the correct definition:
brightness_command_template: '{"channel":44,"value": {{ value }}}'