whaleygeek / pyenergenie

A python interface to the Energenie line of products
MIT License
81 stars 51 forks source link

MIHO009: Double Light Switch support #129

Closed whaleygeek closed 3 years ago

whaleygeek commented 3 years ago

The MIHO009 Double Light Switch (herein called "2gang light switch" has some challenging timing requirements.

If the left channel switches and then the right channel switches soon after, it confuses the switch. Same the other way round.

Further timing restrictions need to be added to impose a holdoff delay or tx silence once a switch has switched, before sending it another command. This presumably gives it time to recharge an internal link capacitor that is dropped across the contacts, so that it can receive another payload and drive either relay open or closed again.

whaleygeek commented 3 years ago

I am working on this on the master branch, will keep rough notes here for historic reasons.

I proved today that if you send messages to another OOK device within the 3 second silence window requirement after the 2gang has switched, this causes some mis-switching (mostly on the right channel). This sort of implies that the processing of the (non matching) preamble is using some energy from the link capacitor and extending the delay before a successful switching event.

I also checked with an FSK device (adaptor plus) and proved that there seems to be no causal link between FSK switching and any adverse side effects of the 2gang switch.

Thus, the plan is to write a tx_silence enforcer to allow the 2gang switch to charge its link properly before more messages come in. The current modifications on the master branch do this. However, I have implemented a tx_silence after switching of the MIHO009 (which works very well), but bench testing of this while successful, indicates that lack of silence before attempting to switch the MIHO009 still causes occasional mis-switching.

It is possible therefore that any OOK activity causes some drain of the link capacitor and affects switching. So I might have to implement a 'silence before' rather than a 'silence after'.

The TwoBitAirInterface and radio_config changes made work well with the current algorithm though, so it is a good basis for future work.

whaleygeek commented 3 years ago

Moved the tx_silence to the beginning of the transmit phase, this works so much better. I think this is pretty much working rock solid now.

We don't have a concept of left-side and right-side of a MIHO009 2gang switch, but as long as you use the MIHO009 class with it, the timing knits together nicely with any other device.

Might do some testing of the single light switch just to see if it needs any tx_pre_silence for cap charge time (back to back switching on and off with no delay).