Not really tested all that much but example 1 shows creating real entities in HA and the second shows creating temp ones that will disappear after a HA reset and will only appear again after their state changes.
[{"id":"d5c4ef79.0c564","type":"ha-api","z":"b28195ad.c495e8","name":"Register Sensor","debugenabled":false,"protocol":"websocket","method":"get","path":"","data":"","dataType":"json","location":"here","locationType":"msg","responseType":"json","x":912,"y":112,"wires":[["6cba3632.d10ad8"]]},{"id":"d872791e.7e3db8","type":"server-events","z":"b28195ad.c495e8","name":"","event_type":"home_assistant_client","exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"waitForRunning":true,"x":168,"y":112,"wires":[["cab5b48c.7d4408"]]},{"id":"9ddb7a33.f8dad8","type":"ha-api","z":"b28195ad.c495e8","name":"Update Sensor","debugenabled":true,"protocol":"websocket","method":"get","path":"","data":"","dataType":"json","location":"payload","locationType":"msg","responseType":"json","x":912,"y":208,"wires":[[]]},{"id":"3066ba37.c8ef16","type":"comment","z":"b28195ad.c495e8","name":"Register Sensors","info":"","x":128,"y":64,"wires":[]},{"id":"9df1457d.2665c8","type":"comment","z":"b28195ad.c495e8","name":"Update Sensors","info":"","x":128,"y":160,"wires":[]},{"id":"cab5b48c.7d4408","type":"switch","z":"b28195ad.c495e8","name":"running?","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"running","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":364,"y":112,"wires":[["28c3215c.c54dce"]]},{"id":"fe75725c.0db45","type":"comment","z":"b28195ad.c495e8","name":"Update Sensors after registering them","info":"","x":518,"y":160,"wires":[]},{"id":"a158770b.9ec218","type":"ha-get-entities","z":"b28195ad.c495e8","name":"get all lights","rules":[{"property":"entity_id","logic":"starts_with","value":"light.","valueType":"str"}],"output_type":"split","output_empty_results":false,"output_location_type":"msg","output_location":"payload","output_results_count":1,"x":582,"y":112,"wires":[["cb2f3f76.c36ce"]]},{"id":"cb2f3f76.c36ce","type":"function","z":"b28195ad.c495e8","name":"","func":"const id = msg.payload.entity_id.split(\".\")[1];\nconst node_id = `${id}_brightness`;\nconst name = msg.payload.attributes.friendly_name ? `${msg.payload.attributes.friendly_name} Brightness` : `${id.replace(\"_\", \" \")} brightness`;\n\nmsg.data = msg.payload;\nmsg.payload = {\n data: {\n type:\"nodered/discovery\",\n component: \"sensor\",\n server_id: \"home\",\n node_id,\n config: {\n name\n }\n }\n};\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":748,"y":112,"wires":[["d5c4ef79.0c564"]]},{"id":"28c3215c.c54dce","type":"change","z":"b28195ad.c495e8","name":"","rules":[{"t":"delete","p":"createdEntities","pt":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":463,"y":112,"wires":[["a158770b.9ec218"]],"l":false},{"id":"6cba3632.d10ad8","type":"function","z":"b28195ad.c495e8","name":"","func":"const id = msg.data.entity_id.split(\".\")[1];\nconst node_id = `${id}_brightness`;\nconst name = msg.data.attributes.friendly_name ? `${msg.data.attributes.friendly_name} Brightness` : `${id.replace(\"_\", \" \")} brightness`;\nconst brightness = msg.data.state !== \"on\" ? 0 : (msg.data.attributes.brightness || 0);\n\nmsg.payload = {\n data: {\n type:\"nodered/entity\",\n server_id: \"home\",\t \n node_id,\n state: brightness\n }\n};\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":748,"y":208,"wires":[["9ddb7a33.f8dad8"]]},{"id":"1c0038cc.619de7","type":"server-state-changed","z":"b28195ad.c495e8","name":"","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"^light\\.(?!.*\\_brightness$).*","entityidfiltertype":"regex","outputinitially":false,"state_type":"str","haltifstate":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"output_only_on_state_change":false,"for":0,"forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"x":208,"y":208,"wires":[["8c2a719c.02828"]]},{"id":"8c2a719c.02828","type":"change","z":"b28195ad.c495e8","name":"","rules":[{"t":"set","p":"data","pt":"msg","to":"msg.data.new_state","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":463,"y":208,"wires":[["6cba3632.d10ad8"]],"l":false}]
[{"id":"a0279b06.8882a8","type":"function","z":"b28195ad.c495e8","name":"","func":"const e = msg.data.new_state;\nconst state = e.state !== \"on\" ? 0 : (e.attributes.brightness || 0);\n\nmsg.payload = {\n path: `states/${e.entity_id.replace(\"light.\", \"sensor.\")}_brightness`,\n data: {\n state\n }\n}\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":460,"y":416,"wires":[["49dc0d09.cd7074"]]},{"id":"47f2fcc.51cc604","type":"server-state-changed","z":"b28195ad.c495e8","name":"","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"^light\\.(?!.*\\_brightness$).*","entityidfiltertype":"regex","outputinitially":false,"state_type":"str","haltifstate":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"output_only_on_state_change":false,"for":0,"forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"x":208,"y":416,"wires":[["a0279b06.8882a8"]]},{"id":"49dc0d09.cd7074","type":"ha-api","z":"b28195ad.c495e8","name":"create temp sensor","debugenabled":true,"protocol":"http","method":"post","path":"","data":"","dataType":"json","location":"payload","locationType":"msg","responseType":"json","x":666,"y":416,"wires":[[]]}]