Hello guys
I bought this Sunricher switch with four buttons and paired it with my Sonoff Zigbee adapter.
I use Zigbee2mqtt and IKEA lights, and it’s working!
My goal with this switch was to turn on/off lights as well as dim the lightning. I couldn’t find anyone who solved it already ( or maybe my googling skills is kind of bad )
The thing is with this switch is, that it only sends events, which for me is:
press_1, release_1, press_2 release_2, press_3, release_3, press_4 release_4
But I wanted to know if the button was either short or long pressed.
So I have now created a new component which solves this, I call it dimmer_button for now.
So what it does is, when the event press_1 is pressed, it spawns a new thread and waits for x time before it checks again. If the release_1 was trigged, then we had a shortpress, otherwise the loop sends longpresses which then increase or decrease the lightning in the room.
I just wanted to share this component if someone else is interested in the same functionality.
It’s still a beta release, but please try it out if you have time
Put this in the configuration.yaml file:
dimmer_button:
sleep_time: 0.2
switches:
- switch:
no_of_buttons: 4
entity: sensor.strombrytare_vardagsrum_action
buttons:
- button: 1
target: light.lampor_vardagsrum
pressed: press_1
released: release_1
shortpressed: turn_on
longpressed: brightness_step_pct=+10
- button: 2
target: light.lampor_vardagsrum
pressed: press_2
released: release_2
shortpressed: turn_off
longpressed: brightness_step_pct=-10
- button: 3
target: light.vardagsrummet
pressed: press_3
released: release_3
shortpressed: turn_on
longpressed: brightness_step_pct=+10
- button: 4
target: light.vardagsrummet
pressed: press_4
released: release_4
shortpressed: turn_off
longpressed: brightness_step_pct=-10
- switch:
no_of_buttons: 1
entity: mybutton2
buttons:
- button: 1
target: light.minlampa2
pressed: press_1
released: release_1
shortpressed: turn_on
longpressed: brighter
I created a tarball (.tar.gz), on your home assistant instance:
tar zxvf dimmer_button.tar.gz
put it in the:
/root/config/custom_components/dimmer_button
folder if you are running Home Assistant OS.
Dimmer_button can be found here:
https://github.com/payano/core/blob/ea9beeb106e0c8a595d2f1edf26314030f359934/homeassistant/components/dimmer_button.tar.gz
Source code is here:
https://github.com/payano/core/tree/dimmer_button/homeassistant/components/dimmer_button
Please come with feedback.
For now it’s hardcoded for the press, release events. If you have other events, then I’ll consider to make it configurable.