Advertisement
ottelo15

Add new Tasmota value to Home Assistan via MQTT config topic message

Mar 28th, 2024 (edited)
484
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JSON 2.54 KB | None | 0 0
  1. == How to transfer a new Tasmota value from your Tasmota Script to Home Assistant ==
  2.  
  3. You can use MQTT Discovery in HA to add sensors and other entities that are not discovered through Tasmota integration and associate them with an already discovered device.
  4.  
  5. More infos:
  6. https://www.home-assistant.io/integrations/sensor.mqtt/#configuration-variables
  7. https://github.com/home-assistant/core/blob/dev/homeassistant/components/mqtt/abbreviations.py
  8. https://tasmota.github.io/docs/Home-Assistant/#supplemental-custom-discovery-message
  9.  
  10. HOWTO
  11. -------------------------------------------------------
  12. 1) add a new line of code inside your script
  13.    e.g. =>publish stat/%topic%/script/consday %2(dcon[day])%
  14.    e.g. in this script section:
  15.  
  16. >S
  17. if (secs%60==0)
  18. {
  19.   =>publish stat/%topic%/script/consday %dcon[day]%
  20. }
  21.  
  22.   See example script ottelo.jimdofree.com/stromz%C3%A4hler-auslesen-tasmota/#SkriptDownload.
  23.  
  24. 2) Install and start MQTT Explorer in HA
  25. 3) Look for your new MQTT sensor inside MQTT Explorer e.g. stat/%topic%/script/consday = xxx
  26. 4) Publish a new config topic to Home Assistant with MQTT Explorer. Home Assistant will then automatically add the sensor to the already published device.
  27. 5) Click on topic "homeassistant/sensor". On right side click on "homeassistant/sensor" below "Publish". Change the topic address to e.g. "homeassistant/sensor/mt175/consday/config"
  28. 6) Then paste the following JSON code into the field and activate the retain flag. Change or add mqtt config variables if needed (use abbreviations to keep everything short, see url above). A02xxxxAFAD3 is the MAC of Tasmota and tasmota_1AFAD3 the topic + last part of MAC. Change it!
  29.  
  30. Example Yieldday of Smartmeter MT175 (yieldday calculated inside Tasmota script and saved into array dprod[day]):
  31. {
  32.   "name": "Smartmeter Day Consumption",
  33.   "uniq_id": "mt175_dayconsumption",
  34.   "dev_cla": "energy",
  35.   "stat_t": "stat/tasmota_1AFAD3/script/consday",
  36.   "unit_of_meas": "kWh",
  37.   "dev": {
  38.     "connections": [
  39.       [
  40.         "mac",
  41.         "A02xxxxAFAD3"
  42.       ]
  43.     ]
  44.   }
  45. }
  46.  
  47. 7) Press on Publish
  48.  
  49.  
  50. Other example:
  51. =>publish stat/%topic%/RESULT {"script":{"power2":%power2%}}
  52. Config topic: homeassistant/sensor/mt175/config
  53. {
  54.   "name": "Stromzähler Leistung (gefiltert)",
  55.   "uniq_id": "mt175_mt175_power2",
  56.   "dev_cla": "power",
  57.   "stat_t": "stat/tasmota_1AFAD3/RESULT",
  58.   "unit_of_meas": "W",
  59.   "val_tpl": "{{value_json.script.power2}}",
  60.   "sug_dsp_prc": "0",
  61.   "dev": {
  62.     "connections": [
  63.       [
  64.         "mac",
  65.         "A02xxxxAFAD3"
  66.       ]
  67.     ]
  68.   }
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement