Light.turn_off does not work, but light.turn_on does

Here is the config of light.dimmer_44:

- platform: mqtt
  name: "dimmer_44"
  state_topic: "stat/dimmer_44/POWER"
  command_topic: "dimmer_44/POWER"
# command_topic: "dimmer_44/switch"
  
#  availability_topic: "dimmer_44/LWT"
  brightness_state_topic: "stat/dimmer_44/RESULT"
  brightness_command_topic: "cmnd/dimmer_44/Dimmer"
  brightness_scale: 100
  brightness_value_template: "{{ value_json.Dimmer }}"
  qos: 1
  payload_on: "ON"
  payload_off: "OFF"
  payload_available: "Online"
  payload_not_available: "Offline"
  optimistic: true
  retain: false   

You have provided topics for state, command, and brightness and then also added optimistic: true. Why?

Usually you only employ optimistic: true when the device does not report its state.

The truthful answer is, I use optimistic: true… because that is what I have done in the past with dimmers that are working correctly. I will switch it to false, and see what happens.
Thanks.

Post an example of the payload received by these two topics:

stat/dimmer_44/POWER
stat/dimmer_44/RESULT
  • I assume the first topic’s payload is either ON or OFF.
  • The second topic’s payload is probably JSON data, something like: {"Dimmer": 50}

In addition, what kind of payload does the device expect to receive via this topic?

cmnd/dimmer_44/Dimmer

If I want to set the device to a brightness level of 50, does the device expect to simply receive 50 or something in JSON format?

I’m not sure how to easily answer your request on payload. I can tell you that this config, used on the exact type dimmer, works perfectly:

 platform: mqtt
  name: "OutsideEntry_71"
  state_topic: "stat/OutsideEntry_71/POWER"
  command_topic: "cmnd/OutsideEntry_71/POWER"
  availability_topic: "tele/OutsideEntry_71/LWT"
  brightness_state_topic: "stat/OutsideEntry_71/RESULT"
  brightness_command_topic: "cmnd/OutsideEntry_71/Dimmer"
  brightness_scale: 100
  brightness_value_template: "{{ value_json.Dimmer }}"
  qos: 1
  payload_on: "ON"
  payload_off: "OFF"
  payload_available: "Online"
  payload_not_available: "Offline"
  optimistic: true
  retain: false 

- id: Dimmer_On9
  alias: "Master Entry Chandlier off at Sunset + 2 hrs"
  trigger:  
    - platform: sun
      event: sunset
      offset: "+02:00:00"
  action:
   - service: light.turn_off  
     entity_id: light.OutsideEntry_71

I can further say that the dimmer that is not working correctly:

  1. UI publishes to the dimmer just fine light.turn_on (as i see it in my mqtt explorer)
  2. UI publishes nothing which uses light.turn_off

Thanks for you help an patients.

This is what the dimmer received when executing a light.turn_on:

stat/dimmer_44/RESULT = {“POWER”:“ON”,“Dimmer”:100}

When executing anything with light.turn_off, nothing is published

Command topic 1 is dimmer_44/POWER
Command topic 2 is cmnd/OutsideEntry_71/POWER

Yes. The second example is another automation that is working correctly. I just posted it to show that the coding does work. But… doesn’t seem to work on the automation for dimmer_44

When I slam the dimmer slider in the UI, this is published to dimmer_44:

stat/dimmer_44/POWER = OFF (retained)
stat/dimmer_44/RESULT = {“POWER”:“OFF”,“Dimmer”:0}

And the dimmer properly turns off. BUT the toggle publishes nothing, along with the animation.

I think I see what you are pointing out about the 2 different. I will make the change and report back

THAT WORKED!.. I worked on this thing for two days. I must have been yaml blind. I want to thank you very much for your help… everyone, but especially Francis. I owe you an ice cream cone.

Here is the conf with the correction:

- platform: mqtt
  name: "dimmer_44"
  state_topic: "stat/dimmer_44/POWER"
  command_topic: "cmnd/dimmer_44/POWER"
# command_topic: "dimmer_44/switch"
  
#  availability_topic: "dimmer_44/LWT"
  brightness_state_topic: "stat/dimmer_44/RESULT"
  brightness_command_topic: "cmnd/dimmer_44/Dimmer"
  brightness_scale: 100
  brightness_value_template: "{{ value_json.Dimmer }}"
  qos: 1
  payload_on: "ON"
  payload_off: "OFF"
  payload_available: "Online"
  payload_not_available: "Offline"
  optimistic: false
  retain: false   

In that case, you have the option of using the same topic to receive both the device’s state and brightness.

- platform: mqtt
  name: "dimmer_44"
  state_topic: "stat/dimmer_44/RESULT"
  state_value_template: "{{ value_json.POWER }}"
  command_topic: "cmnd/dimmer_44/POWER"
  brightness_state_topic: "stat/dimmer_44/RESULT"
  brightness_value_template: "{{ value_json.Dimmer }}"
  brightness_command_topic: "cmnd/dimmer_44/Dimmer"
  brightness_scale: 100
  payload_available: "Online"
  payload_not_available: "Offline"
  qos: 1

Or use two separate topics as you’re currently doing.


Separate question for you: What kind of device is dimmer_44?

It is a Martin Jerry flashed with Tasomta_8.1.0.1(DigIDIMv9).bin

If it’s Tasmota, why not just use MQTT Discovery? It avoids having to configure each device manually (and potentially make typing errors).

Tasmota: Home Assistant Automatic Discovery

Home Assistant has a feature called MQTT discovery. With MQTT discovery no user interaction or configuration file editing is needed to add new devices in Home Assistant.

I have been using the old fashion yaml entries for quite a while. Got use to it as my house went from a switch or two… to about 25 different lights/dimmers etc. But, HA has changed a lot in the last year. I have not really kept up. When I do an HA update, I always am as nervous has hell that something is going to break, and it always does.

Basically, I guess, HA is evolving faster the me!