If you want your Tasmota energy sensors to appear in the Energy tab, the solution is very simple :
Open MQTT explorer, copy the original discovery message to the clipboard, past in notepad, add “last_reset_topic”,“last_reset_value_template”,“device_class”,“state_class” and republish
example for a sonoff pow r2 :
orginal discovery message :
{"name":"powr2 ENERGY Total","stat_t":"~SENSOR","avty_t":"~LWT","pl_avail":"Online","pl_not_avail":"Offline","uniq_id":"193EF5_ENERGY_Total","device":{"identifiers":["193EF5"]},"~":"powr2/tele/","unit_of_meas":"kWh","val_tpl":"{{value_json['ENERGY'].Total}}"}
new discovery message :
{"name":"powr2 ENERGY Total","stat_t":"~SENSOR","avty_t":"~LWT","pl_avail":"Online","pl_not_avail":"Offline","uniq_id":"193EF5_ENERGY_Total","device":{"identifiers":["193EF5"]},"~":"powr2/tele/","unit_of_meas":"kWh","last_reset_topic":"powr2/tele/SENSOR","last_reset_value_template":"1970-01-01T00:00:00+00:00","device_class":"energy","state_class":"measurement","val_tpl":"{{ value_json['ENERGY'].Total }}"}
if you want to create a script, be sure to put {{ value_json[‘ENERGY’].Total }} between {% raw %}"{{ value_json[‘ENERGY’].Total }}"{% endraw %}
scripttasmotapow2:
sequence:
- service: mqtt.publish
data:
retain: true
topic: homeassistant/sensor/193EF5_ENERGY_Total/config
payload: >
{"name":"powr2 ENERGY Total","stat_t":"~SENSOR","avty_t":"~LWT","pl_avail":"Online","pl_not_avail":"Offline","uniq_id":"193EF5_ENERGY_Total","device":{"identifiers":["193EF5"]},"~":"powr2/tele/","unit_of_meas":"kWh","last_reset_topic":"powr2/tele/SENSOR","last_reset_value_template":"1970-01-01T00:00:00+00:00","device_class":"energy","state_class":"measurement","val_tpl":{% raw %}"{{ value_json['ENERGY'].Total }}"{% endraw %}}
If you are not used to writing json, use https://jsonformatter.org/ to see if you wrote valid json