USB controlled mains switch

Jan 18, 2025 Last reply: 1 year ago 37 Replies

I'm using these (relays) to control my central heating from a Pi Zero. They are OK

Driving a relay via a transistor is very simple and the code is minimal

You mean you didn't follow the "See more product details" under "About this item" link ?

Ah, there is also a "product parameters" paragraph (down the page).

And no, the relais themselves being specced for 220V doesn't mean s**te when the board its on has its low- and high-voltage tracks too close together.

Regards, Rudy Wieser

The high-voltage tracks are MUCH fatter than the low voltage tracks on the PCB, as you can clearly see in the photo of the underside of the board, and high and low voltage sections of the board are well separated. My main concern would be the high voltage tracks heating up and deliminating when the current gets really high, but I think they are OK for 10A. Looks pretty good to me.

Lars,

Thick tracks are current, not voltage related.

And by the way, I didn't see those images the first time around : I've got all third-party (domain) content blocked by default.

How many low-voltage lines do you seee going to the relays at the underside ? I see just a single one. And that means the topside has the rest, which I can't see.

And do remember there is a 30 Watts rating mentioned. Which one should we believe ? That one, or the other, 2200 Watts one ?

I can guess a bit, but I'd rather not when letal voltages are in play. :-|

Regards, Rudy Wieser

What you want is a mains rated GPIO compatible relay card. All good Pi stockists carry them, and they are available in any thing from a single relay single pole, up to 4 or more dual pole units. You'll want to get a small electric junction box to put the relay and the spliced cable into.

---druck

The easy solution to that is to get a short single socket mains extension cable and splice the relay into that. It's then usable with any device.

If it's got a wall wart, it's far better to switch the low voltage side. You can then use a less expensive non mains rated relay. Most wall wart devices have a connector of some sort, so make an extension lead to splice the relay into. If it is a hard wired one, you'll have to cut the cable at some point, but fit some 5.5x2.1mm jack connectors so you can rejoin it without the relay if needed.

---druck

No need to rewire the end device to use a relay controller. Just wire up a simple intermediate between the relay and the controlled device. i.e. add a plug and outlet to the relay. Or buy a pre-built one:

Low voltage controlled (about $40)

formatting link
Ethernet controlled (about $80)
formatting link

In message snipped-for-privacy@ku.gro.lloiff>, Adrian snipped-for-privacy@ku.gro.lioff> writes

OP here with a follow up.

After some ruminating, I decided to give the Local Bytes Smart plug a try. I've got it happily working now, although I did have to install (yet) another Pi to act as the control hub (Home Assistant if anyone is interested). I'm now waiting for a fresh delivery of a Pi3 to install as a WiFi AP (the Pis in the locality are all Pi2).

