Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactored management of lights, using classes and integers instead of floats. #5702

Merged
merged 11 commits into from
Apr 29, 2019

Conversation

s-hadinger
Copy link
Collaborator

Description:

This is a refactoring of the way Lights are managed.

  • all manipulation are encapsulated in classes.
  • all values are stored and computed as integers, avoiding expensive float calculations and avoiding rounding errors. Only exception: RGBtoXY uses floats
  • Brightness is now managed at full range 0..255, Dimmer is kept in sync with range 0..100
  • Hue/Sat and RGB are always kept in full sync. RGB is stored with full brightness (i.e. at least one of the components is 255), channels are then mixed with Brightness to get actual PWM values
  • Except if Option37 is set, light is either in RGB/Hue-Sat mode or in CT (white with colortone) mode. If CT is zero, then RGB mode, else CT mode.

Please use the following singletons:

  • light_state: to query light state (do not use setters unless you know exactly what you're doing)
  • light_controller: to change the values of the light. It will automatically recompute all channels, and store settings. Note: it does not send any MQTT message.

Final good news, code is 1.1KB smaller.

**Related issue (if applicable):

Checklist:

  • The pull request is done against the latest dev branch
  • Only relevant files were touched (Also remember to update changelog.ino file)
  • Only one feature/fix was added per PR.
  • The code change is tested and works.
  • The code change pass travis tests. Your PR cannot be merged unless tests pass
  • I accept the CLA.

@s-hadinger
Copy link
Collaborator Author

@Jason2866 I don't have access to an Alexa device until the end of the week. I did thorough testing via an alternative iOS app (Hue Lights) and through the Web API.

Would you be kind enough to try with an actual Alexa device and confirm it still works?

@Jason2866
Copy link
Collaborator

Jason2866 commented Apr 25, 2019

Switching on / off and dimmer still working. Not working is setting color via Alexa.
Test device is a real Color RGB light bulb (AiLight)

Command "Alexa Light blue" ends up in this (still lightning white)
There is no error feedback, Alexa responds with confirmed...

17:34:17 UDP: Packet (125)
17:34:17 HTP: Hue API (/vr0cFpv41CwnP3PpmyLwZaX0BtBARCMSNr6fkZc9/lights/1)
17:34:17 HTP: Hue Result ({"state":{"on":true,"bri":127,"colormode":"ct","xy":[0.31, 0.33],"hue":0,"sat":0,"ct":500,"alert":"none","effect":"none","reachable":true},"type":"Extended color light","name":"Licht","modelid":"LCT007","uniqueid":"dc:4f:22:0c:b8:da:00:11-1","swversion":"5.50.1.19085"})
17:34:18 HTP: Hue API (/vr0cFpv41CwnP3PpmyLwZaX0BtBARCMSNr6fkZc9/lights/1/state)
17:34:18 HTP: Hue POST args ()
17:34:18 HTP: Hue POST args ({"on": false})
17:34:18 SRC: Hue
17:34:18 MQT: stat/sonoff-0CB8DA/RESULT = {"POWER":"OFF"}
17:34:18 MQT: stat/sonoff-0CB8DA/POWER = OFF
17:34:18 HTP: Hue Result ([{"success":{"/lights/1/state/on":false}}])
17:34:18 HTP: Hue API (/vr0cFpv41CwnP3PpmyLwZaX0BtBARCMSNr6fkZc9/lights/1)
17:34:18 HTP: Hue Result ({"state":{"on":false,"bri":127,"colormode":"ct","xy":[0.31, 0.33],"hue":0,"sat":0,"ct":500,"alert":"none","effect":"none","reachable":true},"type":"Extended color light","name":"Licht","modelid":"LCT007","uniqueid":"dc:4f:22:0c:b8:da:00:11-1","swversion":"5.50.1.19085"})
17:34:18 CFG: Saved to flash at F4, Count 276, Bytes 3584
17:34:20 HTP: Hue API (/vr0cFpv41CwnP3PpmyLwZaX0BtBARCMSNr6fkZc9/lights/1)
17:34:20 HTP: Hue Result ({"state":{"on":false,"bri":127,"colormode":"ct","xy":[0.31, 0.33],"hue":0,"sat":0,"ct":500,"alert":"none","effect":"none","reachable":true},"type":"Extended color light","name":"Licht","modelid":"LCT007","uniqueid":"dc:4f:22:0c:b8:da:00:11-1","swversion":"5.50.1.19085"})
17:34:23 HTP: Hue API (/vr0cFpv41CwnP3PpmyLwZaX0BtBARCMSNr6fkZc9/lights/1)
17:34:23 HTP: Hue Result ({"state":{"on":false,"bri":127,"colormode":"ct","xy":[0.31, 0.33],"hue":0,"sat":0,"ct":500,"alert":"none","effect":"none","reachable":true},"type":"Extended color light","name":"Licht","modelid":"LCT007","uniqueid":"dc:4f:22:0c:b8:da:00:11-1","swversion":"5.50.1.19085"})
17:34:25 HTP: Hue API (/vr0cFpv41CwnP3PpmyLwZaX0BtBARCMSNr6fkZc9/lights/1/state)
17:34:25 HTP: Hue POST args ()
17:34:25 HTP: Hue POST args ({ "on": true, "xy": [0.13550301400290363,0.03987867049354716] })
17:34:25 SRC: Hue
17:34:25 MQT: stat/sonoff-0CB8DA/RESULT = {"POWER":"ON"}
17:34:25 MQT: stat/sonoff-0CB8DA/POWER = ON
17:34:25 HTP: Hue Result ([{"success":{"/lights/1/state/on":true}}])
17:34:26 HTP: Hue API (/vr0cFpv41CwnP3PpmyLwZaX0BtBARCMSNr6fkZc9/lights/1)
17:34:26 HTP: Hue Result ({"state":{"on":true,"bri":127,"colormode":"ct","xy":[0.31, 0.33],"hue":0,"sat":0,"ct":500,"alert":"none","effect":"none","reachable":true},"type":"Extended color light","name":"Licht","modelid":"LCT007","uniqueid":"dc:4f:22:0c:b8:da:00:11-1","swversion":"5.50.1.19085"})
17:34:26 CFG: Saved to flash at FB, Count 277, Bytes 3584
17:34:26 HTP: Hue API (/vr0cFpv41CwnP3PpmyLwZaX0BtBARCMSNr6fkZc9/lights/1)
17:34:26 HTP: Hue Result ({"state":{"on":true,"bri":127,"colormode":"ct","xy":[0.31, 0.33],"hue":0,"sat":0,"ct":500,"alert":"none","effect":"none","reachable":true},"type":"Extended color light","name":"Licht","modelid":"LCT007","uniqueid":"dc:4f:22:0c:b8:da:00:11-1","swversion":"5.50.1.19085"})
17:34:27 UDP: Packet (199)
17:34:27 UDP: Packet (199)
17:34:27 UDP: Packet (199)
17:34:27 UDP: Packet (199)

Alex light red:


17:37:56 UDP: Packet (199)
17:38:05 HTP: Hue API (/vr0cFpv41CwnP3PpmyLwZaX0BtBARCMSNr6fkZc9/lights/1/state)
17:38:05 HTP: Hue POST args ()
17:38:05 HTP: Hue POST args ({ "on": true, "xy": [0.7006062331309042,0.2993009868421053] })
17:38:05 SRC: Hue
17:38:05 MQT: stat/sonoff-0CB8DA/RESULT = {"POWER":"ON"}
17:38:05 MQT: stat/sonoff-0CB8DA/POWER = ON
17:38:05 HTP: Hue Result ([{"success":{"/lights/1/state/on":true}}])
17:38:05 HTP: Hue API (/vr0cFpv41CwnP3PpmyLwZaX0BtBARCMSNr6fkZc9/lights/1)
17:38:05 HTP: Hue Result ({"state":{"on":true,"bri":127,"colormode":"ct","xy":[0.31, 0.33],"hue":0,"sat":0,"ct":500,"alert":"none","effect":"none","reachable":true},"type":"Extended color light","name":"Licht","modelid":"LCT007","uniqueid":"dc:4f:22:0c:b8:da:00:11-1","swversion":"5.50.1.19085"})
17:38:05 CFG: Saved to flash at F7, Count 281, Bytes 3584
17:38:07 UDP: Packet (125)
17:38:07 UDP: Packet (199)

@Jason2866
Copy link
Collaborator

Changing colors via Alexa App Color select doesnt work too.
Alexa doesnt accept settings,

@s-hadinger
Copy link
Collaborator Author

Thanks. I don't know why Alexa sends XY colors and not HSB. It seems I need to handle XY colors after all. Code is ready, it should be quick to fix but will increase slightly code size.

@s-hadinger
Copy link
Collaborator Author

I think I understand the issue. The device was in CT mode "colormode":"ct" and Alexa wants to send a color. Since both Hue/Sat and XY are available, it chooses XY.

When in colormode, "colormode":"hs" so Alexa sends only Hue/Sat.

I will change to not send XY values when in CT mode, hoping that Alexa will send only Hue/Sat.

@s-hadinger
Copy link
Collaborator Author

@Jason2866 Could you please try with this new commit?

@Jason2866
Copy link
Collaborator

Short test. Doesnt work. Now Alexa give error messages. "Something went wrong..."
Can do more tests tomorrow, if needed
-> You opened a can of worms ;-)

