Ok, I have some plugwise switches which I run plugwise2py for, which enables MQTT control of these.
That part works fine, from the command line I get it all working, but from HA I have a challenge…
If I configure the switch like this I can switch things on and off perfectly, but the switch always toggles back to off, evne if I turn on the lamp (which works)
Please format your configuration using the instructions in the link in the big blue box at the top of the page. Without that, nobody can make sense of it.
The value_template: is used to pick out a value from the json. If your payload_on: and payload_off: contain all the json, then I think you can just omit the value_template: altogether.
You just have to make sure that the payload received always matches one of configured values exactly.
Edit:
I have just reread the second comment of your first post, and I’m not sure if the first example you posted is correct. What is the configuration that successfully sends a command?
The first one I can switch on and off, but the state does not work.
The second one I can NOT switch, but the state is correct if I switch the device from outside of home assistant
I’m not sure I understand this comment, given your examples. Does it need {'cmd": “switch”, “val”: “on”} or '{"mac": "000D6F00002369B9", "switch": "on"}' from your example?
To turn on or off the switch I need to send {“mac”:“000D6F00002369B9”,“cmd”:“switch”,“val”:“on”}.
Upon successful switching on the switch will return a full response, including the state:
One of the restrictions of an MQTT switch is the payload for the command must match the payload for the state response. The best way I have seen to get around this is to use a combination of a binary sensor and a template switch, using the mqtt_publish service. Something like this - I may have got some of the details wrong, but the principle works