-
How to pass units from script to home assistant using tasmota integration? I wrote SML script and I see all sensors in HA, but units where no configured. How unit are passed to HA during discovery "SO19 0" -> Home assistant integration. |
Beta Was this translation helpful? Give feedback.
Replies: 9 comments 15 replies
-
Assuming that you by "Unit" means which unit of measurement each number is in, that is generally implied in the /SENSOR payloads published. Tasmota only includes explicit unit when there are options allowing the user to select unit of preference, like temperature in C vs F. For energy monitoring, the implied units are same as used on the front page of Tasmota, V/Hz/A/W/VA/VAr/%/KWh. These are not passed. |
Beta Was this translation helpful? Give feedback.
-
I need this too ... |
Beta Was this translation helpful? Give feedback.
-
Hello, The issue I´m running into is that I can get the sensor values, but as I don´t know from the JSON what type of measurement it is, I cannot show the "units of measurement" on my dashboard. Unfortunately e.g. some energy sensors sometimes report a mix of e.g. "W" and "kWh" for current values vs. totals. Other sensors like light meters might have different units of measurement too. Would the effort to implement Tasmota returning the sensor values with units of measurement a complicated thing? My feel it should not impose too much on complexity / memory usage as Tasmota already "knows" the units of measurement (they are shown in the web-ui). Would it be reasonable to ask to provide those units of measurement in JSON returned on http status 8 request? Thanks for your inputs ... |
Beta Was this translation helpful? Give feedback.
-
Status 8 do provide units that have alternatives : Temperature in °C or °F, pressure in bar ot mmHg, speed in kph or mph It's not that it is complicated, it is done for the units that have alternatives, but because Tasmota has to run on ESP8266 devices where flash size is constrainted, we are avoiding adding any code that do not really provide value. So I suggest that you assume those units. |
Beta Was this translation helpful? Give feedback.
-
@barbudor: Thanks for the fast response. The issue is not mainly with energy sensors but the broad range of sensors that users can connect to their devices and they want to be seen in my dashboard app. E.g. I might get something back like this: How should I know what units those are in? (In fact three of them are in kWh, one in W ). Users might have light sensors connected and want me to show Lux - but how should I even know that it is a light sensor? I would have to parse the sensor type and have a lookup table to see that values and units of measurements it would report - virtually impossible with those large amount of sensors supported by Tasmota (luckily). Currently I would only see the option to parse the web UI html which would be slow, put a lot of burden on the ESP and might be very reliable. Having those units of measurement would be of great help for everyone doing Tasmota dashboards. |
Beta Was this translation helpful? Give feedback.
-
Thanks - that is very helpful information for my general understanding. Cumbersome but doable ... as you mention that this is not currently documented - would it be possible for me to find those references in the code? I tried to take a quick look at the different sensor drivers but could not figure it out from there. In regard to above status 8 sample: It was send to me by a customer stating it was an "IR smart meter interface". I´ll try to get more information about what type exactly and report back. |
Beta Was this translation helpful? Give feedback.
-
Thanks for your helpful responses - although it seems hard to implement that by just parsing the JSON returned to Status 8.
How would I know that a sensor returns mA and not A? How do I get from the JSON keys like in here:
to the reference "unit of measurement". E.g. I can´t find the "Yesterday" key in the tables you cross referenced. Is this an example of where the driver has it in his code directly? My only current workable idea is:
Tasmota seems to do it in a smart way showing those in the HTML gui and I have no idea how complex / memory consuming it would be to add those in a "clean" way to the Status 8 JSON, but I think it would be the most reliable and future proof way, if having those in external apps is of interest for Tasmota. |
Beta Was this translation helpful? Give feedback.
-
Thanks @sfromis and @barbudor - those informations were very helpful. Thanks again for your support - in case there is any hope to get units from JSON in the future - that would be even better (I think for many external applications). |
Beta Was this translation helpful? Give feedback.
-
I found the other answers confusing since you have to choose your own name of the sensors in the Smart Meter Interface script, so I'm not sure what is meant by "it is implicit". For the Home Assistant Tasmota integration, the map of MQTT key to unit of measurement is here: https://github.com/emontnemery/hatasmota/blob/master/hatasmota/sensor.py#L153 (SENSOR_UNIT_MAP) The corresponding constants are defined here: So in your Smart Meter Interface if you e.g. name your sensor "Power" it will get the correct icon and unit "W", if you name it "Energy" it will have unit "kWh". with script:
tasmota will publish
which in home assistant will show up as kWh and W correctly (not because of the unit_of_measurement field in the script but because of the magic name "Energy" and "Power" |
Beta Was this translation helpful? Give feedback.
Assuming that you by "Unit" means which unit of measurement each number is in, that is generally implied in the /SENSOR payloads published. Tasmota only includes explicit unit when there are options allowing the user to select unit of preference, like temperature in C vs F.
For energy monitoring, the implied units are same as used on the front page of Tasmota, V/Hz/A/W/VA/VAr/%/KWh. These are not passed.