News for hackers. Stuff that matters.
Re:The Amazing $1 Microcontroller (2017) by neya on Tuesday May 07, 2019 @03:32PM (#19852674)
Sure. Power monitoring is tricky. Rest are simple.

Power monitoring involves converting the mains voltage to DC that is almost proportional to the mains voltage. Then you would rectify it and downsize it and get it to a voltage level that whatever power management IC you use can accept. You also need to include fuses and other safety circuitry to ensure it doesn't exceed that threshold your microcontroller can accept. For example, if my uC works based off just 5 volts, I want to make sure I downsize my 120VAC to just 2.5V but still proportional, this means, when there is a spike, my uC can take a hit upto 5 volts, but that means my actual power supply has a spike of 100%, which means I'm getting 240VAC on a 120VAC outlet (which has never happened so far).

Then, for the actual turning on or off of switches itself, I just use relays and some relay/motor coil ICs to control them. Sorry I don't remember exactly as this was a year ago and this system is lying inside my wall. So I need to remove the switchboard (and use a lens) to find out the numbers. But then, you can always google for "Power management / mains voltage IC", you can find even ready made modules on eBay.

The tricky part is component layout since you are dealing with high voltage, it can form arcs: https://www.youtube.com/watch?v=MAlyEMQxTN0

Not as powerful, but still a smaller version of those arcs. So, you want to use well rated components with decent thresholds. Eg. Don't use a low power relay, cheap capacitors, etc.

All of this is then passed on through uCs(ATTINY 85 + other uCs in the circuit) to some nrF wireless modules I bought in bulk on AliBaba through my uC

To be clear, each switchboard housing contains - a couple of relays, uCs, nRF modules, temperature and humidity sensors and some infrared sensors (I don't use them anymore). I believe they also have overvoltage protection and short circuit protection in built (because of an IC I use). It will simply turn the relay off in the event of a spike or short circuit.

BTW, AliBaba is the cheapest. Don't buy from AliExpress, it's usually plagued with dropshippers (god, I hate them so much) who just keep hefty margins off a factory somewhere that you can find on AliBaba. Other alternatives, but still under AliBaba group: 1688.com, tmall.com

If you think about it, in cloud lingo, we would call this architecture as "micro services" except that there's one big monolith which is my mains module run by an old laptop motherboard. (Sony Vaio FZ series)

This nrF module talks to a an old laptop motherboard through serial, that passes information to a REST API. This laptop motherboard is located where usually all the mains connections go in. One thing I didn't use on purpose is smart trippers/circuit breakers. Sure, they're smart, but you're relying on someone else for security while also giving away your power usage consumption data. Besides, if a circuit breaker goes off, you want to know why it happened before turning it on, so I find it pointless to make them be able to turn on automatically or from your phone when I can just walk to my mains box and turn it on myself.

The REST API is built with Phoenix/Elixir, and is hosted on Google Cloud AppEngine. I haven't had any downtime so far (yet) and is blazing fast. Like I said, I'm a Google Cloud consultant, so this is what I do for a living. You may have luck doing the same with AWS/DigitalOcean. Just use something you know well.

And don't ever get into doing devops for this kind of thing. It's more critical than you think. So, don't make choices like try to save up on the servers by running your own instance on a DO droplet for 5 bucks a month. Sure, you saved up some cash, but the devops it takes you will cost you more. More importantly, if some hacker gets in, you're doomed!

Once, when I was in my house, the lights and TV suddenly started turning on and off in the hall room. This was right after I came back from watching Insidious and it was really scary. Then I found out, it happened because there was a really fat mouse on the motherboard (don't know how it got there) walking around the jumper wires. Haha!

Hope this helps, sorry I will try to update with specifics maybe in a separate blog post here.

Re:The Amazing $1 Microcontroller (2017) by magicalhippo on Tuesday May 07, 2019 @04:02PM (#19852937)
> You also need to include fuses and other safety circuitry to ensure it doesn't exceed that threshold your microcontroller can accept.

I'd say you need to include other safety circuitry, as well as proper PCB design, to make sure it doesn't start a fire.

If you don't know what you're doing, don't rely on random stuff from AliExpress etc to be grid safe, and don't try to make stuff that connects to the grid yourself.

If you do not know what you're doing, for stuff like this I'd go with say Fibaro Z-Wave stuff or similar devices which have built-in power monitors, and can interface with Home Assistant or similar.

Re:The Amazing $1 Microcontroller (2017) by cm2187 on Tuesday May 07, 2019 @05:55PM (#19853812)
There are also cheap-ish USB devices that can do that [1] that you can stick in a raspberry pi and control with pretty much any language including python. For someone who shouldn’t be trusted with high voltage like me that’s the right level of tinkering.

[1] https://www.yoctopuce.com/EN/products/category/usb-electrica...

Re:The Amazing $1 Microcontroller (2017) by neya on Wednesday May 08, 2019 @09:44AM (#19858719)
Of course, that goes without saying, to be clear, I'm not advocating buying random off the shelf parts from AliBaba. I recommend doing proper research and getting certified safe parts for mains and I also agree not to play with the mains if you don't know what you're doing, it is far from a hobbyist thing and the only reason I did this is because I have a background in electrical and electronics.

Having said that, you can always buy "modules" from Siemens, Honeywell, etc. Get your circuits audited by someone with more experience, in particular by an experienced electrical engineer before using it live.

Have multiple levels of fail-safe, fuses, fire retardant casings, what not. Just think of every possible worse-case scenario before you do it.

After all, electricity is no joke and can literally kill you.

Re:The Amazing $1 Microcontroller (2017) by foobarian on Tuesday May 07, 2019 @04:34PM (#19853195)
I would be terrified of any kind of relay there. I had a few relays fail on my furnace such that they burned a 1" diameter hole in the PCB.
Re:The Amazing $1 Microcontroller (2017) by aaroninsf on Tuesday May 07, 2019 @05:28PM (#19853614)
watermelon0 has the correct answer: [most] hobbyists should stick 100% to low-voltage low-current applications and use off the shelf certified hardware whene interfacing with high-voltage (i.e. mains) power.

MEE hobbyists, disregard.

Re:The Amazing $1 Microcontroller (2017) by vvanders on Tuesday May 07, 2019 @05:43PM (#19853718)
Even with a MEE your Homeowner's policy may deny a claim due to non-UL listed components installed along the mains.

I won't touch electrical on my house and will happily contract it out to a license+bonded electrician for the exact same reason.

That said really cool project and Kudos for tacking it, just make sure your smoke detector is working :).

Re:The Amazing $1 Microcontroller (2017) by watermelon0 on Tuesday May 07, 2019 @05:19PM (#19853541)
If you have a device drawing high current, you would probably use a contactor (high-power relay), and then you can use low current (or even low voltage) relay/triac to drive the contactor from your circuit.
Re:The Amazing $1 Microcontroller (2017) by neya on Wednesday May 08, 2019 @04:57AM (#19857068)
High power relays with safety certifications are typically used in mains boxes available commercially. In fact, I'm using the ones from my old mains box.

Even theoretically, the only way a relay could catch fire if the coil inside overheats or if you pass very high voltages to the coil. But, with a well designed circuit, it should be fine.

Re:The Amazing $1 Microcontroller (2017) by painted on Wednesday May 15, 2019 @08:41AM (#19918786)
I prefer having the REST API running on a raspberry pi or a local server, that can proxy things to Google Cloud and back, just because in case something happens to the internet connection, your house is bricked, by having a local instance your system does not rely on your ISP for speed and availability.

I'd be curious of how do you update these devices, did you get OTA to work through an nRF24? did you need some external eeprom for that?

Re:The Amazing $1 Microcontroller (2017) by StavrosK on Tuesday May 07, 2019 @09:24PM (#19855084)
Can you buy single items on AliBaba? I've been buying from AliExpress a lot because of the convenience, I didn't know you could do the same on the main site?