22:21:36 UDP: Packet (199)
22:21:37 MQT: tele/sonoff-0CB8DA/STATE = {"Time":"2019-04-25T22:21:37","Uptime":"0T00:00:15","Vcc":3.557,"SleepMode":"Dynamic","Sleep":50,"LoadAvg":19,"POWER":"OFF","Dimmer":50,"Color":"000000FF","HSBColor":"0,0,50","Channel":[0,0,0,100],"Scheme":0,"Fade":"OFF","Speed":1,"LedTable":"OFF","Wifi":{"AP":1,"SSId":"Jason_Home_WLAN","BSSId":"00:A0:57:2A:BD:19","Channel":9,"RSSI":100,"LinkCount":1,"Downtime":"0T00:00:05"}}
22:21:46 HTP: Hue API (/vr0cFpv41CwnP3PpmyLwZaX0BtBARCMSNr6fkZc9/lights/1/state)
22:21:46 HTP: Hue POST args ()
22:21:46 HTP: Hue POST args ({"on": true})
22:21:46 SRC: Hue
22:21:46 MQT: stat/sonoff-0CB8DA/RESULT = {"POWER":"ON"}
22:21:46 MQT: stat/sonoff-0CB8DA/POWER = ON
22:21:46 HTP: Hue Result ([{"success":{"/lights/1/state/on":true}}])
22:21:46 HTP: Hue API (/vr0cFpv41CwnP3PpmyLwZaX0BtBARCMSNr6fkZc9/lights/1)
22:21:46 HTP: Hue Result ({"state":{"on":true,"bri":128,"colormode":"ct","hue":0,"sat":0,"ct":500,"alert":"none","effect":"none","reachable":true},"type":"Extended color light","name":"Licht","modelid":"LCT007","uniqueid":"dc:4f:22:0c:b8:da:00:11-1","swversion":"5.50.1.19085"})
22:21:47 CFG: Saved to flash at F9, Count 285, Bytes 3584
22:21:47 WIF: Checking connection...
22:21:47 WIF: Connected
22:21:56 HTP: Hue API (/vr0cFpv41CwnP3PpmyLwZaX0BtBARCMSNr6fkZc9/lights/1/state)
22:21:56 HTP: Hue POST args ()
22:21:56 HTP: Hue POST args ({ "on": true, "xy": [0.7006062331309042,0.2993009868421053] })
22:21:56 SRC: Hue
22:21:56 MQT: stat/sonoff-0CB8DA/RESULT = {"POWER":"ON"}
22:21:56 MQT: stat/sonoff-0CB8DA/POWER = ON
22:21:56 HTP: Hue Result ([{"success":{"/lights/1/state/on":true}}])
22:21:56 HTP: Hue API (/vr0cFpv41CwnP3PpmyLwZaX0BtBARCMSNr6fkZc9/lights/1)
22:21:56 HTP: Hue Result ({"state":{"on":true,"bri":128,"colormode":"ct","hue":0,"sat":0,"ct":500,"alert":"none","effect":"none","reachable":true},"type":"Extended color light","name":"Licht","modelid":"LCT007","uniqueid":"dc:4f:22:0c:b8:da:00:11-1","swversion":"5.50.1.19085"})
22:22:07 HTP: Hue API (/vr0cFpv41CwnP3PpmyLwZaX0BtBARCMSNr6fkZc9/lights/1/state)
22:22:07 HTP: Hue POST args ()
22:22:07 HTP: Hue POST args ({ "on": true, "xy": [0.13550301400290363,0.03987867049354716] })
22:22:07 SRC: Hue
22:22:07 MQT: stat/sonoff-0CB8DA/RESULT = {"POWER":"ON"}
22:22:07 MQT: stat/sonoff-0CB8DA/POWER = ON
22:22:07 HTP: Hue Result ([{"success":{"/lights/1/state/on":true}}])
22:22:07 HTP: Hue API (/vr0cFpv41CwnP3PpmyLwZaX0BtBARCMSNr6fkZc9/lights/1)
22:22:07 HTP: Hue Result ({"state":{"on":true,"bri":128,"colormode":"ct","hue":0,"sat":0,"ct":500,"alert":"none","effect":"none","reachable":true},"type":"Extended color light","name":"Licht","modelid":"LCT007","uniqueid":"dc:4f:22:0c:b8:da:00:11-1","swversion":"5.50.1.19085"})
22:22:07 WIF: Checking connection...
22:22:07 WIF: Connected
22:22:18 HTP: Console
22:22:25 HTP: Hue API (/vr0cFpv41CwnP3PpmyLwZaX0BtBARCMSNr6fkZc9/lights/1/state)
22:22:25 HTP: Hue POST args ()
22:22:25 HTP: Hue POST args ({"on": false})
22:22:25 SRC: Hue
22:22:25 MQT: stat/sonoff-0CB8DA/RESULT = {"POWER":"OFF"}
22:22:25 MQT: stat/sonoff-0CB8DA/POWER = OFF
22:22:25 HTP: Hue Result ([{"success":{"/lights/1/state/on":false}}])
22:22:25 HTP: Hue API (/vr0cFpv41CwnP3PpmyLwZaX0BtBARCMSNr6fkZc9/lights/1)
22:22:25 HTP: Hue Result ({"state":{"on":false,"bri":128,"colormode":"ct","hue":0,"sat":0,"ct":500,"alert":"none","effect":"none","reachable":true},"type":"Extended color light","name":"Licht","modelid":"LCT007","uniqueid":"dc:4f:22:0c:b8:da:00:11-1","swversion":"5.50.1.19085"})
22:22:25 CFG: Saved to flash at F8, Count 286, Bytes 3584
22:22:27 WIF: Checking connection...
22:22:27 WIF: Connected
22:22:30 UDP: Packet (199)
22:22:30 UDP: Packet (199)

