Integrate mqtt light which can only send and receive brightness values in format { "value": 100 }

I’m trying to slowly migrate away from another home automation system (Zipato Zipabox) to Home Assistant.
In this other system the light is represented as a slider which I can move from the left (value 0 which is off) to the right (100 which is maximum brightness).

I managed to get the system to send MQTT messages which are in the following format;

# And off course any value in between 0 and 100.

To adjust the light a message like this needs to be sent:

{ "value": 0 }
# Where 0 turns off the light and 1-100 set a specific brightness level.

Now my attempts to try and integrate it:

Method 1 using the cover functionality:

  - platform: mqtt
    name: "Test3"
    position_topic: "/Zipabox/attributes/5aceaf68-7430-445a-90cb-a7166e17c315/value"
    set_position_topic: "/Zipabox/request/attributes/5aceaf68-7430-445a-90cb-a7166e17c315/value"
    value_template: "{{ value_json.value }}"
    position_open: 100
    position_closed: 0

Result: I get a slider in Home Assistant which indeed moves to the correct position when I manipulate the switch on the wall. However I can’t manipulate the light from HA, as it doesn’t format the light in the correct way. The message is:

Where the light expects { "value": 17 }

Another issue is obviously that Home Assistant thinks it’s a cover and not a light.

Method 2 which correctly identifies it as a light, and can sort of read the correct brightness but not set the brightness.

- platform: mqtt
name: "Test 1"
brightness_state_topic: "/Zipabox/attributes/5aceaf68-7430-445a-90cb-a7166e17c315/value"
command_topic: "/Zipabox/request/attributes/5aceaf68-7430-445a-90cb-a7166e17c315/value"
brightness_command_topic: "/Zipabox/request/attributes/5aceaf68-7430-445a-90cb-a7166e17c315/value"
brightness_scale: 100
brightness_value_template: "{{ value_json.value }}"
on_command_type: 'brightness' #Using brightness will only send brightness commands instead of the payload_on to turn the light on.

Turning on the light in HA sends the value 100 and setting the slider to 50 sends the value 50 while turning off the light sends the value OFF. These messages do not correspond to the message the light expects which is { "value": 100 }. So the light doesn’t do anything.

HA doesn’t read the values sent by the light when HA thinks the light is off. When it thinks the light is on it (because I clicked the light in HA) it does read the values, so if HA reads 100 the slider goes to the right and the animated bulb shows maximum brightness. If it reads 50 the slider goes to the middle and the bulb is less bright. If it reads zero the slider goes to the left and curiously enough the bulb shows maximum brightness.

Method 3, which can correctly set the brightness, but not read the brightness level

- platform: mqtt
name: 'Test 2' 
schema: template
command_topic: "/Zipabox/request/attributes/5aceaf68-7430-445a-90cb-a7166e17c315/value"
state_topic: "/Zipabox/attributes/5aceaf68-7430-445a-90cb-a7166e17c315/value"
state_template: '{{ value_json.value }}'
command_on_template: '{ {% if brightness is defined %}"value": {{ (brightness / 2.55)|int }} {% else %} "value": "15" {% endif %}}'
command_off_template: '{"value": "0"}' 
brightness_template: "{{ value_json.value }}"

When selecting a brightness in HA it correctly sends the brightness value to MQTT in a way the light can read it.
When clicking the light switch in HA:

  • the light turns on with brightness level 15 so physical behaviour is correct

  • however in lovelace the brightness slider does not move

  • in addition in lovelace the light switch button (which I just turned on) switches back to off after one second (in reality the lgiht remain on a level 15).

If I turn off the light in HA, the light turns off.

If I change brightness levels outside of HA, HA does not read this.

The little animated lightbulb never does anything (whether I manipulate the light physically or in Home Assistant).

So with many hours of effort (because I don’t really understand properly the code I have created), I still haven’t found a method to do something extremely simple:
integrate a light which only sends brightness values (no separate on or off commands) using the format {"value":17,"timestamp":"2020-11-14T08:00:41Z"} and which can only receive brightness values (no separate on or off) using the format { "value": 0 }

I was hoping you could help me integrate this light properly?

I got some help on another forum and managed to create the solution.
In case anyone every has a similar issue, here is the working code:

  - platform: mqtt
    name: 'nameofyourdevice'
    schema: template
    command_topic: "/xxx/request/attributes/xxx/value"
    state_topic: "/xxx/attributes/xxx/value"
    command_on_template: >
      {%- if brightness is defined -%}
      "value": {{ brightness | float | multiply(0.3922) | round(0) }}
      {% else %}
      "value": 100
      {%- endif -%}
    command_off_template: '{"value": 0}'
    state_template: '{% if value_json.value > 0 %}on{% else %}off{% endif %}'
    brightness_template: '{{ (value_json.value * 2.55) | int  }}'

tx @quizzical
this helped me indeed!
yeah … years later :stuck_out_tongue:


Lol I don’t understand anymore what I wrote at the time, but I’m happy it helped you :grin: