UKC

Home automation - reading dimmer switch

New Topic
This topic has been archived, and won't accept reply postings.

I've ended up with a load of smart bulbs in my living room, originally for the ability to tweak the colour temperature, but I've since fallen down a bit of a rabbit hole with Home Assistant. Crucially, I want my home to work like a normal home - light switches switch the lights on and off, for example. I've added a few Shelly relays to the light switches to allow the switch to recall scenes in Home Assistant. So far so good.

I don't like that I have to open an app or webpage to tweak the brightness of things though. I currently have a 2 gang back box above my mantel that the previous owners were using to route an antenna cable to their TV, and is currently sitting there with a blanking plate. I'd like to add a 4-way dimmer switch and use the four knobs to control the state of individual bulbs. I need to somehow read the value of each dimmer knob into Home Assistant. Getting USB power to the back box should be possible.

My current thoughts are to use an ESP32 to read the resistance of the dimmers via the ADC inputs. Does anyone have any experience of achieving the end result I want, and have any thoughts or alternate suggestions on how to achieve it?

Post edited at 09:32
 montyjohn 21 Nov 2024
In reply to the.last.thesaurus:

I think I'm at a similar stage to you.

In my living room I'm using the Candeo no-neutral zigbee dimmer with dumb bulbs and it works great.

I tried to fit smart bulbs with the dimmer, but couldn't find a way to only read the knob position, and click, and disable the default function of the unit in HA.

The result was lots of flickering. Even when on full power.

So I fitted the smart bulbs in the bedroom, and just adjust their brightness and colour based on time, phone alarm, phone charge state and sun position. I therefore find I don't need to adjust it in the phone.

Except, I need to fit a shelly because I end up running automations when power is cut to the bulbs. They sometimes get the automation, and sometimes don't when turned off. Not sure why this is. Maybe HA keeps trying for a while?

I may purchase a few Zigbee Tuya Smart Knobs that are battery operated and get full control that way and use a shelly in detached mode to control the on and off. 

What's the reason for wanting to control all the bulbs separately? I usually find if I want one dim, I want them all dim. On the very rare occasion I want something out of the ordinary then using the  phone isn't too much faff.

Post edited at 10:51
In reply to montyjohn:

> What's the reason for wanting to control all the bulbs separately? I usually find if I want one dim, I want them all dim. On the very rare occasion I want something out of the ordinary then using the  phone isn't too much faff.

I'm a lighting designer, and thus never happy! The switch selecting scene based on time of day or similar doesn't work for me as my days vary massively - I don't have a set routine, dinner time, etc. I also don't want a modern interface - my entire home has a Victorian feel to it (trying to pay homage to the Victorian building I live inside) , and so the solution needs to fit with that. It also makes life easier for anyone staying or otherwise there when I'm not - a knob per light is pretty simple to work out if one isn't happy with the lights as they come on when switched on. And some of the light sources are practical - reading lamps, etc - so being able to turn a physical knob and make it brighter or dimmer would be quite useful.

Post edited at 11:36
 montyjohn 21 Nov 2024
In reply to the.last.thesaurus:

> I'm a lighting designer, and thus never happy!

This must by why you are spending hundreds of pounds and hours now, to save a tiny bit of electricity and time in the future.  In the end I had to accept it's a hobby.

> my entire home has a Victorian feel to it (trying to pay homage to the Victorian building I live inside) , and so the solution needs to fit with that

There is something satisfying about switches looking old and dumb, but actually being very sophisticated. I like it.

I think your route using a ESP32 will be your best option. 've not used one for monitoring changes to a resister, but I used one for controlling a servo motor which will soon hopefully lock and unlike my cat flap. ESPHome is surprisingly easy to use. I had to cheat with the YAML and used copilot a lot, but it works well.

Also updated over the via is surprisingly satisfying.

In my next house, if it ends up being a full renovation, I wouldn't mind running 3V, 6V and 12V cables to all windows, doors, radiators etc to avoid all battery operated sensors and actuators.

In reply to montyjohn:

> This must by why you are spending hundreds of pounds and hours now, to save a tiny bit of electricity and time in the future.  In the end I had to accept it's a hobby.

Eh? £30 of smart bulbs, a Raspberry Pi and probably an ESP32. The change from "hundreds of pounds" would buy a substantial amount of beer.

I'm ultimately doing it because I want my living space to be lit to my satisfaction and no other reason.

 CantClimbTom 21 Nov 2024
In reply to the.last.thesaurus:

I use digital controls, usually application of "Dexter F2" but "Sinister F2" can work just as well 

Post edited at 16:52
 montyjohn 21 Nov 2024
In reply to the.last.thesaurus:

The bug truly hasn't caught you yet then.

When/if you start doing something similar in every room, and then move on to adding smart sockets, cameras, motion sensors, door open sensors, power monitoring etc it's very easy to spend a substantial amount of money.

