Transition of light does not work after `split` node

I’m trying to save states for my lights to create a scene using this example:
https://zachowj.github.io/node-red-contrib-home-assistant-websocket/cookbook/saving-and-restoring-states.html

I’ve tried using the scene approach and that does not work. I’ve also tried saving the state in the context, but that does not make any difference.

Flow that does work but the lights do not dim down using transition. The change is immediate. Notice that I set the transition duration in the transform data node

[{"id":"d9d0df36971e80d2","type":"ha-get-entities","z":"c085bc6e0d844dad","name":"Get States","server":"8406d051c9cf8e4b","version":0,"rules":[{"property":"entity_id","logic":"starts_with","value":"light.office_light","valueType":"str"}],"output_type":"array","output_empty_results":false,"output_location_type":"msg","output_location":"payload","output_results_count":1,"x":1130,"y":480,"wires":[["4c6a3ad579066549"]]},{"id":"dc89b834773f6e83","type":"inject","z":"c085bc6e0d844dad","name":"Store states","props":[{"p":"payload","v":"","vt":"date"},{"p":"topic","v":"","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":954,"y":480,"wires":[["d9d0df36971e80d2"]]},{"id":"7331b56b10683c60","type":"comment","z":"c085bc6e0d844dad","name":"How I would do store states","info":"","x":988,"y":432,"wires":[]},{"id":"4c6a3ad579066549","type":"function","z":"c085bc6e0d844dad","name":"transform data","func":"const entities = msg.payload.map((e) => {\n    const domain = e.entity_id.split('.')[0];\n    const payload = {};\n\n    switch(domain) {\n        case 'switch':\n        case 'light':\n            payload.domain = domain;\n            payload.service = `turn_${e.state}`;\n            //payload.entity_id = e.entity_id\n            payload.data = { \n                entity_id: e.entity_id,\n                brightness: e.attributes.brightness,\n                //brightness_pct: Math.round((e.attributes.brightness / 255) * 100),\n                color_temp: e.attributes.color_temp,\n                //flash: 'short'\n                transition: 3,\n            };\n            break;\n        case 'climate':\n            payload.domain = 'climate';\n            payload.service = `set_temperature`;\n            payload.data = {\n                entity_id: e.entity_id,\n                temperature: e.attributes.temperature,\n                target_temp_low: e.attributes.min_temp,\n                target_temp_high: e.attributes.max_temp,\n                operation_mode: e.attributes.operation_mode\n            };\n            break;\n    }\n    return payload;\n});\n// Save the states\nflow.set('savedStates', entities);\n\n// create a blank message object with out new payload\nmsg = { payload: entities };\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1316,"y":480,"wires":[["b1ab8e4ba2193f52"]]},{"id":"b1ab8e4ba2193f52","type":"debug","z":"c085bc6e0d844dad","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":1482,"y":480,"wires":[]},{"id":"ab90e938.1eff18","type":"inject","z":"c085bc6e0d844dad","name":"Restore states","repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":950,"y":340,"wires":[["a5a0930.ed3ae7"]]},{"id":"a5a0930.ed3ae7","type":"change","z":"c085bc6e0d844dad","name":"Get Saved States","rules":[{"t":"set","p":"payload","pt":"msg","to":"savedStates","tot":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":1146,"y":340,"wires":[["6247c7cf.5cb858"]]},{"id":"6247c7cf.5cb858","type":"split","z":"c085bc6e0d844dad","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":1310,"y":340,"wires":[["817d939de77b7a6b","0de9cc8ae25b0e89"]]},{"id":"817d939de77b7a6b","type":"debug","z":"c085bc6e0d844dad","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":1610,"y":360,"wires":[]},{"id":"0de9cc8ae25b0e89","type":"api-call-service","z":"c085bc6e0d844dad","name":"Restore State","server":"8406d051c9cf8e4b","version":3,"debugenabled":false,"service_domain":"","service":"","entityId":"","data":"","dataType":"json","mergecontext":"","mustacheAltTags":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"data"}],"queue":"none","x":1500,"y":260,"wires":[[]]},{"id":"9b04c42100f8ce7d","type":"comment","z":"c085bc6e0d844dad","name":"Restore states","info":"","x":930,"y":280,"wires":[]},{"id":"8406d051c9cf8e4b","type":"server","name":"Home Assistant","version":2,"addon":false,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true,"heartbeat":false,"heartbeatInterval":"30"}]

