mongoose-os-apps / shelly-homekit

Apple HomeKit firmware for Shelly's
Other
1.75k stars 128 forks source link

Shelly Dimmer / Dimmer2 support possible ? #14

Closed andyblac closed 4 days ago

andyblac commented 4 years ago

as title do you think Shelly Dimmer would possible ?

rojer commented 4 years ago

in principle, yes. but it has secondary microcontroller, which is an additional complication.

andyblac commented 4 years ago

I could do with it, would you be willing to take a look if I send you one ?

andyblac commented 4 years ago

could this help ? https://github.com/alexryd/homebridge-shelly

rojer commented 4 years ago

no, that's not relevant.

i would not recvommend starting with dimmer. implementing input as push button would be easier and get you acquainted with what implementing a HAP service entails.

andyblac commented 4 years ago

an a dimmer act as on/off too ?

rojer commented 4 years ago

what's the use for the dimmer without, you know, dimming functionality? i think we should hold off declaring support for shelly dimmer until dimming is implemented. in terms of HAP, that would mean implementing a lightbulb service, which supports variable brightness.

andyblac commented 4 years ago

so if I purchased a shelly dimmer I could try adding as a switch to start ?

kzyapkov commented 4 years ago

The dimmer is indeed not the device to start with. If lighting is your thing, try the LED drivers, they should be much simpler, using PWM for output control.

As for the dimmer -- we plan on releasing info about the UART protocol used to control the small MCU which does the actual dimming, but no ETA.

andyblac commented 4 years ago

ahhhh. atm I'm using Philips Hue, but tbh it is unreliable, found shelly's much more so and it is instant, I was hoping to replace my Hue with Shelly's.

kzyapkov commented 4 years ago

please drop a note to developers@shelly.cloud, we may be able to help

andyblac commented 4 years ago

atm I have zero knowledge of HAP or MOS, I am a python coder. mOS looks vastly different, I am trying to read through this git code to try to get an understanding of it.

rojer commented 4 years ago

right, so dimmer is not a good start. better pick a simpler issue to tackle. for HAP, your bible is HAP-Specification-Non-Commercial-Version.pdf. you can download it from here. you'll need to login with apple id but it's free of charge. get familiar with the concepts - controller, accessory, service, characteristic, event. then read existing code to understand how services are defined and characteristics and events managed. fortunately, it's not that much - all of the "switch" service implemented by shellies is contained here.

in terms of coding - yeah, it's the good old C, not Python. not much do be done about it, i'm afraid. either you pick it up, or you won't be able to do much.

andyblac commented 4 years ago

thanks, I have some homework to do πŸ˜„

sebastianheise commented 4 years ago

Hi guys! How are you doing? I've caught up on this thread and had a look at the HAP. From my understanding a dimmer would be implemented using the brightness characteristic. Correct? So instead of a switch, the device would need to authenticate as a light bulb service. Is that assumption correct? Unfortunately I also don't have any experience in HAP and MOS, but it sounds like a fun project. If I can help with anything I'm all keen. Just give me a yell. Would be awesome to have support for the Shelly dimmer!

rojer commented 4 years ago

yes, that is correct.

On Mon 24 Feb 2020, 09:34 Sebastian Heise, notifications@github.com wrote:

Hi guys! How are you doing? I've caught up on this thread and had a look at the HAP. From my understanding a dimmer would be implemented using the brightness characteristic. Correct? So instead of a switch, the device would need to authenticate as a light bulb service. Is that assumption correct? Unfortunately I also don't have any experience in HAP and MOS, but it sounds like a fun project. If I can help with anything I'm all keen. Just give me a yell. Would be awesome to have support for the Shelly dimmer!

β€” You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/mongoose-os-apps/shelly-homekit/issues/14?email_source=notifications&email_token=AAEBW22ZN6MVSONBO7SYKX3REOIAXA5CNFSM4KUBHZDKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEMXEHNI#issuecomment-590234549, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAEBW2YH2NXSTSSSHOR4HF3REOIAXANCNFSM4KUBHZDA .

Olly68 commented 4 years ago

@rojer Do you have plans for Shelly Dimmer 2 at the moment? Or is time still your problem?

It would be great if you can find a solutionπŸ‘ŒπŸ»πŸ˜€

ree109 commented 4 years ago

Would this help with the dimmer - https://github.com/curla92/LED-Dimmer-Homekit

vanrri commented 4 years ago

Anyone tried it yet?

On Wed, 19 Aug 2020 at 7:47 PM ree109 notifications@github.com wrote:

Would this help with the dimmer - https://github.com/curla92/LED-Dimmer-Homekit