One useful feature of the Local Bytes offering is that you can see to power being consumed by the device it is controlling (although mine suggests that I'm on 245V), but I've yet to work out how to access that via a command line, rather than web interface.

Thanks again for the suggestions.

Adrian

Did you opt for ESPHome or Tasmota firmware?

I use Tasmota, but I use Domoticz rather than Home Assistant. From what I read ESPHome is tailored for Home Assistant and uses REST API rather than MMQT like Tasmota.

A Pi4 can handle a lot of different services on the same machine, installed in Docker Containers. So you don't necessarily need lots of Pis. If the Pi4 isn't enough, there are more powerful Pis.

In message <voibvg$2bloc$ snipped-for-privacy@dont-email.me, Pancho snipped-for-privacy@proton.me writes

Tasmota. No particular reason.

Machine power isn't likely to be an issue. HA suggest a Pi4 as a suitable host, but I didn't have a spare one, so I installed it on a Pi3. However, as I need to set up a WiFi Access point, and that needs >=Pi3 I had to go shopping. I hope that for what I'm going to be using it for (apart from the AP), a Pi3 will be more than enough.

So far as I've been able to find out, HA is only installed as an image on the SD card (using the RPI Imager), rather than manually installed on an existing Pi image (e.g. apt install ...), so that means that the Pi can only be used for what HA allows you to do. Therefore, one downside (for me) with HA is that I don't seem to be able to gain SSH access to the PI. I can access it via the web interface, and I can install a ZSH shell on it, but that is in (I think) a Docker Container. What I would like to be able to do, which I can with my other Pis, is to run regular health check stuff, CPU temp, free memory, free card space that sort of stuff. I can do that from the Docker Container, but I can't set up a cron job to do it, and I haven't even tried getting it to email me a daily summary.

A quick look at Domoticz suggests that it will allow me to do my own monitoring, so that could be worth looking at in due course.

Thanks for the follow up.

Adrian

I hope you plan to run other services on the Pi3 as well - used purely as an access point, the pi is not the best choice. For a low number of stations and low throughput, it works, but dedicated wireless access points have better wifi hardware (and probably cost less).

cu Michael

Indeed I do. I'll see how it goes, and if it doesn't work out, then I can turn the WiFi off, and it can carry on with its other duties. My expectation is that it will be talking to at the most three Smart Switches, I'm unlikely to be using it for (e.g.) Internet access from a phone.

Adrian

HA can be installed in several ways.

The normal HAOS install has a series of Docker containers that are orchestrated by HA, and to do that it uses the whole Pi. SSH access is to inside the primary container, rather than the native system.

It's possible to install HA via Docker onto a regular RaspiOS system. That means you have access to the outside system, but the downside is that HA can't manage its own containers. For example, some plugins come in separate containers and you'd have to install those by using Docker, rather than clicking a button in HAOS and have it spin them up itself.

(If you pass through the Docker socket to the primary HA container, it's possible it can then orchestrate other containers without using HAOS. I haven't tried that)

There's also a 'just install HA using Python' method in which case there's no Docker containers, but that means upgrading is up to you doing it by hand. HA changes pretty regularly so that method isn't recommended.

Finally, if you were on x86 you can install HAOS in a VM which is just like having it take over the whole machine only inside a VM. You could run a HAOS image using KVM on a Pi but I'm not sure how smooth that would be.

Theo

In message <eSD* snipped-for-privacy@news.chiark.greenend.org.uk>, Theo <theom+ snipped-for-privacy@chiark.greenend.org.uk> writes

<big snip for brevity>

Thanks for the extra info. More to digest when I get a chance.

Adrian

I had no idea why I chose Domoticz over HA, it was a few years ago, but you present a compelling argument.

My rpi4 Domoticz install is a 12 line docker-compose.yml.

I already had MQTT.

Domoticz works, lets me switch things on and off, immediately or scheduled, and provides me with historical usage graphs. Which is all I really want.

Dunno if it relates to you, but I had a similar SSH problem.

I had a Gitea Container (a pretty UI git repo manager) needing to reserve the standard SSH port for git to work, this took over the host rPi host standard SHH port. My solution was to assign the Gitea container its own LAN IP address using a Docker Macvlan network drive, thus the Gitea container and the host rPI could each use the default SSH port as they had distinct IPs.

I've managed to get a PI to ask HA to turn my switch on and off, but I've not been able to get the PI to read the data used to generate the graphs, which I'd like to be able to do. It would be useful to at least know if the switch is already on before I try to turn it on again ! Bonus points for being able to get the power consumption of the device it is controlling.

Until installing HA, I've never (knowingly) had any dealings with Docker.

Adrian

Try Domoticz, it is supposed to be much simpler than HA. Not as feature rich as HA, but maybe a better fit for a simple home setup. (Caveat: I've never used HA).

That should be Macvlan network driver, not drive.

Docker is brilliant! If they had had it when I was working, I wouldn't have needed to wear my brown trousers every release day, at least not so much :-). Although, I'm sure the bright young things of today will have introduced new complexity, so it is still easy to mess things up.

Nowadays, for me, it can make installing third party software simple, as opposed to a nightmare of conflicting environment.

In message <volamj$2v89p$ snipped-for-privacy@dont-email.me, Pancho snipped-for-privacy@protonmail.com writes

It's on the tuit list.

From what little I know of it, I can see the attraction of using it for complex stuff, but I'm not convinced that it isn't a bit OTT for simpler stuff. A problem is deciding when simple becomes complex.

Adrian

Join the Discussion

Have something to add? Share your thoughts — no account required.

Didn't find your answer?

Ask the community — no account required