Hello good people. I am trying to do something very similar: When i walk into my bedroom a motion detector should trigger a brightness/color change (go to full brighness, white light) and if no motion is detected, go back to the previous state of the light after 2min.
Since i am using Ikea Tradfri lights that cannot process two commands at a time, there is a subflow that splits the message containing the info into bits and sends it to the light with some delays in between. You can see how the expected message going into the subflow should look like in the “bedroom”-change node.
Now i constructed the below Flow, also adding brightness as a reset-value. However the reset is not working. Any ideas on how i should proceed? I suspect the way Kermit’s change & function nodes construct de msg does not play well with my subflow for the Tradfri lights. However i am by far too new to Node-Red to understand exactly what is wrong…
[{"id":"20b81b5b.682884","type":"subflow","name":"Tradfri light color","info":"","category":"","in":[{"x":40,"y":100,"wires":[{"id":"cfd6ffb7.b8e4e"}]}],"out":[],"env":[],"color":"#DDAA99"},{"id":"9f086959.46c608","type":"api-call-service","z":"20b81b5b.682884","name":"Turn on lights","server":"b805682b.1077a8","version":1,"debugenabled":false,"service_domain":"light","service":"turn_on","entityId":"","data":"{\"transition\":1}","dataType":"json","mergecontext":"","output_location":"payload","output_location_type":"msg","mustacheAltTags":false,"x":420,"y":60,"wires":[[]]},{"id":"5c5cbc36.782294","type":"api-call-service","z":"20b81b5b.682884","name":"Set color","server":"b805682b.1077a8","version":1,"debugenabled":false,"service_domain":"light","service":"turn_on","entityId":"","data":"{\"transition\":2}","dataType":"json","mergecontext":"","output_location":"payload","output_location_type":"msg","mustacheAltTags":false,"x":540,"y":120,"wires":[[]]},{"id":"2c870fe0.7aef","type":"delay","z":"20b81b5b.682884","name":"","pauseType":"delay","timeout":"2","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":400,"y":120,"wires":[["5c5cbc36.782294"]]},{"id":"cfd6ffb7.b8e4e","type":"function","z":"20b81b5b.682884","name":"Split payload","func":"br = {\n payload: {\n data: {\n entity_id: msg.payload.entity_id,\n brightness_pct: msg.payload.brightness_pct\n }\n }\n}\n\ncolor = {\n payload: {\n data: {\n entity_id: msg.payload.entity_id,\n rgb_color: msg.payload.rgb_color\n }\n }\n}\n\nwarmth = {\n payload: {\n data: {\n entity_id: msg.payload.entity_id,\n color_temp: msg.payload.color_temp\n }\n }\n}\n\nreturn [br, color, warmth]\n","outputs":3,"noerr":0,"x":170,"y":100,"wires":[["9f086959.46c608"],["2c870fe0.7aef"],[]]},{"id":"189edc3e.c7cb14","type":"server-state-changed","z":"9a07763e.6bef38","name":"bedroom motion","server":"b805682b.1077a8","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"binary_sensor.presence_7","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"output_only_on_state_change":true,"x":200,"y":1320,"wires":[["2310bce9.f4eb34"]]},{"id":"2640d8cc.2bd6c8","type":"change","z":"9a07763e.6bef38","name":"","rules":[{"t":"set","p":"prevState.state","pt":"msg","to":"data.state","tot":"msg"},{"t":"set","p":"prevState.color","pt":"msg","to":"rgb_color","tot":"str"},{"t":"set","p":"prevState.brightness","pt":"msg","to":"brightness_pct","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":720,"y":1320,"wires":[["b9cd1d6e.68f9f","1774f3c8.ef5cfc"]]},{"id":"d06a06d7.ab9878","type":"function","z":"9a07763e.6bef38","name":"Set Previous State","func":"msg.payload = {\n domain: msg.payload.domain,\n service: `turn_${msg.prevState.state}`,\n data: {\n entity_id: msg.payload.data.entity_id,\n rgb_color: msg.prevState.color,\n brightness_pct:prevState.brightness\n }\n};\n\nreturn msg;","outputs":1,"noerr":0,"x":1130,"y":1380,"wires":[["fea1a2d6.cb4c2"]]},{"id":"2310bce9.f4eb34","type":"api-current-state","z":"9a07763e.6bef38","name":"","server":"b805682b.1077a8","version":1,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"light.bedroom_mood","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":460,"y":1320,"wires":[["2640d8cc.2bd6c8"]]},{"id":"b9cd1d6e.68f9f","type":"change","z":"9a07763e.6bef38","name":"bedroom","rules":[{"t":"set","p":"payload","pt":"msg","to":"{\"entity_id\":\"light.bedroom_mood\",\"rgb_color\":[255,255,200],\"brightness_pct\":100}","tot":"json"}],"action":"","property":"","from":"","to":"","reg":false,"x":940,"y":1280,"wires":[["d37b1c92.c44a5"]]},{"id":"1774f3c8.ef5cfc","type":"delay","z":"9a07763e.6bef38","name":"","pauseType":"delay","timeout":"2","timeoutUnits":"minutes","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":940,"y":1380,"wires":[["d06a06d7.ab9878"]]},{"id":"fea1a2d6.cb4c2","type":"subflow:20b81b5b.682884","z":"9a07763e.6bef38","name":"Tradfri light color","env":[],"x":1350,"y":1380,"wires":[]},{"id":"d37b1c92.c44a5","type":"subflow:20b81b5b.682884","z":"9a07763e.6bef38","name":"Tradfri light color","env":[],"x":1350,"y":1280,"wires":[]},{"id":"b805682b.1077a8","type":"server","z":"","name":"Home Assistant","legacy":false,"hassio":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true}]