Integrating a Sonoff S60TPG wifi controlled plug with Home Assistant Green
The Problem
I need to be able to remotely power cycle a device in my shed. While I can sometimes go down to the shed and manually reset the device, having the ability to power cycle it remotely would be an advantage. This becomes even more valuable if I can set a periodic power cycle or programmatically power cycle it based on some detected condition. I posted a query on Mastodon asking for personal recommendations for a ‘smart’ plug socket that I could integrate with HomeAssistant or that would otherwise allow me to control the socket’s state (on/off).
A Solution?
One of the more common suggestions for a device that would do what I wanted was a Sonoff S60TPG. This reasonably priced (£13.32 when I ordered it) device claims to integrate with Home Assistant or can be used entirely locally without cloud integration. It also offers voltage, current, and power monitoring and scriptable control of the socket status.
Initial Configuration
The instructions with the Sonoff S60TPG were fairly minimal but tell you to download their app for your phone. I skipped setting up an account and managed to add my device by plugging it into the mains and setting the Wi-Fi details in the app. I gave the socket a unique name and a location. Testing from the app, I was able to control the socket locally over Wi-Fi with no need for any cloud connection. I also added a ‘smart scene’ to power-cycle, the socket at one minute after midnight every day of the week forever.
Home Assistant Integration
These notes were written at the very end of December 2024; if you’re reading this more than a few months after that date, you will need to check for any updates here or elsewhere on the web. Home Assistant changes frequently, and what works now might not work by the time you try.
These are the software versions known to work as of December 2024.
Software | Version |
---|---|
Sonoff Firmware | 1.1.1 |
Home Assistant Core | 2024.12.5 |
Home Assistant Supervisor | 2024.12.0 |
Home Assistant Operating System | 14.1 |
Home Assistant Frontend | 20241127.8 |
I’ll preface this integration documentation by saying that while I got it to work, I’m still not entirely happy with it. I had to create an account with the device manufacturer, which I consider a failure. I should be able to control this entirely locally, with the manufacturer knowing nothing more about me and my purchase than that it has made them fractionally richer.
Hunting for information about supporting Sonoff hardware on Home Assistant led me to multiple forums and GitHub pages, where people asked questions but provided no examples of what they tried. After reading a few, I understood I needed to install HACS first, but again, I had no idea what this was or how to do it. Here’s how I went about it.
- Get HACS on your Home Assistant: https://www.hacs.xyz/docs/use/download/download/
- There’s a magic link that will start the process, assuming your Home Assistant install is available at ‘homeassistant.local’
- Select ‘open link’, fix the URL to point to your HA install, and in the Missing add-on repository dialog box, select Add.
- Select Install HACS, follow the instructions on the screen and reboot the HA when requested.
- Configure HACS
- In Home Assistant, go to Settings > Devices & services.
- Click Add Integration
- Search for HACS
- Tick all the boxes
- You’ll get a code and a link to Github. I don’t know what happens if you don’t use GitHub or don’t have an account with them.
- On GitHub select Authorize HACS
- You’ll be redirected back to HA
- Add HACS to an Area.
- You’ll probably need to reboot HA again now
- I needed to enable ‘AppDaemon apps discovery & tracking’ in the HACS integration configuration.
- Install eWeLink for Sonoff device controls
- In HACS, search for eWelink and install that. It showed up as Sonoff LAN on my install.
- Reboot HA
- In Home Assistant, go to Settings > Devices & services.
- Add Integration
- Search Sonoff
- It will ask for Sonoff / eWeLink account details. I had to create an account to continue; I couldn’t detect the Sonoff Plug on my LAN without an account. I DO NOT LIKE THIS.
- When the account details are added, you should be able to detect Sonoff devices on the LAN and add them as you would normally add controls to HA.
I added two cards, one for control of the supply and one for monitoring the supply.
Did it do what I wanted?
My ultimate aim in all this experimentation was to be able to reboot my weather station from inside the house. To this end, I plugged the power supply into the Sonoff plug and used HA to power-cycle the power supply periodically to reboot the weather station. Unfortunately, I hadn’t realised that the outputs on the power supply are disabled after a power cycle. They are only re-enabled with a button press. I could wire a small robot into HA to press the button on the power supply; it’s probably easier to just put a relay in the low-voltage supply to the weather station and control that instead. This will be another project. For now, I’ll move the Sonoff plug to my dehumidifier and scare myself with how much power it uses (now I can monitor it).
I’m not happy I had to create an account to use this plug. I’m not sure if that is something I’ve screwed up or a feature of the device. In fairness, using the eWelink software on a phone did not require any account; only getting the plug to run under HA seemed to need the account - filling in fake credentials or leaving them out entirely resulted in no devices being found.