I migrated over to this today now that it supports MQTT authentication (PR exists but hasn’t been merged yet).
All of my lights and switches work perfectly but as expected my front door lock does not. But as this is using MQTT I went about trying to use an MQTT Lock. I managed to get it working successfully.
First you need to find the command class you want to trigger. I used mosquitto_sub to look through the data at OpenZWave/# and found the following.
OpenZWave/1/node/2/instance/1/commandclass/98/value/39354384/ {
"Label": "Locked",
"Value": true,
"Units": "",
"Min": 0,
"Max": 0,
"Type": "Bool",
"Instance": 1,
"CommandClass": "COMMAND_CLASS_DOOR_LOCK",
"Index": 0,
"Node": 2,
"Genre": "User",
"Help": "State of the Lock",
"ValueIDKey": 39354384,
"ReadOnly": false,
"WriteOnly": false,
"ValueSet": false,
"ValuePolled": false,
"ChangeVerified": false,
"Event": "valueAdded",
"TimeStamp": 1583006263
}
The two important parts required here are the ValueIDKey and Value. ValueIDKey is the command ID we need to trigger and Value is the current state of the lock. True in this case shows it is currently locked.
To test unlock the door I used mosquitto_pub to send a command to change the locked value to false. Unlocking the door.
mosquitto_pub -h localhost -p 1883 -t "OpenZWave/1/command/setvalue/" -m '{"ValueIDKey": 39354384, "Value": false}'
To re-lock the door the command can be changes to “Value”:true.
Now that works it is just a matter of constructing an MQTT Lock within the HA configuration. We know the lock and unlock commands as well as where in the json the current state is. As well as the state is either true or false for locked and unlocked.
lock:
- platform: mqtt
name: Front Door
command_topic: "OpenZWave/1/command/setvalue/"
payload_lock: '{"ValueIDKey": 39354384, "Value": true}'
payload_unlock: '{"ValueIDKey": 39354384, "Value": false}'
state_topic: 'OpenZWave/1/node/2/instance/1/commandclass/98/value/39354384/'
value_template: '{{value_json.Value}}'
state_locked: true
state_unlocked: false
Hopefully this will help someone construct unsupported devices using MQTT directly.