Improve MQTT switch example (#28495)

* Improve MQTT switch example

* Tiny tweaks

---------

Co-authored-by: c0ffeeca7 <38767475+c0ffeeca7@users.noreply.github.com>
This commit is contained in:
Jan Bouwhuis 2023-08-08 08:48:44 +02:00 committed by GitHub
parent babaeea969
commit a0922fae84
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -248,7 +248,19 @@ mqtt:
retain: true
```
For a check, you can use the command line tools `mosquitto_pub` shipped with `mosquitto` to send MQTT messages. This allows you to operate your switch manually:
For a check, you can use the command line tools `mosquitto_pub` shipped with `mosquitto` to send MQTT messages. This allows you to operate your switch manually. First, we can simulate the availability message sent for the switch:
```bash
mosquitto_pub -h 127.0.0.1 -t home/bedroom/switch1/available -m "online"
```
We can simulate the switch being turned on by publishing the "ON" command message:
```bash
mosquitto_pub -h 127.0.0.1 -t home/bedroom/switch1/set -m "ON"
```
Finally, we can simulate the switch reporting back the changed state to Home Assistant:
```bash
mosquitto_pub -h 127.0.0.1 -t home/bedroom/switch1 -m "ON"