@s-hadinger
Copy link
Collaborator Author

Hmmm. You should have the same issue with the development branch (the Alexa code just merged).

Could I ask one more test: please do "Color 1" (force RGB mode to red) before doing the Alexa device discovery. I just want to make sure it's linked to the CT/HS mode.

@Jason2866
Copy link
Collaborator

Jason2866 commented Apr 26, 2019

OTA didnt work (said successfull but still old version)... Light is switching on / off.
Dimming works. No error messages!
Color changing via Alexa still doesnt work.
Color in Alexa App changes to correct color when typed color <x>

Bad thing development branch doesnt work for devices with relais. I overlooked to test with powering off Alexa and doing a "fresh" discovery. Status in Alexa App "Device doesnt respond"

Log Alexa "light red" (before it was set to green via color 2)


09:50:38 HTP: Hue POST args ()
09:50:38 HTP: Hue POST args ({ "on": true, "xy": [0.7006062331309042,0.2993009868421053] })
09:50:38 SRC: Hue
09:50:38 MQT: stat/sonoff-0CB8DA/RESULT = {"POWER":"ON"}
09:50:38 MQT: stat/sonoff-0CB8DA/POWER = ON
09:50:38 HTP: Hue Result ([{"success":{"/lights/1/state/on":true}}])
09:50:38 HTP: Hue API (/vr0cFpv41CwnP3PpmyLwZaX0BtBARCMSNr6fkZc9/lights/1)
09:50:38 HTP: Hue Result ({"state":{"on":true,"bri":254,"colormode":"hs","hue":21906,"sat":254,"xy":[0.11500,0.82600],"ct":284,"alert":"none","effect":"none","reachable":true},"type":"Extended color light","name":"Licht","modelid":"LCT007","uniqueid":"dc:4f:22:0c:b8:da:00:11-1","swversion":"5.50.1.19085"})
09:50:39 HTP: Hue API (/vr0cFpv41CwnP3PpmyLwZaX0BtBARCMSNr6fkZc9/lights/1)
09:50:39 HTP: Hue Result ({"state":{"on":true,"bri":254,"colormode":"hs","hue":21906,"sat":254,"xy":[0.11500,0.82600],"ct":284,"alert":"none","effect":"none","reachable":true},"type":"Extended color light","name":"Licht","modelid":"LCT007","uniqueid":"dc:4f:22:0c:b8:da:00:11-1","swversion":"5.50.1.19085"})
09:50:39 WIF: Checking connection...
09:50:39 WIF: Connected
09:50:42 HTP: Hue API (/vr0cFpv41CwnP3PpmyLwZaX0BtBARCMSNr6fkZc9/lights/1)
09:50:42 HTP: Hue Result ({"state":{"on":true,"bri":254,"colormode":"hs","hue":21906,"sat":254,"xy":[0.11500,0.82600],"ct":284,"alert":"none","effect":"none","reachable":true},"type":"Extended color light","name":"Licht","modelid":"LCT007","uniqueid":"dc:4f:22:0c:b8:da:00:11-1","swversion":"5.50.1.19085"})
09:50:45 HTP:

@s-hadinger
Copy link
Collaborator Author

Thanks. I'm worried about the relais. I thought I tested it successfully. Do you mean device like Sonoff Basic?

Let's put on hold until next week, I'll have an Alexa device back.

@Jason2866
Copy link
Collaborator

Sonoff Basic doesnt work anymore with Alexa and latest dev branch.
Just flashed a second and did a full power cycle with all devices and a fresh discovery in Alexa App.

Yes, i think it is best if you can test directly with a Alexa device.

@s-hadinger
Copy link
Collaborator Author

This is a tentative for 'xy' color control. It works with the iOS app "Hue Lights" but completely untested with Alexa. Will be tested with Alexa next week.

@Jason2866
Copy link
Collaborator

Strike! Alexa voice light control does work :-)

@Jason2866
Copy link
Collaborator

Sonoff Basic still not working

Log


00:00:00 CFG: Loaded from flash at FB, Count 258
00:00:00 Project sonoff Kohlendioxid Version 6.5.0.9(sonoff)-STAGE
00:00:00 SNS: Hardware Serial
00:00:00 WIF: Connecting to AP1 Jason_Home_WLAN in mode 11N as sonoff-71C254-0596...
00:00:05 WIF: Connected
00:00:05 HTP: Web server active on sonoff-71C254-0596 with IP address 192.168.2.134
00:00:05 UPP: Multicast (re)joined
19:28:21 MQT: Attempting connection...
19:28:21 MQT: Connected
19:28:21 MQT: tele/sonoff-71C254/LWT = Online (retained)
19:28:21 MQT: cmnd/sonoff-71C254/POWER = 
19:28:21 MQT: tele/sonoff-71C254/INFO1 = {"Module":"Sonoff Basic","Version":"6.5.0.9(sonoff)","FallbackTopic":"cmnd/sonoff-71C254_fb/","GroupTopic":"sonoffs"}
19:28:21 MQT: tele/sonoff-71C254/INFO2 = {"WebServerMode":"Admin","Hostname":"sonoff-71C254-0596","IPAddress":"192.168.2.134"}
19:28:21 MQT: tele/sonoff-71C254/INFO3 = {"RestartReason":"Software/System restart"}
19:28:21 MQT: stat/sonoff-71C254/RESULT = {"POWER":"ON"}
19:28:21 MQT: stat/sonoff-71C254/POWER = ON
19:28:22 UPP: Multicast (re)joined
19:28:30 MQT: tele/sonoff-71C254/STATE = {"Time":"2019-04-26T19:28:30","Uptime":"0T00:00:14","Vcc":3.462,"SleepMode":"Dynamic","Sleep":50,"LoadAvg":19,"POWER":"ON","Wifi":{"AP":1,"SSId":"Jason_Home_WLAN","BSSId":"00:A0:57:2A:BD:19","Channel":9,"RSSI":96,"LinkCount":1,"Downtime":"0T00:00:04"}}
19:28:30 MQT: tele/sonoff-71C254/SENSOR = {"Time":"2019-04-26T19:28:30","MHZ19B":{"Model":"B","CarbonDioxide":964,"Temperature":24.0},"TempUnit":"C"}
19:29:29 MQT: stat/sonoff-71C254/RESULT = {"POWER":"ON"}
19:29:29 MQT: stat/sonoff-71C254/POWER = ON
19:29:30 MQT: tele/sonoff-71C254/STATE = {"Time":"2019-04-26T19:29:30","Uptime":"0T00:01:14","Vcc":3.463,"SleepMode":"Dynamic","Sleep":50,"LoadAvg":19,"POWER":"ON","Wifi":{"AP":1,"SSId":"Jason_Home_WLAN","BSSId":"00:A0:57:2A:BD:19","Channel":9,"RSSI":96,"LinkCount":1,"Downtime":"0T00:00:04"}}
19:29:30 MQT: tele/sonoff-71C254/SENSOR = {"Time":"2019-04-26T19:29:30","MHZ19B":{"Model":"B","CarbonDioxide":982,"Temperature":24.0},"TempUnit":"C"}
19:30:09 LOG: SerialLog 0, WebLog 4, SysLog 0, LogHost , LogPort 514, TelePeriod 60
19:30:09 HTP: Configuration
19:30:09 HTP: Hue API (/vr0cFpv41CwnP3PpmyLwZaX0BtBARCMSNr6fkZc9/lights/1)
19:30:09 HTP: Hue Result ({"state":{"on":true,"alert":"none","effect":"none","reachable":true},"type":"Extended color light","name":"Kohlendioxid","modelid":"LCT007","uniqueid":"5c:cf:7f:71:c2:54:00:11-1","swversion":"5.50.1.19085"})
19:30:10 CFG: Saved to flash at F9, Count 260, Bytes 3584
19:30:11 DMP: FF 86 03 CB 40 00 2D 00 3F
19:30:11 HTP: Main Menu
19:30:12 HTP: Hue API (/vr0cFpv41CwnP3PpmyLwZaX0BtBARCMSNr6fkZc9/lights/1)
19:30:12 HTP: Hue Result ({"state":{"on":true,"alert":"none","effect":"none","reachable":true},"type":"Extended color light","name":"Kohlendioxid","modelid":"LCT007","uniqueid":"5c:cf:7f:71:c2:54:00:11-1","swversion":"5.50.1.19085"})
19:30:15 HTP: Hue API (/vr0cFpv41CwnP3PpmyLwZaX0BtBARCMSNr6fkZc9/lights/1)
19:30:15 HTP: Hue Result ({"state":{"on":true,"alert":"none","effect":"none","reachable":true},"type":"Extended color light","name":"Kohlendioxid","modelid":"LCT007","uniqueid":"5c:cf:7f:71:c2:54:00:11-1","swversion":"5.50.1.19085"})
19:30:17 HTP: Console
19:30:18 HTP: Hue API (/vr0cFpv41CwnP3PpmyLwZaX0BtBARCMSNr6fkZc9/lights/1)
19:30:18 HTP: Hue Result ({"state":{"on":true,"alert":"none","effect":"none","reachable":true},"type":"Extended color light","name":"Kohlendioxid","modelid":"LCT007","uniqueid":"5c:cf:7f:71:c2:54:00:11-1","swversion":"5.50.1.19085"})
19:30:19 DMP: FF 86 03 C9 40 00 2D 00 41
19:30:20 WIF: Checking connection...
19:30:20 WIF: Connected
19:30:21 HTP: Hue API (/vr0cFpv41CwnP3PpmyLwZaX0BtBARCMSNr6fkZc9/lights/1)
19:30:21 HTP: Hue Result ({"state":{"on":true,"alert":"none","effect":"none","reachable":true},"type":"Extended color light","name":"Kohlendioxid","modelid":"LCT007","uniqueid":"5c:cf:7f:71:c2:54:00:11-1","swversion":"5.50.1.19085"})
19:30:23 UDP: Packet (199)
19:30:24 HTP: Hue API (/vr0cFpv41CwnP3PpmyLwZaX0BtBARCMSNr6fkZc9/lights/1)
19:30:24 HTP: Hue Result ({"state":{"on":true,"alert":"none","effect":"none","reachable":true},"type":"Extended color light","name":"Kohlendioxid","modelid":"LCT007","uniqueid":"5c:cf:7f:71:c2:54:00:11-1","swversion":"5.50.1.19085"})
19:30:26 HTP: Hue API (/vr0cFpv41CwnP3PpmyLwZaX0BtBARCMSNr6fkZc9/lights/1/state)
19:30:26 HTP: Hue POST args ()
19:30:26 HTP: Hue POST args ({"on": true})
19:30:26 SRC: Hue
19:30:26 MQT: stat/sonoff-71C254/RESULT = {"POWER":"ON"}
19:30:26 MQT: stat/sonoff-71C254/POWER = ON
19:30:26 HTP: Hue Result ([{"success":{"/lights/1/state/on":true}}])
19:30:26 HTP: Hue API (/vr0cFpv41CwnP3PpmyLwZaX0BtBARCMSNr6fkZc9/lights/1)
19:30:26 HTP: Hue Result ({"state":{"on":true,"alert":"none","effect":"none","reachable":true},"type":"Extended color light","name":"Kohlendioxid","modelid":"LCT007","uniqueid":"5c:cf:7f:71:c2:54:00:11-1","swversion":"5.50.1.19085"})
19:30:27 DMP: FF 86 03 C8 40 00 2D 00 42
19:30:27 HTP: Hue API (/vr0cFpv41CwnP3PpmyLwZaX0BtBARCMSNr6fkZc9/lights/1)
19:30:27 HTP: Hue Result ({"state":{"on":true,"alert":"none","effect":"none","reachable":true},"type":"Extended color light","name":"Kohlendioxid","modelid":"LCT007","uniqueid":"5c:cf:7f:71:c2:54:00:11-1","swversion":"5.50.1.19085"})
19:30:30 MQT: tele/sonoff-71C254/STATE = {"Time":"2019-04-26T19:30:30","Uptime":"0T00:02:14","Vcc":3.463,"SleepMode":"Dynamic","Sleep":50,"LoadAvg":19,"POWER":"ON","Wifi":{"AP":1,"SSId":"Jason_Home_WLAN","BSSId":"00:A0:57:2A:BD:19","Channel":9,"RSSI":92,"LinkCount":1,"Downtime":"0T00:00:04"}}
19:30:30 MQT: tele/sonoff-71C254/SENSOR = {"Time":"2019-04-26T19:30:30","MHZ19B":{"Model":"B","CarbonDioxide":969,"Temperature":24.0},"TempUnit":"C"}
19:30:30 HTP: Hue API (/vr0cFpv41CwnP3PpmyLwZaX0BtBARCMSNr6fkZc9/lights/1)
19:30:30 HTP: Hue Result ({"state":{"on":true,"alert":"none","effect":"none","reachable":true},"type":"Extended color light","name":"Kohlendioxid","modelid":"LCT007","uniqueid":"5c:cf:7f:71:c2:54:00:11-1","swversion":"5.50.1.19085"})
19:30:33 HTP: Hue API (/vr0cFpv41CwnP3PpmyLwZaX0BtBARCMSNr6fkZc9/lights/1)
19:30:33 HTP: Hue Result ({"state":{"on":true,"alert":"none","effect":"none","reachable":true},"type":"Extended color light","name":"Kohlendioxid","modelid":"LCT007","uniqueid":"5c:cf:7f:71:c2:54:00:11-1","swversion":"5.50.1.19085"})
19:30:35 DMP: FF 86 03 C9 40 00 2D 00 41
19:30:36 HTP: Hue API (/vr0cFpv41CwnP3PpmyLwZaX0BtBARCMSNr6fkZc9/lights/1)
19:30:36 HTP: Hue Result ({"state":{"on":true,"alert":"none","effect":"none","reachable":true},"type":"Extended color light","name":"Kohlendioxid","modelid":"LCT007","uniqueid":"5c:cf:7f:71:c2:54:00:11-1","swversion":"5.50.1.19085"})
19:30:37 UDP: Packet (199)
19:30:37 UDP: Packet (199)
19:30:37 UDP: Packet (199)
19:30:37 UDP: Packet (199)
19:30:37 UDP: Packet (199)
19:30:37 UDP: Packet (199)
19:30:37 UDP: Packet (199)
19:30:37 UDP: Packet (199)
19:30:37 UDP: Packet (199)
19:30:37 UDP: Packet (199)
19:30:39 HTP: Hue API (/vr0cFpv41CwnP3PpmyLwZaX0BtBARCMSNr6fkZc9/lights/1)
19:30:39 HTP: Hue Result ({"state":{"on":true,"alert":"none","effect":"none","reachable":true},"type":"Extended color light","name":"Kohlendioxid","modelid":"LCT007","uniqueid":"5c:cf:7f:71:c2:54:00:11-1","swversion":"5.50.1.19085"})
19:30:40 WIF: Checking connection...
19:30:40 WIF: Connected
19:30:42 HTP: Hue API (/vr0cFpv41CwnP3PpmyLwZaX0BtBARCMSNr6fkZc9/lights/1)
19:30:42 HTP: Hue Result ({"state":{"on":true,"alert":"none","effect":"none","reachable":true},"type":"Extended color light","name":"Kohlendioxid","modelid":"LCT007","uniqueid":"5c:cf:7f:71:c2:54:00:11-1","swversion":"5.50.1.19085"})