I'm not quite that bad yet, but as I slowly add stuff it will eventually get there.

As a lighting designer you know you want smart bulbs in the bedroom. You can then program them to do a sunrise affect when your alarm goes off. Maybe it's too cheesy, but it's nice to wake up to.

 Lankyman 21 Nov 2024
In reply to CantClimbTom:

> I use digital controls, usually application of "Dexter F2" but "Sinister F2" can work just as well 

I think you've put your finger on it?

In reply to the.last.thesaurus:

ESP32 is the right answer for this. It'll be super easy.

Edit: I've used the capacitive sensors built into the ESP32 as touch sensitive controls for lighting. You don't even need knobs.

Edit again: if you do want to use knobs, you'll probably want rotary encoders rather than resistors, so that you can change the settings from elsewhere and not have it bound to the position of the knob.

Post edited at 19:18
In reply to Longsufferingropeholder:

Knobs are desirable in this instance

I'll take a proper look into it tomorrow. Been ages since I wrote code for an embedded thing (or anything to be honest), so it should be a fun little project.

 Billhook 21 Nov 2024
In reply to the.last.thesaurus:

I live in a late Victorian house.   We have light bulbs in ceiling lights and a fair amount of table lamps suited to their purpose, such as reading.

These have a switch on the wall to turn them on and off or on  the lamp itself.

Its quite a simple system and has been around for many years and doesn't cost a lot.  The lamps are also quite portable.

2
In reply to Billhook:

That would be absolutely fine - but fortunately (for the planet) we've stopped selling incandescent light bulbs, and the most suitable replacement I've found is a smart bulb which needs to not be actually switched off to be most useful, and can't be dimmed by a standard dimmed. Thus the problem was born.

(And now, as a side benefit, I can just switch one switch and all of the lights come on as I want them too - floor lamps and all.)

Post edited at 19:48
 montyjohn 21 Nov 2024
In reply to Longsufferingropeholder:

> Edit again: if you do want to use knobs, you'll probably want rotary encoders rather than resistors, so that you can change the settings from elsewhere and not have it bound to the position of the knob.

It would make the project a fair bit more complicated using a rotary encoder, as he'll have to buy the Victorian style dimmer switch and rebuild it using something like a KY-040 as the style he wants I suspect only comes in an analog flavour. It would be a better solution but harder to fabricate.

I don't see why the position of the resistor would dictate light brightness of the bulbs as Home Assistant can override this and tell the bulbs to be any brightness the user chooses.

The only problem would be that when you turn the knob the light might jump around a bit the bulb brightness and knob are out of sync. You could deal with this by making the light brightness not change until the dial has caught up with the set brightness. 

 Joez 21 Nov 2024
In reply to the.last.thesaurus:

How about an Aqara Cube?

You can get stickers or 3D print covers for it to fit in more with your aesthetic.

In reply to montyjohn:

That's exactly the problem I was on about. What if you want to turn it further away from its current setting? There would be all kinds of non-intuitive stuff you'd have to make it do.

Much easier just to have it go up and down from where it's set. You can put any knob you want on the encoders.

 dread-i 22 Nov 2024
In reply to montyjohn:

>When/if you start doing something similar in every room, and then move on to adding smart sockets, cameras, motion sensors, door open sensors, power monitoring etc it's very easy to spend a substantial amount of money.

I see that, like me, you're a fan of 'man maths'. 'If I spend £££ on a Smartthings hub, some bulbs, sockets, Tado, Arlo, zigbee bits and bobs etc, I can link it all together using ITTT and save 30p worth of electricity, if I leave my lights on when I go away for 2 weeks.

In reply to montyjohn:

Forgot to add, the off the shelf dimmer won't be a resistor anyway, so it'd need rebuilding either way unless there's some easy way to get in there and tap off from the knob directly and/or rip out all the thyristor gubbins. At that point may as well can the whole lot and go with encoders so that it'll behave just like everyone expects. I would expect if there's not better way they could simply be glued on the inside of the faceplate and then the knobs could be made to fit using various levels of sophistication from 3d printed adaptors all the way down to hot glue.

In reply to montyjohn:

> When/if you start doing something similar in every room, and then move on to adding smart sockets, cameras, motion sensors, door open sensors, power monitoring etc it's very easy to spend a substantial amount of money.

It really depends how you do it. If you buy off the shelf 'smart stuff' and use paid for apps and walled gardens then yeah. But when you homebrew it all with esp32s, open source software and electronic bits that come from random eBay shops for somehow unfathomably less than the price of a stamp, it's staggeringly cheap to do.

Edit: obviously don't cheap out on the mains voltage stuff. But for everything else the bits are pence.

Post edited at 09:20
 elsewhere 22 Nov 2024