If I do a simple flow like below the transition works as expected. Any ideas?

[{"id":"c0c77aca44475533","type":"api-call-service","z":"c085bc6e0d844dad","name":"Fade down lamp","server":"8406d051c9cf8e4b","version":3,"debugenabled":false,"service_domain":"light","service":"turn_on","entityId":"light.office_light_1","data":"{\"brightness\":50,\"transition\":2}","dataType":"json","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":1170,"y":580,"wires":[[]]},{"id":"127885b4ce9adff8","type":"inject","z":"c085bc6e0d844dad","name":"fade down","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payloadType":"date","x":900,"y":580,"wires":[["c0c77aca44475533"]]},{"id":"8406d051c9cf8e4b","type":"server","name":"Home Assistant","version":2,"addon":false,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true,"heartbeat":false,"heartbeatInterval":"30"}]

Below is a good example of the issue.

[{"id":"1087e5e65fdfaf5d","type":"api-call-service","z":"c085bc6e0d844dad","name":"Snapshot Entities","server":"8406d051c9cf8e4b","version":3,"debugenabled":false,"service_domain":"scene","service":"create","entityId":"","data":"{\"scene_id\":\"before\",\"snapshot_entities\":[\"light.office_light_3\"]}","dataType":"json","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":1178,"y":120,"wires":[["f40e3131284c521b"]]},{"id":"f40e3131284c521b","type":"api-call-service","z":"c085bc6e0d844dad","name":"Change entities","server":"8406d051c9cf8e4b","version":3,"debugenabled":false,"service_domain":"light","service":"turn_on","entityId":"light.office_light_3","data":"{\"rgb_color\":[255,0,0],\"brightness\":50,\"transition\":3}","dataType":"json","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":1376,"y":120,"wires":[["ba354bc1be4da627"]]},{"id":"ba354bc1be4da627","type":"delay","z":"c085bc6e0d844dad","name":"","pauseType":"delay","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"outputs":1,"x":1548,"y":120,"wires":[["497d0a5e89ab2086"]]},{"id":"497d0a5e89ab2086","type":"api-call-service","z":"c085bc6e0d844dad","name":"Restore Entities State","server":"8406d051c9cf8e4b","version":3,"debugenabled":false,"service_domain":"scene","service":"turn_on","entityId":"scene.before","data":"{\"transition\":4}","dataType":"json","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":1732,"y":120,"wires":[[]]},{"id":"996a1a956b59e72d","type":"inject","z":"c085bc6e0d844dad","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":840,"y":200,"wires":[["1087e5e65fdfaf5d"]]},{"id":"8406d051c9cf8e4b","type":"server","name":"Home Assistant Myrmalm","version":2,"addon":false,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true,"heartbeat":false,"heartbeatInterval":"30"}]

The transition works in the “Change entities” node, but after the delay and the scene is applied no transition is used. It resets to the correct state though.

If I fake the fade down before the split node the transition works. If I put the fake fade down after the split node the transition doesn’t work. Isn’t that weird?

So I solved this finally.

For some reason the color_temp attribute in the Store states flow disables the animation. If I remove that attribute it works as expected.

Updated flow

[{"id":"d9d0df36971e80d2","type":"ha-get-entities","z":"c085bc6e0d844dad","name":"Get States","server":"8406d051c9cf8e4b","version":0,"rules":[{"property":"entity_id","logic":"starts_with","value":"light.office_light","valueType":"str"}],"output_type":"array","output_empty_results":false,"output_location_type":"msg","output_location":"payload","output_results_count":1,"x":1130,"y":480,"wires":[["4c6a3ad579066549"]]},{"id":"dc89b834773f6e83","type":"inject","z":"c085bc6e0d844dad","name":"Store states","props":[{"p":"payload","v":"","vt":"date"},{"p":"topic","v":"","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":954,"y":480,"wires":[["d9d0df36971e80d2"]]},{"id":"7331b56b10683c60","type":"comment","z":"c085bc6e0d844dad","name":"How I would do store states","info":"","x":988,"y":432,"wires":[]},{"id":"4c6a3ad579066549","type":"function","z":"c085bc6e0d844dad","name":"transform data","func":"const entities = msg.payload.map((e) => {\n    const domain = e.entity_id.split('.')[0];\n    const payload = {};\n\n    switch(domain) {\n        case 'switch':\n        case 'light':\n            payload.domain = domain;\n            payload.service = `turn_on`;\n            //payload.transition = 4;\n            //payload.entity_id = e.entity_id\n            // const extras = {\n            //     entity_id: e.entity_id,\n            //     transition: 3\n            // }\n            // payload.data = {...e.attributes, ...extras}\n            payload.data = {\n                //transition: 3,\n                entity_id: e.entity_id,\n                brightness: e.attributes.brightness,\n                //brightness_pct: Math.round((e.attributes.brightness / 255) * 100),\n                //color_temp: e.attributes.color_temp,\n                //flash: 'short'\n            };\n            break;\n        case 'climate':\n            payload.domain = 'climate';\n            payload.service = `set_temperature`;\n            payload.data = {\n                entity_id: e.entity_id,\n                temperature: e.attributes.temperature,\n                target_temp_low: e.attributes.min_temp,\n                target_temp_high: e.attributes.max_temp,\n                operation_mode: e.attributes.operation_mode\n            };\n            break;\n    }\n    return payload;\n});\n// Save the states\nflow.set('savedStates', entities);\n\n// create a blank message object with out new payload\nmsg = { payload: entities };\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1316,"y":480,"wires":[["b1ab8e4ba2193f52"]]},{"id":"b1ab8e4ba2193f52","type":"debug","z":"c085bc6e0d844dad","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":1482,"y":480,"wires":[]},{"id":"ab90e938.1eff18","type":"inject","z":"c085bc6e0d844dad","name":"Restore states","repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":950,"y":340,"wires":[["01ea349d21b30284"]]},{"id":"6247c7cf.5cb858","type":"split","z":"c085bc6e0d844dad","name":"","splt":" ","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":true,"addname":"topic","x":1350,"y":340,"wires":[["1876979c1ace20c7"]]},{"id":"9b04c42100f8ce7d","type":"comment","z":"c085bc6e0d844dad","name":"Restore states","info":"","x":930,"y":280,"wires":[]},{"id":"01ea349d21b30284","type":"change","z":"c085bc6e0d844dad","name":"Get Saved States","rules":[{"t":"set","p":"payload","pt":"msg","to":"savedStates","tot":"flow","dc":true}],"action":"","property":"","from":"","to":"","reg":false,"x":1170,"y":340,"wires":[["6247c7cf.5cb858"]]},{"id":"1876979c1ace20c7","type":"api-call-service","z":"c085bc6e0d844dad","name":"Restore State","server":"8406d051c9cf8e4b","version":3,"debugenabled":true,"service_domain":"","service":"","entityId":"","data":"{\"transition\":3}","dataType":"json","mergecontext":"","mustacheAltTags":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"data"}],"queue":"all","x":1560,"y":340,"wires":[[]]},{"id":"8406d051c9cf8e4b","type":"server","name":"Home Assistant Myrmalm","version":2,"addon":false,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true,"heartbeat":false,"heartbeatInterval":"30"}]
1 Like