I ended up using Node-Red to post the value to Home Assistant because using mqtt auto discovery, there is no need to restart Home Assistant when adding or removing variables / sensors.
Templating requires to restart Home Assistant, at least, for what I have tried, I see the added templates in the configuration.yaml only gets available after a reboot.
It would be great if templating works just like the variable helpers does, as it is easy to maintain and configure.
in case anyone ends up also to use node-red with autodiscovery of sensors / variables to Home assistant, have a look to the code below:
[{"id":"984ee91a278bf7b8","type":"link out","z":"2e1e9df744ebc531","name":"mqtt out","mode":"link","links":["3d1827435b36e5f5"],"x":635,"y":1760,"wires":[]},{"id":"3da4e6da03462ad6","type":"function","z":"2e1e9df744ebc531","name":"ID","func":"stateTopic = \"nodered_solar_current_watts\";\ntopicTarget = \"homeassistant/sensor/\" +stateTopic + \"/state\";\nunique_id = \"nodered_\" + stateTopic;\nname = \"Solar current W\"\nT = msg.payload;\nwaarde = parseFloat(T).toFixed(0);\n\n\nif(msg.target === '2'){\n var sensor_config2 = {\n \"state_topic\": topicTarget,\n \"value_template\": \"{{ value_json.value | default('') }}\",\n \"json_attributes_topic\": topicTarget,\n \"device\": {\n \"identifiers\": [\n unique_id\n ],\n \"manufacturer\": \"Node-Red\",\n \"model\": \"Virtual Tag\",\n \"name\": name\n },\n \"name\": name,\n \"unique_id\": unique_id,\n \"state_class\": \"measurement\",\n \"unit_of_measurement\": \"W\",\n \"device_class\": \"energy\"\n};\n\nmsg.payload = sensor_config2;\n\n msg.topic=\"homeassistant/sensor/\"+ stateTopic+ \"/config\";\n return [msg, null];\n}\n\n\nvar sensor_config = {\n \"value\": waarde\n};\n\nmsg.payload = sensor_config;\nmsg.topic=\"homeassistant/sensor/\"+ stateTopic+ \"/state\";\nreturn [msg, null];","outputs":3,"noerr":0,"initialize":"","finalize":"","libs":[],"x":490,"y":1760,"wires":[["984ee91a278bf7b8"],[],[]]},{"id":"dfd34ed815130ec0","type":"server-state-changed","z":"2e1e9df744ebc531","name":"","server":"2e51afe.c76fa5","version":3,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"sensor.solaredge_current_power","entityidfiltertype":"exact","outputinitially":false,"state_type":"num","haltifstate":"-1","halt_if_type":"num","halt_if_compare":"is_not","outputs":2,"output_only_on_state_change":true,"for":0,"forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":true,"ignoreCurrentStateUnavailable":true,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":200,"y":1760,"wires":[["3da4e6da03462ad6"],[]]},{"id":"dbba3b5111b8076b","type":"inject","z":"2e1e9df744ebc531","name":"postConfig","props":[{"p":"target","v":"2","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":320,"y":1800,"wires":[["3da4e6da03462ad6"]]},{"id":"5b370fe18eea9eb8","type":"function","z":"2e1e9df744ebc531","name":"Random number generator","func":"const MIN = 1000;\nconst MAX = 2000;\n\nmsg.payload =function getRandomInt(min = MIN, max = MAX) {\n min = Math.ceil(min);\n max = Math.floor(max);\n return 0.23456 + Math.floor(Math.random() * (max - min)) + min;\n}();\n\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":360,"y":1840,"wires":[["3da4e6da03462ad6"]]},{"id":"a92a4949a2a26a1d","type":"inject","z":"2e1e9df744ebc531","name":"postValue","props":[{"p":"target","v":"1","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":120,"y":1840,"wires":[["5b370fe18eea9eb8"]]},{"id":"e138a2bed73cf1fb","type":"mqtt out","z":"2e1e9df744ebc531","name":"Post to MQTT","topic":"","qos":"","retain":"true","respTopic":"","contentType":"","userProps":"","correl":"","expiry":"","broker":"9fedca0d.c87928","x":1080,"y":1600,"wires":[]},{"id":"3d1827435b36e5f5","type":"link in","z":"2e1e9df744ebc531","name":"mqtt in","links":["6c73d20fdaa78a2f","48e1aca3a1dd65e1","984ee91a278bf7b8"],"x":955,"y":1600,"wires":[["e138a2bed73cf1fb"]]},{"id":"2e51afe.c76fa5","type":"server","name":"Home Assistant","addon":true},{"id":"9fedca0d.c87928","type":"mqtt-broker","name":"homeassistant","broker":"localhost","port":"1883","clientid":"","usetls":false,"compatmode":false,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""}]