I have a zwave dimmer that connects to HA via mqtt and I want make a switch that follows the brightness topic to switch to on at any brightness and to off at 0 brightness.
This works to turn the light on and off, but I am not getting the second desired effect. If turn the light on at the physical switch to a brightness greater than 0, I want the mqtt switch to change to ON.
Its giving me this error:
Invalid config for [light.mqtt]: required key not provided @ data[‘command_topic’]. Got None. (See ?, line ?). Please check the docs at https://home-assistant.io/components/light.mqtt/
Doesn’t work and isn’t able to turn the light on or off when “Test Light” switch is toggled and its default state is on.
Interesting enough, on the states page for your light, it shows a brightness attribute that follows the changes when I turn the light on/off from the physical switch.
I recommend you use an MQTT client, such as MQTT Explorer, to observe what Home Assistant publishes to zwave2mqtt/2/38/1/0/set when you turn the MQTT Light on and off.This information is needed otherwise it becomes very difficult for me to diagnose this further
When providing someone with assistance, you have to assume everything they tell you and everything they share with you is a fact. For example, in the first example you provided, you used string values for payload_on and payload_off:
payload_on: "99"
payload_off: "0"
So all of my examples use string values. However, in your latest example, the one you claim that works, (which is almost identical to the one that I proposed) it uses integer values:
payload_off: 0
payload_on: 99
I’m no longer certain what is fact and what is fiction. For example, you stated this:
The message published to zwave2mqtt/2/38/1/0 is 0 when the switch is toggled.
What do you mean when you say ‘switch is toggled’? Did you flip the switch off/on/off? Did you simply turn it off? Saying it is 0 when ‘toggled’ isn’t at all clear to me. Please elaborate.
If the values are integers, and 0 is off and 99 is on, then this should minimally be able to turn the light on and off and display the light’s state:
Sorry for the confusion, I just tested the payload_on and payload_off as an integer and string in the last example I posted that worked and both ways it functions the same.
The “test light” switch defaults to on with the light off.
Switching “test light” off, the switch goes back to the on position by it self, and the light stays off.
If I switch “test light” off and switch back on before it does it self, the light turns on, and the switch says in the on position.
With the light on and the switch in the on position, switching “test light” off, the switch goes back to the on position by it self, and the light stays off.
The results you’ve provided indicate the messaging is not as simple as 0=off and 99=on. If it was, then the configuration you tested would work, yet it does not.
The “test light” switch defaults to on with the light off.
This is a problem. Because it is on it means:
It received a payload from zwave2mqtt/2/38/1/0
The payload was processed by state_value_template
The template determined the payload’s value is non-zero so it reported 99 which corresponds to payload_on.
Why does zwave2mqtt/2/38/1/0 contain a non-zero value when the actual light is `off``?
You need to use an MQTT client to subscribe to this topic and confirm what value it contains.
Switching “test light” off, the switch goes back to the on position by it self, and the light stays off.
Immediately returning to its previous state means “I sent the command to turn off but did not receive the expected response from the device so I am putting myself back to my previous state”.
It means it sent 0 but never received a reply containing 0.
For the next two steps, where you had some success turning the actual light on/off, implies “test light” was sending payloads that were understood by the actual light. However, the test light always had trouble with displaying the actual light’s status. This corresponds to the very first problem where the test light defaults to on, namely it has trouble getting the light’s correct status.
Here is what I would do:
Remove (or comment out) the ‘Test Light’ configuration from Home Assistant. Restart Home Assistant.
Turn off the light.
Connect MQTT Explorer to the MQTT broker.
Look at the payload in zwave2mqtt/2/38/1/0. It should be 0.
Turn on the light.
zwave2mqtt/2/38/1/0 should now contain 99.
Use MQTT Explorer to publish 0 to zwave2mqtt/2/38/1/0/set.
The light should turn off.
Look at the payload in zwave2mqtt/2/38/1/0. It should be 0.
Use MQTT Explorer to publish 99 to zwave2mqtt/2/38/1/0/set.
The light should turn on.
zwave2mqtt/2/38/1/0 should now contain 99.
If your test results don’t match what I’ve listed above, then the light’s behavior is not the way it was initially described.