probonopd / ESP8266HueEmulator

Emulate a Philips Hue bridge running on an ESP8266 using the Arduino IDE.
MIT License
411 stars 93 forks source link

Add a semblance of scene support #48

Closed opticron closed 7 years ago

opticron commented 7 years ago

This adds all the plubming required to support scenes, but does not actually store the information necessary to apply them. This allows apps that require the scene api to interact with the emulated bridge without blowing up or taking up the additional memory required for proper support.

probonopd commented 7 years ago

Thanks @opticron will test it in a minute.

What do you think about https://github.com/probonopd/ESP8266HueEmulator/pull/46 and can you make it apply cleanly?

probonopd commented 7 years ago

I am getting with the Hue iOS app with the "colorful" icon

Starting SSDP...
SSDP Started
=== 83998
Method: GET
requestedUri: api/nouser/config
URI: config
83999
{"name":"hue emulator","swversion":"81012917","bridgeid":"xxxxxxxxxxxxxxxx","portalservices":false,"linkbutton":true,"mac":"xx:xx:xx:xx:xx:xxx","dhcp":true,"ipaddress":"192.168.0.16","netmask":"255.255.255.0","gateway":"192.168.0.1","apiversion":"1.3.0","whitelist":{"":{"name":"clientname#devicename"}},"swupdate":{"text":"","notify":false,"updatestate":0,"url":""}}
84027
=== 94055
Method: GET
requestedUri: api/nouser/config
URI: config
94056
{"name":"hue emulator","swversion":"81012917","bridgeid":"xxxxxxxxxxxxxxxx","portalservices":false,"linkbutton":true,"mac":"xx:xx:xx:xx:xx:xxx","dhcp":true,"ipaddress":"192.168.0.16","netmask":"255.255.255.0","gateway":"192.168.0.1","apiversion":"1.3.0","whitelist":{"":{"name":"clientname#devicename"}},"swupdate":{"text":"","notify":false,"updatestate":0,"url":""}}
94083
=== 94096
Method: GET
requestedUri: api/nouser/config
URI: config
94098
{"name":"hue emulator","swversion":"81012917","bridgeid":"xxxxxxxxxxxxxxxx","portalservices":false,"linkbutton":true,"mac":"xx:xx:xx:xx:xx:xxx","dhcp":true,"ipaddress":"192.168.0.16","netmask":"255.255.255.0","gateway":"192.168.0.1","apiversion":"1.3.0","whitelist":{"":{"name":"clientname#devicename"}},"swupdate":{"text":"","notify":false,"updatestate":0,"url":""}}
94125
=== 94174
Method: POST
requestedUri: api/
URI: 
CLIENT: 
api
94175
[{"success":{"username":"api"}}]
94176
=== 94234
Method: PUT
requestedUri: api/api/config
URI: config
94236
{"name":"hue emulator","swversion":"81012917","bridgeid":"xxxxxxxxxxxxxxxx","portalservices":false,"linkbutton":true,"mac":"xx:xx:xx:xx:xx:xxx","dhcp":true,"ipaddress":"192.168.0.16","netmask":"255.255.255.0","gateway":"192.168.0.1","apiversion":"1.3.0","whitelist":{"":{"name":"clientname#devicename"}},"swupdate":{"text":"","notify":false,"updatestate":0,"url":""}}
94263
=== 94294
Method: GET
requestedUri: api/api
URI: 
94300
{"groups":{},"scenes":{},"config":{"name":"hue emulator","swversion":"81012917","bridgeid":"xxxxxxxxxxxxxxxx","portalservices":false,"linkbutton":true,"mac":"xx:xx:xx:xx:xx:xxx","dhcp":true,"ipaddress":"192.168.0.16","netmask":"255.255.255.0","gateway":"192.168.0.1","apiversion":"1.3.0","whitelist":{"":{"name":"clientname#devicename"}},"swupdate":{"text":"","notify":false,"updatestate":0,"url":""}},"lights":{"1":{"type":"Extended color light","name":"Hue LightStrips 1","modelid":"LST001","state":{"on":false,"hue":0,"bri":0,"sat":0,"xy":[0.00000,0.00000],"ct":500,"alert":"none","effect":"none","colormode":"hs","reachable":true}},"2":{"type":"Extended color light","name":"Hue LightStrips 2","modelid":"LST001","state":{"on":false,"hue":0,"bri":0,"sat":0,"xy":[0.00000,0.00000],"ct":500,"alert":"none","effect":"none","colormode":"hs","reachable":true}},"3":{"type":"Extended color light","name":"Hue LightStrips 3","modelid":"LST001","state":{"on":false,"hue":0,"bri":0,"sat":0,"xy":[0.00000,0.00000],"ct":500,"alert":"none","effect":"none","colormode":"hs","reachable":true}},"4":{"type":"Extended color light","name":"Hue LightStrips 4","modelid":"LST001","state":{"on":false,"hue":0,"bri":0,"sat":0,"xy":[0.00000,0.00000],"ct":500,"alert":"none","effect":"none","colormode":"hs","reachable":true}},"5":{"type":"Extended color light","name":"Hue LightStrips 5","modelid":"LST001","state":{"on":false,"hue":0,"bri":0,"sat":0,"xy":[0.00000,0.00000],"ct":500,"alert":"none","effect":"none","colormode":"hs","reachable":true}},"6":{"type":"Extended color light","name":"Hue LightStrips 6","modelid":"LST001","state":{"on":false,"hue":0,"bri":0,"sat":0,"xy":[0.00000,0.00000],"ct":500,"alert":"none","effect":"none","colormode":"hs","reachable":true}}},"schedules":{}}
94445
=== 95259
Method: GET
requestedUri: api/api
URI: 
95265
{"groups":{},"scenes":{},"config":{"name":"hue emulator","swversion":"81012917","bridgeid":"xxxxxxxxxxxxxxxx","portalservices":false,"linkbutton":true,"mac":"xx:xx:xx:xx:xx:xxx","dhcp":true,"ipaddress":"192.168.0.16","netmask":"255.255.255.0","gateway":"192.168.0.1","apiversion":"1.3.0","whitelist":{"":{"name":"clientname#devicename"}},"swupdate":{"text":"","notify":false,"updatestate":0,"url":""}},"lights":{"1":{"type":"Extended color light","name":"Hue LightStrips 1","modelid":"LST001","state":{"on":false,"hue":0,"bri":0,"sat":0,"xy":[0.00000,0.00000],"ct":500,"alert":"none","effect":"none","colormode":"hs","reachable":true}},"2":{"type":"Extended color light","name":"Hue LightStrips 2","modelid":"LST001","state":{"on":false,"hue":0,"bri":0,"sat":0,"xy":[0.00000,0.00000],"ct":500,"alert":"none","effect":"none","colormode":"hs","reachable":true}},"3":{"type":"Extended color light","name":"Hue LightStrips 3","modelid":"LST001","state":{"on":false,"hue":0,"bri":0,"sat":0,"xy":[0.00000,0.00000],"ct":500,"alert":"none","effect":"none","colormode":"hs","reachable":true}},"4":{"type":"Extended color light","name":"Hue LightStrips 4","modelid":"LST001","state":{"on":false,"hue":0,"bri":0,"sat":0,"xy":[0.00000,0.00000],"ct":500,"alert":"none","effect":"none","colormode":"hs","reachable":true}},"5":{"type":"Extended color light","name":"Hue LightStrips 5","modelid":"LST001","state":{"on":false,"hue":0,"bri":0,"sat":0,"xy":[0.00000,0.00000],"ct":500,"alert":"none","effect":"none","colormode":"hs","reachable":true}},"6":{"type":"Extended color light","name":"Hue LightStrips 6","modelid":"LST001","state":{"on":false,"hue":0,"bri":0,"sat":0,"xy":[0.00000,0.00000],"ct":500,"alert":"none","effect":"none","colormode":"hs","reachable":true}}},"schedules":{}}
95410
=== 95823
Method: GET
requestedUri: api/api/config
URI: config
95824
{"name":"hue emulator","swversion":"81012917","bridgeid":"xxxxxxxxxxxxxxxx","portalservices":false,"linkbutton":true,"mac":"xx:xx:xx:xx:xx:xxx","dhcp":true,"ipaddress":"192.168.0.16","netmask":"255.255.255.0","gateway":"192.168.0.1","apiversion":"1.3.0","whitelist":{"":{"name":"clientname#devicename"}},"swupdate":{"text":"","notify":false,"updatestate":0,"url":""}}
95851
=== 98001
Method: GET
requestedUri: api/api/config
URI: config
98002
{"name":"hue emulator","swversion":"81012917","bridgeid":"xxxxxxxxxxxxxxxx","portalservices":false,"linkbutton":true,"mac":"xx:xx:xx:xx:xx:xxx","dhcp":true,"ipaddress":"192.168.0.16","netmask":"255.255.255.0","gateway":"192.168.0.1","apiversion":"1.3.0","whitelist":{"":{"name":"clientname#devicename"}},"swupdate":{"text":"","notify":false,"updatestate":0,"url":""}}
98029
=== 100007
Method: GET
requestedUri: api/api/config
URI: config
100009
{"name":"hue emulator","swversion":"81012917","bridgeid":"xxxxxxxxxxxxxxxx","portalservices":false,"linkbutton":true,"mac":"xx:xx:xx:xx:xx:xxx","dhcp":true,"ipaddress":"192.168.0.16","netmask":"255.255.255.0","gateway":"192.168.0.1","apiversion":"1.3.0","whitelist":{"":{"name":"clientname#devicename"}},"swupdate":{"text":"","notify":false,"updatestate":0,"url":""}}
100036
=== 100504
Method: GET
requestedUri: api/api
URI: 
100509
{"groups":{},"scenes":{},"config":{"name":"hue emulator","swversion":"81012917","bridgeid":"xxxxxxxxxxxxxxxx","portalservices":false,"linkbutton":true,"mac":"xx:xx:xx:xx:xx:xxx","dhcp":true,"ipaddress":"192.168.0.16","netmask":"255.255.255.0","gateway":"192.168.0.1","apiversion":"1.3.0","whitelist":{"":{"name":"clientname#devicename"}},"swupdate":{"text":"","notify":false,"updatestate":0,"url":""}},"lights":{"1":{"type":"Extended color light","name":"Hue LightStrips 1","modelid":"LST001","state":{"on":false,"hue":0,"bri":0,"sat":0,"xy":[0.00000,0.00000],"ct":500,"alert":"none","effect":"none","colormode":"hs","reachable":true}},"2":{"type":"Extended color light","name":"Hue LightStrips 2","modelid":"LST001","state":{"on":false,"hue":0,"bri":0,"sat":0,"xy":[0.00000,0.00000],"ct":500,"alert":"none","effect":"none","colormode":"hs","reachable":true}},"3":{"type":"Extended color light","name":"Hue LightStrips 3","modelid":"LST001","state":{"on":false,"hue":0,"bri":0,"sat":0,"xy":[0.00000,0.00000],"ct":500,"alert":"none","effect":"none","colormode":"hs","reachable":true}},"4":{"type":"Extended color light","name":"Hue LightStrips 4","modelid":"LST001","state":{"on":false,"hue":0,"bri":0,"sat":0,"xy":[0.00000,0.00000],"ct":500,"alert":"none","effect":"none","colormode":"hs","reachable":true}},"5":{"type":"Extended color light","name":"Hue LightStrips 5","modelid":"LST001","state":{"on":false,"hue":0,"bri":0,"sat":0,"xy":[0.00000,0.00000],"ct":500,"alert":"none","effect":"none","colormode":"hs","reachable":true}},"6":{"type":"Extended color light","name":"Hue LightStrips 6","modelid":"LST001","state":{"on":false,"hue":0,"bri":0,"sat":0,"xy":[0.00000,0.00000],"ct":500,"alert":"none","effect":"none","colormode":"hs","reachable":true}}},"schedules":{}}
100654
=== 101117
Method: GET
requestedUri: api/api/config
URI: config
101118
{"name":"hue emulator","swversion":"81012917","bridgeid":"xxxxxxxxxxxxxxxx","portalservices":false,"linkbutton":true,"mac":"xx:xx:xx:xx:xx:xxx","dhcp":true,"ipaddress":"192.168.0.16","netmask":"255.255.255.0","gateway":"192.168.0.1","apiversion":"1.3.0","whitelist":{"":{"name":"clientname#devicename"}},"swupdate":{"text":"","notify":false,"updatestate":0,"url":""}}
101145
=== 125284
Method: POST
requestedUri: api/api/groups
URI: groups
JSON Body:{"name":"Esp","lights":["1"],"type":"Room","class":"Living room"}
125287
[{"success":{"id":"1"}}]
125290
=== 125589
Method: POST
requestedUri: api/api/scenes
URI: scenes
JSON Body:{"name":"Entspannen","lights":["1"]}
125591
[{"success":{"id":""}}]
125592
=== 125620
Method: POST
requestedUri: api/api/scenes
URI: scenes
JSON Body:{"name":"Lesen","lights":["1"]}
125622
[{"success":{"id":""}}]
125623
=== 125649
Method: POST
requestedUri: api/api/scenes
URI: scenes
JSON Body:{"name":"Konzentration","lights":["1"]}
125651
[{"success":{"id":""}}]
125653
=== 125676
Method: POST
requestedUri: api/api/scenes
URI: scenes
JSON Body:{"name":"Aktivieren","lights":["1"]}
125677
[{"success":{"id":""}}]
125679
=== 125706
Method: POST
requestedUri: api/api/scenes
URI: scenes
JSON Body:{"name":"Hell","lights":["1"]}
125708
[{"success":{"id":""}}]
125709
=== 125739
Method: POST
requestedUri: api/api/scenes
URI: scenes
JSON Body:{"name":"Gedimmt","lights":["1"]}
125740
[{"success":{"id":""}}]
125742
=== 125767
Method: POST
requestedUri: api/api/scenes
URI: scenes
JSON Body:{"name":"Nachtlicht","lights":["1"]}
125768
[{"success":{"id":""}}]
125770
=== 125800
Method: POST
requestedUri: api/api/scenes
URI: scenes
JSON Body:{"name":"Sonnenuntergang Savanne","lights":["1"]}
125802
[{"success":{"id":""}}]
125805
=== 125830
Method: POST
requestedUri: api/api/scenes
URI: scenes
JSON Body:{"name":"Tropend��mmerung","lights":["1"]}
125832
[{"success":{"id":""}}]
125834
=== 125860
Method: POST
requestedUri: api/api/scenes
URI: scenes
JSON Body:{"name":"Nordlichter","lights":["1"]}
125861
[{"success":{"id":""}}]
125863
=== 125893
Method: POST
requestedUri: api/api/scenes
URI: scenes
JSON Body:{"name":"Frühlingsblüten","lights":["1"]}
125895
[{"success":{"id":""}}]
125897
=== 125927
Method: PUT
requestedUri: api/api/scenes/lights/1/state
URI: scenes/lights/1/state
125928
=== 128153
Method: GET
requestedUri: api/api/config
URI: config
128154
{"name":"hue emulator","swversion":"81012917","bridgeid":"xxxxxxxxxxxxxxxx","portalservices":false,"linkbutton":true,"mac":"xx:xx:xx:xx:xx:xxx","dhcp":true,"ipaddress":"192.168.0.16","netmask":"255.255.255.0","gateway":"192.168.0.1","apiversion":"1.3.0","whitelist":{"":{"name":"clientname#devicename"}},"swupdate":{"text":"","notify":false,"updatestate":0,"url":""}}
128181

## seems to be stalled here

The app says "saving can take some time..." but actually it takes forever and I have to kill the app...

probonopd commented 7 years ago

The iOS app with the non-colorful icon actually does find the emulated bridge and connect to it!

opticron commented 7 years ago

I see the issue. I'll submit a new PR with the POST scene creation sans scene ID fix.

probonopd commented 7 years ago

The iOS app with the non-colorful icon actually does find the emulated bridge and connect to it nowadays seems to use scenes for almost everything; so if I select a color and wait for a couple of seconds, then the color in the app gets reset to the original one...

EDIT: If I create a new scene with only one lamp in it, then i seem to be able to control it.