Here is an example that will make 3 sensors dynamically in HA.
They are defined in the function node.
The function node will send 3 messages to the API node that will create a sensor in HA.
The last of the messages will be with a value picked from the copy of the state machine store in the NR context data folder (the cog in the icon list in the upper right corner and remember to refresh the globals section to actually see the values).
A thing that is important to remember with these sensors is that they are not persistent, so after a restart of HA they do not exist until NR have run the flow. They will be unknown or unavailable until then.
This means you might get some errors in the NR and HA logs if you base stuff, like templates or automations on these sensors and Spook will complain about it. All will however work when the flow creates the sensors and Spook accepts it also and removes the warning.
[{"id":"25ef1c9c74581477","type":"ha-api","z":"be03f9025a1f137a","name":"sensor","server":"","version":1,"debugenabled":false,"protocol":"http","method":"post","path":"/api/states/{{entity_id}}","data":"","dataType":"json","responseType":"json","outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"results"}],"x":800,"y":660,"wires":[[]]},{"id":"06ac8e03a8a85876","type":"function","z":"be03f9025a1f137a","name":"make final payload","func":"let msg1 = {};\nlet msg2 = {};\nlet msg3 = {};\n\nmsg1.entity_id = `sensor.test1`;\nmsg1.payload = {\n data: {\n state: 'test1',\n attributes: {\n 'name': 'name1',\n 'test1': 'test',\n 'test2': 'test',\n friendly_name: 'Test Entity 1',\n icon: 'mdi:pulse'\n }\n }\n};\nnode.send(msg1);\n\nmsg2.entity_id = `sensor.test1`;\nmsg2.payload = {\n data: {\n state: 'test2',\n attributes: {\n 'name': 'name2',\n 'test1': 'test',\n 'test2': 'test',\n friendly_name: 'Test Entity 2',\n icon: 'mdi:pulse'\n }\n }\n};\nnode.send(msg2);\n\nmsg3.entity_id = `binary_sensor.is_nodered_running`;\nmsg3.payload = {\n data: {\n state: global.get('homeassistant').homeAssistant.states[\"binary_sensor.node_red_running\"].state,\n attributes: {\n 'name': 'name3',\n 'test1': 'test',\n 'test2': 'test',\n friendly_name: 'Test Entity 3',\n icon: 'mdi:pulse'\n }\n }\n};\nreturn msg3;\n\n","outputs":1,"timeout":"","noerr":0,"initialize":"","finalize":"","libs":[],"x":630,"y":660,"wires":[["25ef1c9c74581477","fee8ca78ceac8578","b84f7742bdb0e268"]]},{"id":"39963ed0628d85b4","type":"inject","z":"be03f9025a1f137a","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":450,"y":660,"wires":[["06ac8e03a8a85876"]]},{"id":"08d7fed91f66a201","type":"global-config","env":[],"modules":{"node-red-contrib-home-assistant-websocket":"0.80.3"}}]
Import the flow and set your HA server up for it.
Then run it and see the result in the HA developer tools.
The sensors that the flow will create will be removed after a HA restart, so no long term impact of the test.
But check that you do not already have sensors named what is used in the function node. 