Not able to translate MQTT state topic values in correct HASS light state. Probably due to templating

Hi!

I can’t get HASS to properly detect if my dimmer lights are ON or OFF via MQTT.
I am pretty sure i am overlooking something really simple. I am new to MQTT, so excuse me for asking stupid questions :slight_smile:

I have just two MQTT topics:

  • /service/fhem/gw_keukenkoof/dim
  • /service/fhem/gw_keukenkoof/cmnd

Publishing any number between 1 and 100 to the /cmnd topic will switch ON my lights (value 1 being the darkest and 100 being the brightest). Publishing a 0 will switch OFF my lights.
The /dim topic just represents the actual status

I am able to set the right dim value via HASS, however I am not able to read it. Even detecting if the lights are ON or OFF is not working for me. So controlling the brightness outside (or on/off state) outside of HASS is not reflected in HASS.

Below is my yaml

light:
  - platform: mqtt
    name: "Keuken Koof Dimmer"
    state_topic: "/service/fhem/gw_keukenkoof/dim"
    state_value_template: "{{ 'OFF' if value == '0' else 'ON' }}"
    command_topic: "/service/fhem/gw_keukenkoof/cmnd"
    payload_off: "0"
    payload_on: "30"
    brightness_state_topic: "/service/fhem/gw_keukenkoof/dim"
    brightness_command_topic: "/service/fhem/gw_keukenkoof/cmnd"
    on_command_type: 'brightness'
    brightness_scale: 100

Any help in the right direction is appreciated.

Remove these two lines:

    payload_off: "0"
    payload_on: "30"

That will make the light use its default values which are OFF and ON.

Hi Taras.
Thanks for your reply.
That did a part of the trick!! Thanks. Almost there :slight_smile:
The only problem left now, is that when i turn the dimmer into its lowest position, HASS still publishes a “1”, which causes my dimmers not to go off entirely. The goal is to be able to publish a “0”.
Any idea how i can accomplish that?

Thanks,
marcel

OK, then remove state_value_template and add payload_on = 100 and payload_off = 0.

light:
  - platform: mqtt
    name: "Keuken Koof Dimmer"
    state_topic: "/service/fhem/gw_keukenkoof/dim"
    command_topic: "/service/fhem/gw_keukenkoof/cmnd"
    brightness_state_topic: "/service/fhem/gw_keukenkoof/dim"
    brightness_command_topic: "/service/fhem/gw_keukenkoof/cmnd"
    on_command_type: 'brightness'
    brightness_scale: 100
    payload_off: "0"
    payload_on: "100"

Thanks again Taras.
I fixed it differently. I defined a few additional topics and modified the Perl code on FHEM side.
Issue is resolved.

With all due respect, you have marked your post as the Solution but it reveals no details. That doesn’t help anyone else who may have a similar problem.

The community would appreciate it if you took a moment to show examples of what must be done to correct the problem.

Sure i can explain, but i am afraid it will be a little offtopic, as i solved it outside of HASS and inside of FHEM.

This is my current ligtht config (pretty standard):

  - platform: mqtt
    name: "Keukenkoof dimmer"
    state_topic: "/service/fhem/keukenkoof/state"
    command_topic: "/service/fhem/keukenkoof/cmnd"
    brightness_state_topic: "/service/fhem/keukenkoof/dim"
    brightness_command_topic: "/service/fhem/keukenkoof/dimcmnd"
    on_command_type: 'brightness'
    brightness_scale: 100
    payload_on: "on" 
    payload_off: "off"

As you can see I have 4 different topics.
One for the state_topic that takes care of on and off. The other takes care of the dimming value.
Originally, there were just two topics, taking care of both on/off and dimming value, which was causing issues in my config.

Perl code for FHEM SYS_MQTT device for on/off:

SYS_MQTT_KeukenKoof_cmnd:cmnd:.* {
    if ($EVENT =~ qr/.*?: (.*)/p) {
        my $cmnd = $1;
        Log3($NAME, 5, "executed mqtt command: " . $cmnd);
        fhem("set gw_keukenkoof ". $cmnd);
    }
}

Perl code for FHEM SYS_MQTT device for dimming:

SYS_MQTT_KeukenKoof_dimcmnd:cmnd:.* {
    if ($EVENT =~ qr/.*?: (.*)/p) {
        my $cmnd = $1;
        Log3($NAME, 5, "executed mqtt command: " . $cmnd);
        fhem("set gw_keukenkoof dim ". $cmnd);
    }
}

Hi,
i need a support on Mqtt Dimmer light which is having like single topic and different payloads for brightness.

topic=200
payload_off: C,6,0------>light=0ff
Payload_brightness-1: C,6,1----->light=10%
Payload_brightness-2: C,6,2----->light=25%
Payload_brightness-3: C,6,3----->light=35%
Payload_brightness-4: C,6,4----->light=50%
.
.
Payload_brightness-8: C,6,8----->light=100%

is it possible to create a single entity for this type of lights?

note: here Topic = 200 and payload format is:C,5,0 C,5,1…C,5,8