@s-hadinger
Copy link
Collaborator Author

Good news for color control. Thanks for testing promptly.

What are the symptoms with Sonoff Basic? It looks like Alexa is missing some information. I'm afraid that adding "Bri" will bring back the dimmer control.

Do you have a device with only a Dimmer control? ie only one PWM1.

@Jason2866
Copy link
Collaborator

Jason2866 commented Apr 26, 2019

Sonoff Basic: In Alexa App Error message text "Device doesnt respond"
A wemos mini with onboard LED. Worked fine for testing dimmer with Alexa...

@Jason2866
Copy link
Collaborator

Tried wemos mini with only one PWM1. Dimmer doesnt work on this device.
Has always full brightness. Slider in webfrontend has no impact in brightness of LED
Used this setting (does work with standard Tasmota version)
image

@s-hadinger
Copy link
Collaborator Author

I now have an Alexa back. I tested with a Sonoff Basic set-up and it works fine: the lamp does show in Alexa app and can be voice controlled (no dimmer). The only way I can reproduce your issue is to trigger a device discovery with a color device (like Arilux) and then switch Tasmota to Sonoff Basic.

Re-reading our first discussion on #5667 it seems the Dimmer is mandatory in your Alexa version. I will push back this shortly. The downside is that we will always see a dimmer even if it does not make sense.

