Switching UK power socket with no cloud services based on ping results

I have what should be a niche requirement, but as anyone who uses Virgin Media for their broadband in the UK will attest, it’s sadly not. I want to have a script that power cycles the virgin router when its connection drops for longer than a period of time.

I currently have a first-gen rasberry pi with an energenie hat that controls one of their sockets, but the pi is very old and slow and I’d love to replace it with something more modern, and drop the requirement to maintain the old pi.

This feels like Home Assistant territory, but am I right? What socket should I get? How would I connect to it to control it using nothing more than some local wired or wireless protocol? What would I need to do that from the computer side? (which is hopefully going to be a linux VM running on a Synology NAS).

To refine my requirement: I’m ideally not wanting to do any soldering of components or construction of hardware; something already assembled and higher volume production would work better for me, even if it means I’m burning some currently to keep a device on all the time.

Many thanks in advance for any help provided!

Athom power socket preflashed with tasmota
Use this rule to power cycle the router based on ping

https://tasmota.github.io/docs/Rules/#watchdog-for-wi-fi-router-or-modem

1 Like

If your broadband router runs on something like 12VDC you can easily leech the power for a esp from it while at the same time using the NC contact of the relay for even less power draw.

I expect such a solution not only being half of the price than a full fledged plug but also only half of the power draw (maybe) less which will help as this thin runs probably 24-7. :clock1230:

For esphome you can use this custom ping component so no other “brain” is needed. :brain:

I think this is a good scenario what the difference is between devices you can own and extended (esp based ones) and other plugs (like Z-technology) which you can own the hardware but actually not get the logic on it as you have no control over the soft/firmware part :put_litter_in_its_place:

I’d probably use a Sonoff S26 flashed with Tasmota open source firmware (bit like pre-compiled ESPhome), but the use of a Tasmota rule in the device is rather nice.

The S26 is widely available on Amazon, but does need a little work to flash with Tasmota firmware. The first device you convert can take many attempts with a FTDI cable (£5 tops), but once mastered, the skill will get used regularly!

I got the S26 v2 so found it easier to tack solder serial cables to the PCB as unlike other devices, there’s not a nice neat row of 4 pins on the S26.

For external HASS control, here’s a guide to setting up MQTT:

If you really don’t want to touch hardware, get any controllable plug (e.g. Zigbee, or even Bluetooth) and try the ping binary sensor:

If this helps, :heart: this post!

1 Like

Just be careful not to buy the cheapest ESP12F relay module - I’ve been sent one that was a perfect hardware copy, but the relay control chip was a brick as it was missing firmware (not the ESP12F).

That is like the (valid) solution mentioned by @ferbulous.

Still I would want to avoid a extra PSU and a always energized relay. Not only the higher power draw (waste) but also for longlivety. Only energizing the relay for the restart which hopefully not happens often and having the relay with no power draw at the other 99% of the time just makes sense.

Also routers typically get some DC voltage which can directly be harvested for the esp & relay :muscle: (no extra PSU like which is integrated in the sockets :zap:)

Never heard of that. :thinking: Firmware in the relay control chip? You probably ain’t got any sources for your claims?

I only know of a problematic revision/version that needs a bodge wire to work well together with the ESP-01.

Yes. That’s why I said “the use of a Tasmota rule in the device is rather nice.”

Some of the single channel relay modules DON’T just use a GPIO with a MOSFET to switch the relay coil - some a stupid enough to use a hex serial protocol between the ESP and a STC15F104W uP, presumably to act as an I/O expander on larger boards with more channels.

Some copies of copies don’t flash the STC uP, so without lots of bodge wires (or a STC dev kit), it’s a brick. After finding the issue on a few forums, I binned the module as being too much of a time sink. If the manufacture is that bad, I’m not even going to trust the relay contacts with 5V in production.

Oh, you still want sources - “citation needed”. Search for “Duinotech Smart WiFi Relay Kit”
https://www.amazon.co.uk/ask/questions/Tx1I8GKKX2FBM4P/ref=ask_dp_dpmw_al_hza