β€” You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/mongoose-os-apps/shelly-homekit/issues/14#issuecomment-676832486, or unsubscribe https://github.com/notifications/unsubscribe-auth/AQPL2JLGMPVB7LIBAZRTTRTSBRXADANCNFSM4KUBHZDA .

andyblac commented 3 years ago

Just so you don't get Bored!!! HAHA, Can This Be Next Please!!!

rojer commented 3 years ago

yes, i think i'll tackle either dimmer or rgbw2 next. we'll see.

andyblac commented 3 years ago

cool cheers!!!

andyblac commented 3 years ago

yes, i think i'll tackle either dimmer or rgbw2 next. we'll see.

do you need any devices ?, I don't mind donating one of each for you to work with.

rojer commented 3 years ago

no, i'm all set. i've had a couple for a while now.

andyblac commented 3 years ago

ok np.

freddair commented 3 years ago

+1 for Dimmer next :)

rojer commented 3 years ago

yes, dimmer is next (after garage door is out), in particular dimmer2, which is what i have for testing.

andyblac commented 3 years ago

yes, dimmer is next (after garage door is out), in particular dimmer2, which is what i have for testing.

if I can help with debug info for Dimmer1 let me know.

freddair commented 3 years ago

+1 for Dimmer1

Leo-W536 commented 3 years ago

+1 for Dimmer 1 πŸ‘πŸ»

andyblac commented 3 years ago

i now have dimmer2, so can help testing that too πŸ˜„

ToblerCGN commented 3 years ago

I got two dimmers 2. I'd like to help, too!

Przemyslaw-Wosko commented 3 years ago

@rojer can we implemnet shelly dimmer as light bulb instead? it has characteristics to on / off and also dimm i will try to update some code, and rise PR.

What do you think?

rojer commented 3 years ago

that's exactly the plan, dimmer will be represented as a lightbulb HAP service with "brightness" characteristic.

Przemyslaw-Wosko commented 3 years ago

Have you started work somewhere? i've noticed it will be lot of work, since everything relays on Switch I'd love to collaborate instead of writing whole stuff from scratch

rojer commented 3 years ago

the biggest chunk of work will be implementing the UART protocol to communicate with the MCU that does the dimming. adding a HAP service, will be the easy part. no, i haven't written any code yet, but i have test setup and have looked into the protocol details, i have a reasonable grasp of it now. will probably get something written this weekend.

rojer commented 3 years ago

well, this did not go to plan at all. i was having issues getting ,y firmware to run after OTA, and while messing with serial connections, briefly had both non-isolated serial connected while i turned on the mains power... BOOM! sparks, smoke, lights go out. when the smoke cleared, the casualties are: 2 of 2 dimmers, usb hub and, crucially, my main laptop. nothing much to show for it. not a good day... but i'll be back :)

pivale commented 3 years ago

well, this did not go to plan at all. i was having issues getting ,y firmware to run after OTA, and while messing with serial connections, briefly had both non-isolated serial connected while i turned on the mains power... BOOM! sparks, smoke, lights go out. when the smoke cleared, the casualties are: 2 of 2 dimmers, usb hub and, crucially, my main laptop. nothing much to show for it. not a good day... but i'll be back :)