@s-hadinger
Copy link
Collaborator Author

WIll look at single PWM issue tomorrow.

@s-hadinger
Copy link
Collaborator Author

I think I got the issue with only one PWM1.

I reported the code from sonoff/xdrv04_light.ino, lines 672-674:

  if (LT_PWM1 == light_type) {
    Settings.light_color[0] = 255;    // One PWM channel only supports Dimmer but needs max color
}

to new code line 687-688:

    } else if (LT_PWM1 == light_type) {
      light_current_color[0] = 255; // One PWM channel only supports Dimmer but needs max color

Actually I misunderstoof why this code was there in the first place, it was linked to dimmer calculation. It does not make sense anymore with the new implementation. Fix coming!

@Jason2866
Copy link
Collaborator

Good news for dimmer device.
Weired Sonoff Basic behaviour. I tested with real device. Never before was a other device defined.
Just previous versions of Tasmota.

@s-hadinger
Copy link
Collaborator Author

Fix ready for testing. Now Sonoff Basic should work but with a useless slider/dimmer.

@s-hadinger
Copy link
Collaborator Author

I can confirm:

  • Works with one PWM1 or PWM1i (Dinner)
  • Works with two PWM1+PWM2 (White Color tone)
  • Works with three PWM1+PWM2+PWM3 (RGB)

@s-hadinger
Copy link
Collaborator Author

I found a bug, command "CT" always returns 65437. Will look at it tomorrow.

@Jason2866
Copy link
Collaborator

Jason2866 commented Apr 27, 2019

Tested with Sonoff Basic -> works (again)
Tested with PWM1i wemos mini -> works
PWM1 + PWM2 -> one slider in Alexa, dont know if this is correct or not > Device works?
AiLight (RGB) -> works

Nice work!!

@s-hadinger
Copy link
Collaborator Author

Fixed CT command, better management of XY colors (would not reflect changes made outside of Hue commands).

@Jason2866 Do you have a cold/warm bulb? Currently Cold white would set 100% on Cold White leds, Warm white would set 100% of Warm white leds. But Medium white will set 50% on each led.

I'm wondering whether we should send 100% on both leds instead? Would that be too bright? Would that overload power supply of the bulb? Any thoughts?

@Jason2866
Copy link
Collaborator

Jason2866 commented Apr 28, 2019

Everything still working after last changes :-)
No i dont have a cold/warm bulb. Afaik both channels at 100% overloads power supply at some devices.
#4991 (comment)
Maybe @gsimon75 can help? You can take a look in his merged PR #4991
Testing your changes with a SM16716 driven bulb is a good idea too.
I think @gsimon75 can answer questions to bulbs in general. He did a lot of research too.