In reply to dread-i:

A smart bulb or plug may be consuming 0.5W 24/7, so no savings for controlling a 5W LED load. I suspect that's the case for my smart stuff.

Post edited at 09:12
In reply to the.last.thesaurus:

Aaaaand another thing...

When I did a thing with rotary encoders I found that all the Arduino encoder libraries were really glitchy and basically crap. Writing the routines myself only took about 8 lines, and way less time than I'd wasted reading the docs for the libraries, and it worked flawlessly. 

In reply to the.last.thesaurus:

Aaaaand another other thing....

> Getting USB power to the back box should be possible.

A while ago I had plans to do a similar thing, reusing TV aerial back boxes for microcontrollers. Never did it in the end, but after an embarrassingly long time spent scratching my head over how to get a few hundred mA at 5 or 12 V to them, the solution became obvious. Hint: do you still use your aerial wiring for TV signals? We don't.

 dread-i 22 Nov 2024
In reply to elsewhere:

> A smart bulb or plug may be consuming 0.5W 24/7, so no savings for controlling a 5W LED load. I suspect that's the case for my smart stuff.

And then there is the power required to power all those devices, that monitor and control the other devices.

But its a slippery slope, when you start adding numbers. If we let facts and figures get in the way of everything, then we'd never have got to the moon.

In reply to the.last.thesaurus:

Apologies all - have read and noted everyone's replies, haven't had a chance to respond! I'm going to have to do a custom job on the dimmer switch internals anyway, whether potentiometer or rotary encoder they will be swapped out. I see advantages to either, leaning towards a potentiometer and some control logic to not change values until passing through the current value. Powering it by an ESP32 seems like the obvious solution.

In reply to the.last.thesaurus:

>  I see advantages to either, leaning towards a potentiometer and some control logic to not change values until passing through the current value. 

I can't see any advantage of a pot. If it's the code that's putting you off, don't let it. I looked again and my rotary encoder code was really trivial. Might post it later if I remember. Essentially, you set an interrupt on one of the encoder pins that fires a routine to check them both. If they're both the same it's gone one way and if they're different it's gone the other way. That routine sets a flag say p=1 for up p=2 for down, or whatever, then you check that flag in your main loop and do things (and set it back to 0) if it's set. 

That way the esp just says "up please" and "down please" to your home assistant and never needs to know what the current setting is. 

You'll need way more logic to do the other thing and, in my opinion at least, it'll be really confusing behaviour to anyone who isn't you. Doing "has someone turned any of the pots or is it just ADC noise?" is a harder problem to solve. And I think I'd get bored of telling guests "no, no, you have to turn it up to its current setting before you can turn it down".

I'd avoid at all costs any solution that requires the esp to know the current setting, because there will be loads of situations when it won't and it'll do weird stuff.

Post edited at 07:19
In reply to the.last.thesaurus:

This was for an arduino nano so there might be subtleties with how you set up interrupts, but essentially it's this. Let's see how the formatting goes....

void setup() {
...other stuff
  pinMode(clkpin, INPUT_PULLUP);
  pinMode(dtpin, INPUT_PULLUP);
  attachInterrupt(digitalPinToInterrupt(clkpin), knobbed, CHANGE);
...other stuff
}

void loop() {
......other stuff
  if (p != 0){
    target+=p;
    p=0;
    constrain(target,15,95);
  }

,,,,,,,,other stuff
}

void knobbed (){
  noInterrupts();
  if (digitalRead(clkpin) == digitalRead(dtpin)){
    p=-5;
  } else {
    p=5;
  }
  interrupts();
}

 Brass Nipples 26 Nov 2024
In reply to the.last.thesaurus:

You can get dimmable LEDs then you just need a dimmer switch with appropriate load ratings.

1
 montyjohn 26 Nov 2024
In reply to Brass Nipples:

But then you can't adjust colour. e.g., you typically want redder light when it's dark, and white during the day.

And then if you have multiple light, lamps etc, you home assistant you can set up scenes that can quickly be switched on, either with a flick of a switch, or based on time of day, sun position etc. Example scenes could be for watching TV, reading, listening to Barry White with a lady etc.

The one I like is if I go to the toilet between midnight and 6am, light automatically come on at the minimum setting. If using smart bulbs you could also make the shift red which wakes you up less.

 Brass Nipples 26 Nov 2024
In reply to montyjohn:

> But then you can't adjust colour. e.g., you typically want redder light when it's dark, and white during the day.

If it’s not dark, I typically do not have the lights on, and therefore their colour temp at that point doesn’t matter.

3
 montyjohn 26 Nov 2024
In reply to Brass Nipples:

Maybe you have bigger windows than me, but on a cloudy winters day I need lights on to do anything other than watching TV indoors.


New Topic
This topic has been archived, and won't accept reply postings.
Loading Notifications...