For once I am giving back instead of taking - pay iot forward (pun intended)!
(I added a picture of the end result and the wiring diagram - in another post way towards the bottom of this thread, the below original post is how to do all the configuration.)
Elegant solution to a gnarly Shelly Dimmer 2 problem, thought it might be useful to others!
(By the way, this is 110V USA - and here, up is usually on and down is usually off - but the same concepts would work anywhere.)
Problematic requirements:
- Keep old fashioned USA standard two-switch wall plate (as ours is custom painted)
- Replace one of the two switches with a dimmer - but keep it looking like an old wall switch
- No neutral available
- No Zwave or Zigbee
- Have to stick with WiFi (not BLE)
- Able to integrate with HA
- Still be able to at least turn the light on and off even if HA is dead
- No bypass!
A very long search through the internet - for something that can be integrated reliably into Home Assistant via WiFi only with no additional hub or dongle needed resulted in only the below solution which finally works like an easy to use “dumb” dimmer switch - but seamlessly integrates behind the scenes with home automation:
Solution:
-
Shelly Dimmer 2
-
Leviton 1257 momentary two pole switch:
-
Use incandescents (or LEDs and a bypass if you must )
Configuration (#1-3):
- Ensure the switch is connected as detached as shown here in the Shelly dimmer 2 setttings:
Note regarding the above, the dual button mode should NOT be used as it has the following issues: short presses up OR down BOTH toggle the light on and off which is confusing, and even if the light is already on, a long press up will dim the light to 0% brightness FIRST and then start increasing the light level. Very annoying!
Note, Button 1 is up (on or increase brightness if held) and Button 2 is down (off or decrease brightness if held). Depending upon how you wired the switch, you can just swithc 1 and 2 in the Shelly settings so no need to take the dimmer back out of the wall to do that!).
However - to make the switch still be able to turn the light on or off even if HA is dead and while the switch is set to detached mode - go to the Shelly Dimmer 2 settings and put this in the button 1 short pressed URL (and enable it):
and conversely put this in the button 2 short pressed URL (and enable that as well):
Example for the button 2 short pressed off in the settings is here:
Which means that now, a short push of the switch up will still turn the switch on - and only on (even if pressed again), and a short push down will still turn it off - and only off - even though it is detached - even if Home Assistant has died!
How does that work if the dimmer has the switch in DETACHED mode? Look at the url’s entered - they are calling “localhost” so that just means the dimmer 2 is making an internal call to itself - and that still works in detached mode
The only thing that is now no longer directly controlled by the physical dual pole momentary switch is the brightness level - which is handled by the following code for 2. long press up (brightening) and 3. long press down (dimming). The below code has been tested and the timings are needed (especially the delay within each loop) for proper operation:
- Home Assistant YAML code for long press up (brightening the light):
Given:
- The up position switch entity_id in Home Assistant is: binary_sensor.den_shelly_dimmer_2_channel_2_input (replace that with the name of yours)
- The Dimmer 2 is integrated into Home Assistant as a light (in the Shelly Dimmer 2 settings), it’s Home Assistant entity_id is: light.den_shelly_dimmer_2 (replace that with the name of yours)
(Also note, this has logic that first turns the light on without specifying the brightness, which will turn the light on at the previous brightness it already had, to then increase the brightness from there, rather than from 0% (much better and expected user experience).)
Then, this is the code:
alias: Den Shelly Dimmer 2 Long Press Up - Detached Momentary Switch
description: >-
This automation has to use conditions only within the actions as two different
condtions need to be met for each of two different actions. When a dual pole
momentary switch is held in the up position (the position to turn the light
on) for more than 250 millesconds (1/4 of a second), if the light is off first
turn it on, and then as long as the button is still being held up, brighten
the light by 10% every 250 milleseconds (1/4 of a second).
trigger:
- platform: state
entity_id:
- binary_sensor.den_shelly_dimmer_2_channel_2_input
to: "on"
for:
hours: 0
minutes: 0
seconds: 0.25
condition: []
action:
- repeat:
while:
- condition: state
entity_id: light.den_shelly_dimmer_2
state: "off"
sequence:
- service: light.turn_on
data: {}
target:
entity_id: light.den_shelly_dimmer_2
- repeat:
while:
- condition: state
entity_id: binary_sensor.den_shelly_dimmer_2_channel_2_input
state: "on"
sequence:
- service: light.turn_on
data:
brightness_step: 10
transition: 1
target:
entity_id: light.den_shelly_dimmer_2
- delay:
hours: 0
minutes: 0
seconds: 0
milliseconds: 250
mode: single
- Home Assistant YAML code for long press down (dimming the light - only if it is on) -
Given:
- The down position switch Home Assistant entity_id is: binary_sensor.den_shelly_dimmer_2_channel_1_input (replace that with the name of yours)
Then, this is the code:
alias: Den Shelly Dimmer 2 Long Press Down - Detached Momentary Switch
description: >-
When a dual pole momentary switch is held in the down position (the position
to turn the light off) for more than 250 millesconds (1/4 of a second) - only
if the light is on - while the switch is still being presssed, dim the light
by 10% every 250 milleseconds (1/4 of a second).
trigger:
- platform: state
entity_id:
- binary_sensor.den_shelly_dimmer_2_channel_1_input
to: "on"
for:
hours: 0
minutes: 0
seconds: 0.25
condition:
- condition: state
entity_id: light.den_shelly_dimmer_2
state: "on"
action:
- repeat:
while:
- condition: state
entity_id: binary_sensor.den_shelly_dimmer_2_channel_1_input
state: "on"
sequence:
- service: light.turn_on
data:
brightness_step: -10
transition: 1
target:
entity_id: light.den_shelly_dimmer_2
- delay:
hours: 0
minutes: 0
seconds: 0
milliseconds: 250
mode: single
Tweaked to perfection by a home automation fanatic, increasing WAF from 0% to 100%.
I have to correct the above to the below. Any issue with the home automation - decreases it by at least 99%. Any good thing with home automation - increases it by about 0.001 % lol
Tweaked to perfection by a home automation fanatic, increasing WAF from 32% to 32.001%. :-