Hello Everybody !
I'm a new user of node-red and I need some help about a project
I try to make my Connected Lamp Xiaomi yeelight reacting to an incoming notification on my android phone.
I have realised the code, he is working but there is such a little problem :
I have code a feature that make blink the light when she is off and vice versa shutdown it during a short time and then switch then on again. When the lamp is exctinct it works nice but when she is on it just shut down the light and never repower them...
In the debug window I have a thing like that :
On state --> Off state :
# code block
13/01/2019 à 13:09:18[node: d2d308bf.83c38](http://192.168.0.18:1880/#)
msg.payload : string[12]
"{"on": true}"
13/01/2019 à 13:09:21[node: d2d308bf.83c38](http://192.168.0.18:1880/#)
msg.payload : string[13]
"{"on": false}"
Off state --> On state :
# code block
13/01/2019 à 13:09:39[node: d2d308bf.83c38](http://192.168.0.18:1880/#)
msg.payload : string[13]
` "{"on": false}"`
13/01/2019 à 13:09:40[node: d2d308bf.83c38](http://192.168.0.18:1880/#)
msg.payload : string[13]
`"{"on": false}"`
Here is my flow and the node i'm using :
Flow
[{"id":"3e50c602.1c94ca","type":"tab","label":"Nofification trigger","disabled":false,"info":"A flow who blink shortly the Lamp when an notification\narrived on your phone.\nWork with On/Off State.\nAuthor : GridexX"},{"id":"4d78e92d.1362c8","type":"function","z":"3e50c602.1c94ca","name":"inverse power","func":"msg.payload = flow.get('pow');\nif (msg.payload===false) msg.payload='{\"on\": true}';\nelse msg.payload='{\"on\": false}';\nreturn msg;","outputs":1,"noerr":0,"x":1100,"y":680,"wires":[["d9fd4bd7.12fd78","4564cfa3.10991"]]},{"id":"6ed638a.9d06748","type":"switch","z":"3e50c602.1c94ca","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"1","vt":"num"}],"checkall":"true","repair":false,"outputs":1,"x":550,"y":660,"wires":[["92531e4b.a896c","cdc69864.95eed8"]]},{"id":"527d4ba4.18a0bc","type":"function","z":"3e50c602.1c94ca","name":"False","func":"return {payload : false};","outputs":1,"noerr":0,"x":410,"y":620,"wires":[["6ed638a.9d06748"]]},{"id":"db123eec.9cc358","type":"inject","z":"3e50c602.1c94ca","name":"Turn true","topic":"","payload":"true","payloadType":"bool","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":400,"y":700,"wires":[["6ed638a.9d06748"]]},{"id":"92531e4b.a896c","type":"yeelight-compat-hue-state","z":"3e50c602.1c94ca","name":"Get State","server":"1b82c79a.0adf18","x":530,"y":500,"wires":[["b079f31a.68535","527d4ba4.18a0bc"]]},{"id":"30bd23aa.abe554","type":"delay","z":"3e50c602.1c94ca","name":"","pauseType":"delay","timeout":"1","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":920,"y":680,"wires":[["4d78e92d.1362c8"]]},{"id":"d9fd4bd7.12fd78","type":"yeelight-compat-hue-out","z":"3e50c602.1c94ca","name":"","server":"1b82c79a.0adf18","x":1010,"y":880,"wires":[]},{"id":"cdc69864.95eed8","type":"function","z":"3e50c602.1c94ca","name":"get power","func":"msg.payload = flow.get('pow');\nif (msg.payload===true) msg.payload='{\"on\": false}';\nelse msg.payload='{\"on\": true}';\nreturn msg;","outputs":1,"noerr":0,"x":740,"y":680,"wires":[["30bd23aa.abe554","d9fd4bd7.12fd78","4564cfa3.10991"]]},{"id":"4564cfa3.10991","type":"debug","z":"3e50c602.1c94ca","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":1130,"y":800,"wires":[]},{"id":"b079f31a.68535","type":"function","z":"3e50c602.1c94ca","name":"Set State Flow","func":"var onState = msg.payload.state.on;\nflow.set('pow',onState);","outputs":1,"noerr":0,"x":800,"y":500,"wires":[[]]},{"id":"c59c61a1.b8c13","type":"function","z":"3e50c602.1c94ca","name":"Get Back State","func":"if(msg.payload===false) msg.payload='{\"on\": true}';\nelse msg.payload='{\"on\": false}';\nreturn msg;","outputs":1,"noerr":0,"x":1080,"y":1200,"wires":[["247acafc.6ac866","d2d308bf.83c38"]]},{"id":"5e9fcd8e.ac8f54","type":"inject","z":"3e50c602.1c94ca","name":"Get Notification","topic":"","payload":"true","payloadType":"bool","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":320,"y":1200,"wires":[["a6dfac85.b1ace8","4f47c7f1.744b9"]]},{"id":"a6dfac85.b1ace8","type":"yeelight-compat-hue-state","z":"3e50c602.1c94ca","name":"Get State","server":"1b82c79a.0adf18","x":510,"y":1060,"wires":[["67f02d96.dfef44"]]},{"id":"106de578.09a63b","type":"delay","z":"3e50c602.1c94ca","name":"","pauseType":"delay","timeout":"750","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":870,"y":1200,"wires":[["c59c61a1.b8c13"]]},{"id":"247acafc.6ac866","type":"yeelight-compat-hue-out","z":"3e50c602.1c94ca","name":"","server":"1b82c79a.0adf18","x":1210,"y":1120,"wires":[]},{"id":"4f47c7f1.744b9","type":"function","z":"3e50c602.1c94ca","name":"Inverse State","func":"msg.payload = flow.get('pow');\nif (msg.payload===true) msg.payload='{\"on\": false}';\nelse msg.payload='{\"on\": true}';\nreturn msg;","outputs":1,"noerr":0,"x":670,"y":1200,"wires":[["106de578.09a63b","247acafc.6ac866","d2d308bf.83c38"]]},{"id":"67f02d96.dfef44","type":"function","z":"3e50c602.1c94ca","name":"Set State Flow","func":"//send the state on the flow\nvar onState = msg.payload.state.on;\nflow.set('pow',onState);","outputs":1,"noerr":0,"x":760,"y":1060,"wires":[[]]},{"id":"d2d308bf.83c38","type":"debug","z":"3e50c602.1c94ca","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":1150,"y":1300,"wires":[]},{"id":"1b82c79a.0adf18","type":"yeelight-compat-hue-config","z":"","hostname":"192.168.0.34","port":"55443","name":"Smart Bulb RGBW"}]
If someone can help I will be greatfull