For your setup to work you need 3 components
- Mosquitto (MQTT) broker
- HA connected to the mqtt broker
- iotlink service connected to the mqtt broker
Iotlink service runs on your pc and listens to the topic on mqtt broker. In ha the script weāre trying to make publishes a word (suspend/hibernate/etc) which triggers the iotlink service to do w/e it is configured to do when it āhearsā the word.
You might have done all/some of the following, just check if you didnāt miss anything:
Letās assume your MQTT broker runs at 192.168.1.123 listening to the default port 1883, change the values in following examples according to your setup if different.
In Ha go to Settings/Devices & Services. Click the Add Integration at the bottom, Search for MQTT, add MQTT, enter the ip 192.168.1.123 and port 1883. If your broker is secured with name and password enter those too.
Thatās step 1. and 2. covered you have HA connected to MQTT broker.
On the PC you want to control install iotlink, go to Start/All Programs/IOT link/Open Configuration File, in the configuration.yaml
it opens make sure to enter the correct MQTT info like so:
########################################################################
# TCP Connection Settings
########################################################################
tcp:
enabled: true
hostname: 192.168.1.123
port: 1883
again, if your broker is secured enter the name/password above the TCP section. Save the file, Start/All Programs/IOT Link/IOT Link Service Stop and then IOT Link Service Start.
That covers point 3, and at this point the whole setup should be ready for the script as both HA and IOT link are connected to the same MQTT broker.
Letās create the script then. In HA go to Settings/Automations & Scenes and go to Scripts tab at the top, click Add script at the bottom right.
- Fill the top part (name/icon etc) to your preference
- In Sequence there will be default Device action, click the 3 dots in itās row and delete that.
- Add Action / Call Service
- In the dropdown find
MQTT: Publish
- Topic:
iotlink/workgroup/RogerD-PC_SSD/commands/suspend
- Save script
Run the script, your pc should go to sleep. If it doesnāt, assuming the ha and iotlink are connected to the mqtt broker correctly, you can use MQTT Explorer, connect that to 192.168.1.123 port 1883 and see whether both are connected, and if your topics are right like so:
the highlighted part is the topic of your pc, check thatās correct in the script.
Notes:
IOT Link is discontinued although it still works, it has issues, notably the one where you have to restart the service after pc wakes up for which you can use a Task Scheduler on wakeup task running this .bat
@echo off
C:\WINDOWS\system32\net.exe stop IOTLink
C:\WINDOWS\system32\net.exe start IOTLink
That said I still use it on 3 pcs, however I have been looking into GitHub - LAB02-Research/HASS.Agent: Windows-based client for Home Assistant. Provides notifications, quick actions, commands, sensors and more. as replacement just havenāt had time to test it and change the automations etc.
Hope you find any of the above useful and get the script working.