damn :( sorry to hear that!

freddair commented 3 years ago

@rojer glad to understand that yourself have not been harmed though! I have a few stock Dimmer1 laying around, so let me know if and how I can provide you with one!

andyblac commented 3 years ago

@rojer Dam, thats not good, the pesky none isolated serial is dangerous. Just glad to here your OK though, kit can be replaced. I think we need to get you some donations in to help you replace that laptop. One from me on the way!!

Przemyslaw-Wosko commented 3 years ago

@rojer thanks for effort, i didn't knew this could go soo bad and i feel sorry for your laptop, i hope it wasn't something extremally expensive

freddair commented 3 years ago

@rojer do you already have the needed Dimmer UART specification? Otherwise maybe the sample config of HAA firmware could help:

{"t":30,"d":0.1,"b":[{"g":12,"i":1,"p":0},{"g":12,"t":0}],
"0":{"u":[{"v":"010202060000f401000000ff04"}]},
"y0":[{"v":1,"0":{"u":[{"v":"010202060a00f4010000010904"}]}},
{"v":5,"0":{"u":[{"v":"010202063200f4010000013104"}]}},
{"v":10,"0":{"u":[{"v":"010202066400f4010000016304"}]}},
{"v":15,"0":{"u":[{"v":"010202069600f4010000019504"}]}},
{"v":20,"0":{"u":[{"v":"01020206c800f401000001c704"}]}},
{"v":25,"0":{"u":[{"v":"01020206fa00f401000001f904"}]}},
{"v":30,"0":{"u":[{"v":"010202062c01f4010000012c04"}]}},
{"v":35,"0":{"u":[{"v":"010202065e01f4010000015e04"}]}},
{"v":40,"0":{"u":[{"v":"010202069001f4010000019004"}]}},
{"v":45,"0":{"u":[{"v":"01020206c201f401000001c204"}]}},
{"v":50,"0":{"u":[{"v":"01020206f401f401000001f404"}]}},
{"v":55,"0":{"u":[{"v":"010202062602f4010000012704"}]}},
{"v":60,"0":{"u":[{"v":"010202065802f4010000018b04"}]}},
{"v":65,"0":{"u":[{"v":"010202068a02f4010000010904"}]}},
{"v":70,"0":{"u":[{"v":"01020206bc02f401000001bd04"}]}},
{"v":75,"0":{"u":[{"v":"01020206ee02f401000001ef04"}]}},
{"v":80,"0":{"u":[{"v":"010202060032f4010000013104"}]}},
{"v":85,"0":{"u":[{"v":"010202065203f4010000015404"}]}},
{"v":90,"0":{"u":[{"v":"010202068403f4010000018604"}]}},
{"v":95,"0":{"u":[{"v":"01020206b603f401000001b804"}]}},
{"v":100,"0":{"u":[{"v":"01020206e803f401000001ea04"}]}}]}
rojer commented 3 years ago

@freddair that's a neat hack. i'd like to have something more sophisticated than that, though.

freddair commented 3 years ago

of course! πŸ‘

Przemyslaw-Wosko commented 3 years ago

@rojer done is better than perfect :D wouldn't that be sufficient as proof of concept for dimmers? it could be upgraged in future

andyblac commented 3 years ago

@rojer done is better than perfect :D wouldn't that be sufficient as proof of concept for dimmers? it could be upgraged in future

imo, HAA is not the way to go, it far to hacky for my liking, i would rather it done correctly in the place.

freddair commented 3 years ago

@rojer done is better than perfect :D wouldn't that be sufficient as proof of concept for dimmers? it could be upgraged in future

imo, HAA is not the way to go, it far to hacky for my liking, i would rather it done correctly in the place.

Yeah I tried HAA on my Shelly Dimmer 1 before and it was less than perfect - from time to time I had issues with on/off blinking lights and input confusions / crashes... but I thought that UART commands to the dimmer chip would likely not have been the cause.

https://github.com/RavenSystem/esp-homekit-devices/issues/1166

andyblac commented 3 years ago

i did find a github thread that gave @rojer the info he needed, we just need to be patient.

https://github.com/arendst/Tasmota/issues/6914#issuecomment-562109267

rojer commented 3 years ago

i don't intend to polish every last bit for the first iteration, but having just a couple fixed commands to bang out is a bit too low a bar :) since no actual progress is expected until i get my laptop back and a couple test devices, let me dump my thoughts so far instead :)

so, the way dimmer works is quite complicated. it has a slave mcu that does the PWM and communication is over UART. the same UART that is normally used for flashing and debug, so that's complication number 1. second, the protocol is not documented. there are multiple commands. third, the slave MCU formware is tightly coupled to the stock ESP firmware. STM firmware is shipped with the ESP firmware and is stored on the filesystem. ESP will flash it first thing after boot if it detects version mismatch. finally, there is the calibration procedure - calibration data is stored on the filesystem, and is sent to the STM on boot.

so, there's quite a lot of ground to cover here to get to feature parity with the stock firmware, but we can do it in stages.

stage 0, early testing:

this is essentially what HAA bunch of strings does, but a little more sophisticated - we'll actually use proper sequence numbers and check responses.

stage 1:

stage 2:

stage 3:

that's the path i see. of course, i stumbled straight out of the gate - i didn't even get as far as running my code on the ESP before everything went up in smoke :)

freddair commented 3 years ago

@rojer great path! I would love to help in beta testing stage 0.

And I would also love to start with a simple switch implementation (light on/100% and off/0%), as the dimmer is already installed behind the wall switch and I fiddle with it since ages (HAA, home bridge-shelly didn't work either)...

I am currently on stock fw again and really can't wait to have a working basic HomeKit implementation.

Let me know how I can send you one of my spare Dimmer1 :)

rojer commented 3 years ago

@freddair i'm focusing on dimmer2 at first, as that is the current product for sale. that said, extending support to dimmer1 is also planned, so if you can send me a device to test with, it'd be great. sned me an email to rojer@rojer.me and i'll give you the address.