@gsimon75
Copy link
Contributor

gsimon75 commented Apr 28, 2019

A minor thing (I'll need to double-check it though): If I configure LOG_LEVEL_DEBUG to the *_LOG_LEVEL defines, then the bulb just keeps rebooting. With the defaults (_NONE and _INFO) it boots up fine.

Then I started to poke around a bit with the 'cmnd/sonoff/color' command at the web console, and I've found some strange behaviour. Maybe I'm doing something wrong, but it seems that the 'color' command just sets the hue+sat, the brightness is controlled by only the 'dimmer'. Here is what I tried.

Let's start with the smallest bit of red:

16:54:40 CMD: cmnd/sonoff/color 010000
16:54:40 RSL: stat/sonoff/RESULT = {"POWER":"ON","Dimmer":100,"Color":"FF00000000","HSBColor":"0,100,100","Channel":[100,0,0,0,0],"CT":0}

I expected a minimal red, got it at 100%

OK, lets change that R channel:

16:54:40 CMD: cmnd/sonoff/color 010000
16:54:40 RSL: stat/sonoff/RESULT = {"POWER":"ON","Dimmer":100,"Color":"FF00000000","HSBColor":"0,100,100","Channel":[100,0,0,0,0],"CT":0}

No change, red is doing its best...

16:57:27 CMD: cmnd/sonoff/dimmer 50
16:57:27 RSL: stat/sonoff/RESULT = {"POWER":"ON","Dimmer":50,"Color":"8000000000","HSBColor":"0,100,50","Channel":[50,0,0,0,0],"CT":0}

So, dimmer can lower the intensity, but it seems to override the brightness of the raw rgb data.

OK, let's try it with blue (dimmer still at 50!):

17:15:46 CMD: cmnd/sonoff/color 000001
17:15:46 RSL: stat/sonoff/RESULT = {"POWER":"ON","Dimmer":100,"Color":"0000FF0000","HSBColor":"240,100,100","Channel":[0,0,100,0,0],"CT":0}

It seems that whenever I set an rgb value, dimmer gets back to 100.

Cold white behaves like the other channels:

17:17:37 CMD: cmnd/sonoff/color 00000001
17:17:37 RSL: stat/sonoff/RESULT = {"POWER":"ON","Dimmer":100,"Color":"000000FF00","HSBColor":"0,0,100","Channel":[0,0,0,100,0],"CT":500}
17:17:43 CMD: dimmer 5
17:17:43 RSL: stat/sonoff/RESULT = {"POWER":"ON","Dimmer":5,"Color":"0000000D00","HSBColor":"0,0,5","Channel":[0,0,0,5,0],"CT":500}

Warm white the same:

17:18:32 CMD: cmnd/sonoff/color 0000000001
17:18:32 RSL: stat/sonoff/RESULT = {"POWER":"ON","Dimmer":100,"Color":"00000000FF","HSBColor":"0,0,100","Channel":[0,0,0,0,100],"CT":153}
17:18:37 CMD: dimmer 5
17:18:37 RSL: stat/sonoff/RESULT = {"POWER":"ON","Dimmer":5,"Color":"000000000D","HSBColor":"0,0,5","Channel":[0,0,0,0,5],"CT":153}

So the color command seems a bit strange.

@gsimon75
Copy link
Contributor

On the other hand, the ct command is just perfect:

17:21:45 CMD: cmnd/sonoff/ct 153
17:21:45 RSL: stat/sonoff/RESULT = {"POWER":"ON","Dimmer":100,"Color":"00000000FF","HSBColor":"0,0,100","Channel":[0,0,0,0,100],"CT":153}
17:21:50 CMD: cmnd/sonoff/ct 500
17:21:50 RSL: stat/sonoff/RESULT = {"POWER":"ON","Dimmer":100,"Color":"000000FF00","HSBColor":"0,0,100","Channel":[0,0,0,100,0],"CT":500}
17:21:56 CMD: cmnd/sonoff/ct 326
17:21:56 RSL: stat/sonoff/RESULT = {"POWER":"ON","Dimmer":100,"Color":"0000007F80","HSBColor":"0,0,100","Channel":[0,0,0,50,50],"CT":326}

As of the question about the mid-point, whether the cold and warm values should be 100% + 100% or 50% + 50%, I would vote for the 50+50 (as it is now), for two reasons:

  1. As @Jason2866 mentioned, the power supply in these bulbs (even in the original Sonoff ones) is somewhat under-designed, and if all channels are at maximum, then the voltage regulator overheats. This is a graph of the exterior temperature of two bulbs I set to 'FFFFFFFFFF', and a separate measurement showed over 90 Celsius at the regulator of the SYF05 model at the thermal shutdown point.

@kueblc has found that the original firmware never drives even the colour and the white leds at the same time, maybe for a similar reason.

  1. An aesthetical reason :). If you set some brightness and change the colour temperature only, you'd expect the brightness to stay the same, but in the 100+100 case the midpoint would be twice as bright as the coldest or the warmest setting.

