SamZorSec / Arilux_AL-LC0X

Alternative firmware for Arilux AL-LC0X LED controllers, based on the MQTT protocol and a TLS connection
MIT License
190 stars 33 forks source link

[Feature] Remember last color set in EEPROM #36

Open papaiatis opened 7 years ago

papaiatis commented 7 years ago

It would be nice if the device could remember the last color set, eg.: by storing it in its EEPROM so that the next time I plug it in it doesn't start as green.

tedstriker commented 6 years ago

doesnt writing every color change to the eeprom wear it down very quick making this only a somewhat temporary solution?

rvt commented 6 years ago

Isn´t this something mutt can handle?

rvt commented 6 years ago

In the end I decided to create this. The idea is that if mqtt is not available it will use the EEPROM value, otherwise the mqtt value.

It will only store the value if at least it will turn on any LEDS. This makes it similar to for example Ikea light bulbs where you turn off power and then on again you will always have light. This will also make the system much saver to use in a regular household.

In addition, EEPROM is protected against writing to frequent. The system will wait 5 seconds until the color values are stable before write to EEPROM, and will only write a maximum of each 5 minutes.

tedstriker commented 6 years ago

Still having the wear down in mind (despite your writing limit) Why wasn’t RAM an option? Does your mains power geht removed that often?

rvt commented 6 years ago

If you have the device connected on a switch then eeprom would be a good idea. If not, I still believe it’s a good idea for savety reasons to have the light go on after start

tedstriker commented 6 years ago

So you turn off your light twice? Just get me right. I play devils advocate just to get the actual use case clear ;)

rvt commented 6 years ago

@tedstriker:

I have currently two situations in mind: 1) When the light is off but with the wall switch in on setting. Then when you turn off the wall switch and then turn on the wall switch I expect the light to go on in it´s last setting, just like a good old dimmer. Reason: This is handy if you don´t have a ´device´or remote control at hand and you want to have good old wall switch functionality. 2) When the power goes off and on. Reasoning: I expect the light to go on as a safety feature. Any light where the switch is in on position will always go on when power is returned.

I am also concerned when network connectivity isn´t working, for example openhab/homeassistant is not responding, mqtt broker is down, WIFI is down etc... I also I expect normal wall function to work.

To answer your question of Nov 28. EEPROM will wear down to: Estimated it´s for the EEPROM about 100000 write cycles. Current Arduino code for the 8266 has something build in that limites write cycles to only writing changed locations however there are solutions to extend that with some techniques but did´look into that. I did implement crc16 during read/writes to ensure data is ok and will return some default value if crc16 is mis-matched, again to ensure we show something valid after the device goes on and show light.

Hope that clarifies my reasoning...

tedstriker commented 6 years ago

@rvt I didn’t even consider running the light strips behind a regular wall switch. Makes totally sense now. Thanks for your elaborate explanation.

rvt commented 6 years ago

Here is a branch where this issue is solved https://github.com/rvt/Arilux_AL-LC0X/tree/redesign

Note: It´s not a drop-in replacement because color model is changed from RGB to HSB and some things are changed to follow this design. It should be easy to convert though. If there is really a need for RGB model I can see what I can do but I just assumed that all control software (openHAB, Home assistant etc) can output HSB