https://www.jaycar.com.au/medias/sys_master/images/images/9796440719390/XC3804-dataSheetMain.pdf

Writes {0xA0, 0x01, 0x00, 0xA1} for off,{0xA0, 0x01, 0x01, 0xA2} for on, via
serial terminal

Just because the design is stupid, doesn’t make it less true. :man_facepalming:t2: :man_shrugging:t2:

That’s very interesting indeed! I own a couple of this esp-01 relay boards and while they are little bit different one to another they all luckily work the “stupid” way and can be easily triggered via gpio. :control_knobs:

Any way it might be even easier to use a relay board with a esp and serial already on-board because the esp-01 modules need a external serial and probably the most crude esp module around to flash :zap:

Another potential setup could be a D1 Mini with relay and power shield.

imageimageimage

The title has “AZdelivery” in the name. I would never buy any products from them as they have kind of a history of shipping “broken” stuff actually (never bought something myself but read a lot’s of people have problems with there “versions” of esp’s, sensors and so on).

Obviously not. And thanks for the informations (specially the details about the STC uP and the link) :+1:

One more idea having the thing 24-7 hours with low power draw on could be to use a FET and no relay. Obviously the circuit needs to be on all the time but the draw should still be significant lower than a energized relay coil.

Could make use of the hardware suggested by @system :point_down:

Probably just screwing in a DC male and female plug should do the trick for like 95% of the router owners

image

Almost plug’n’play after this :play_or_pause_button:

You’d think so - but there’s a minor trap in the UK. I’m not a Virgin Media customer so don’t know their OP’s kit, however BT/ EE / Plusnet all provide routers which almost have a standard 2.1mm barrel jack. Sadly, the centre pin is just a bit bigger (N.B. a 2.5mm falls out), so a small drill is required to get a “standard” 2.1mm barrel jack plug to fit.

(I went through my sets of adaptor tips and none would fit so suspect a “modification” to discourage non-supplier PSU in the name of proper telecom-grade voltage separation.)

Of course, if you’ve gone this far… I’d buy a cheap CCTV power supply and a 12V SLA battery - for £40 + £10, you get a nice metal case for the ESP relay, a lock, lots of MOV/ polyfuse protection, LEDs, and probably 4 hours UPS backup for the router (mine has never got close to being discharged), and you could easily add a car USB charger for a Wemos D1 mini.

To go completely over the top, add some 12V LED tape, and you could even have a bar graph of Internet usage! :slight_smile:

First thing when I come across such “almost” standard plugs is to take the snips :scissors: and put a “real” standard plug :electric_plug:

Not metal but the Sinilink board suggested by our @system is also available in a smaller version with (plastic) case and could be easily installed in-line :wavy_dash:

Some quick (and unscientific) measurements reveled about 0.3 - 0.4 watt power draw for the whole thing. That might be less than only the energized relay of an ordinary (AC) smart plug (not taking the the internal PSU or ESP into account). :zap:

@FloatingBoater / @orange-assistant - thanks for the suggestions so far!

To refine my requirement: I’m ideally not wanting to do any soldering of components or construction of hardware; something already assembled and higher volume production would work better for me, even if it means I’m burning some currently to keep a device on all the time.

Something with the same form factor as this myenergie product, but without any internet dependency that their MiHome stuff implies.

The closest to a UK non-cloud range of products are Shelly - the problem is they don’t offer a BS1363 plug device like Sonoff:
https://shellystore.co.uk/shop/

So either learn to flash a Sonoff (to remove the cloud firmware with Tasmota), or put a Shelly in a case and wire to the terminals yourself for local control ftom HASS.

The other options are HASS + Zigbee - such as a IKEA Tradfri socket (£15, but ignore the remote controls) + a Sonoff v3 USB Zigbee coordinator.

@FloatingBoater - thanks, that’s very useful! I won’t have a chance to look for a while but wanted to say thanks in the meantime!