These being said, I must confess that when I really need the brightest light the bulb can produce, I do open its console and send cmdn/sonoff/color ffffffffff :D, but only for a short period. So the 'brightest possible light' is indeed a valid use case, only that I don't know any safe way for it.

@mhightower83
Copy link

@Jason2866

No i dont have a cold/warm bulb. Afaik both channels at 100% overloads power supply at some devices.

I have accidentally confirmed, that if both cold and warm LEDs are at full power, the Feit 9W bulb will draw 18 watts. This is easy to do by using the slider to bring it to maximum brightness, with the initial firmware values for color. I think it is a safe bet, that the power and heat management design of a commodity bulb would not handle running at 200% of its advertised rating for long.

Before I realized what was going on power wise, I made the device unstable by having the RGB LEDs and the Cold and Warm LEDs on at the same time, it started flashing. The RGB LEDs by themselves draw around an additional 2-3 watts.

@s-hadinger
Copy link
Collaborator Author

Thanks, this is valuable feedback. I will dive into it tomorrow.

I need to do some small changes, the current PR does not allow to have both cold and warm white at 100%. I understand this should not be the default and keep it 50%-50% by default; but still offer the possibility to specify each PWM values.

About Color command, I falsely understood it would always reset dimmer to 100%. Afterthoughts, that should be only for "Color 1-12" and not when you specify RGB. Will correct it.

@s-hadinger
Copy link
Collaborator Author

Fixed the issue with Color command, thanks @gsimon75.

@gsimon75
Copy link
Contributor

I'll do a test build right away!

Meanwhile I've found the source of the reboots when LOG_LEVEL_DEBUG: support_rtc.ino. It's completely unrelated to your code, the problem most probably is that it's attached as a callback and the logging seems not to be reentrant, so if it's invoked during another log being processed, then we've got trouble. Anyway, it's a completely different issue, way out of scope of this PR.

@gsimon75
Copy link
Contributor

(Sorry for the delay, a soldering got loose and pried up the pcb pad, needed some patching with coil wire.)

The fix seems fine :D, as far as I can tell, color, dimmer and ct all work as expected, compatible with the baseline behaviour. Well done!

Just for completeness' sake I'll test it with an SM16716 bulb, too, but I don't expect too much differences.

@gsimon75
Copy link
Contributor

SM16716 works fine, color and dimmer perfect, ct not supported (being an rgbw-only bulb, that's expected).

So I think this PR is OK :) (and thanks for the great work at the refactoring, it improved a lot on the clarity of the code) !

@Jason2866
Copy link
Collaborator

@gsimon75 Thx for testing and your feedback
@s-hadinger Great Job done, thank you for making Tasmota better :-)

@arendst Could you please merge this PR? It is tested to work with Alexa as before
and the introduced new feature to control color via Alexa (HueEmulation) is so much fun!

@s-hadinger
Copy link
Collaborator Author

Thanks @Jason2866
There is one more thing I'd like to work on: a cleaner colormode toggle and allow for PWM4 and PWM5 at full power (it's currently limited to PWM4+PWM5=100%).

It's probably better to merge this PR and I will submit another one for this small change.

@arendst
Copy link
Owner

arendst commented Apr 29, 2019

Great to see your work while i'm on holiday in Portugal ;-)

@arendst arendst merged commit c0a4e08 into arendst:development Apr 29, 2019
@s-hadinger s-hadinger deleted the feature/refactored_light branch April 29, 2019 18:53
@RaymondMouthaan
Copy link

Thanks for building, testing and merging this PR guys 👍🏽🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants