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.
Good, that helps to confirm its operation. Let’s forget everything that’s been attempted so far and return to the basics with a simple MQTT Switch (not an MQTT Light).
It should work perfectly because it is simplicity itself: 0=off and 99=on. By default, MQTT Switch assumes the reported states are equivalent to payload_on and payload_off so there’s no need to specify state_on and state_off.
If it fails to work (you may try ‘99’ and ‘0’ … but you said both string and integer work), then I suspect there are deeper problems in your system.
What happens if you turn off the zwave dimmer and then turn it on but only to 50 percent? Theoretically, the MQTT Switch should fail to indicate the light is on because it will receive 50 instead of 99.
If the MQTT Switch receives a value greater than 0 the template will covert it to 99. This permits the MQTT Switch to report its status as on for any value > 0.
I’m very interested to learn if this template works like I just explained or will cause the switch to indicate on by default.
Its back to previous behavior of defaulting to on, switching back to on after trying to the mqtt switch off. If I switch the mqtt switch to off and back on quickly, only then does the light turn on.
It’s exactly the same as what I proposed earlier but with one very important correction to the template. The previous version’s template was incorrect because it compared a string to an integer.
Now I would appreciate it if you could mark my post as ‘Solution’ to make it easier for other users to find it (this thread has grown to over 32 posts in length). Only you, the author, can mark a post as ‘Solution’. It will automatically place a link to the Solution under your first post in this thread.
Great post! I had exactly the same issue and was able to identify where I was going wrong.
What in the end was wrong in my configuration file is that I had the string values that were send for the state changes wrong. I used ‘0’ and ’ 100’, while I should have used ’ 0.00’ and ‘100.00’.
I have been looking for a few weeks to find a good step-by-step guide on how to identify errors. This post helped me a great deal understanding how mqtt/home assistant works…
Thanks a lot!