(guide) how to add TemperatureOffset to Tasmota

Hi,
just want to share quick tip how to add Temperature Offset and Humidity Offset to your Tasmota powered devices.
Why? because sometimes instalation of the sensor is influenced by some heat source, which needs to be adjusted or you simply want to calibrate two or more sensors to report same values.

Bosh library supports this feature as many others, unfortunately in Tasmota this is doable kind of weird way - by rules… which I dont like at all… so what we can do about it? :slight_smile:

(I assume one can grab source, editor and is able to build *.bin at the end)

Let’s jump to some files …

sonoff/i18n.h
add (to line 230 for example)

#define D_CMND_TEMPADJUST "TempOffset"
#define D_CMND_HUMADJUST "HumOffset"

sonoff/support_commands.ino
add (to the const kTasmotaCommands after D_CMND_BUTTONDEBOUNCE “|” )

D_CMND_TEMPADJUST "|" D_CMND_HUMADJUST "|" 

add (to the TasmotaCommand after &CmndButtonDebounce, )

 &CmndTempAdjust, &CmndHumAdjust, 

add (before void CmndButtonDebounce(void) )

void CmndHumAdjust(void)
{
  Settings.hum_adjust = XdrvMailbox.payload;
  Response_P(S_JSON_COMMAND_NVALUE, XdrvMailbox.command, Settings.hum_adjust);
}

void CmndTempAdjust(void)
{
  Settings.temp_adjust = XdrvMailbox.payload;
  Response_P(S_JSON_COMMAND_NVALUE, XdrvMailbox.command, Settings.temp_adjust);
}

sonoff/settings.h
add (to the end of the struct SYSCFG { )

  float         temp_adjust;
  float         hum_adjust;

and then to the module you are using (I’ve done it for BMx and DHT so:

sonoff/xsns_09_bmp.ino
change

      dtostrfd((bmp_temperature), Settings.flag2.temperature_resolution, temperature);
to
      dtostrfd((bmp_temperature + (Settings.temp_adjust / 10)), Settings.flag2.temperature_resolution, temperature);

and

      dtostrfd((bmp_sensors[bmp_idx].bmp_humidity), Settings.flag2.humidity_resolution, humidity);
to
      dtostrfd((bmp_sensors[bmp_idx].bmp_humidity + (Settings.hum_adjust / 10)), Settings.flag2.humidity_resolution, humidity);

sonoff/xsns_06_dht.ino
change

    Dht[sensor].t = ConvertTemp(Dht[sensor].t);
    Dht[sensor].h = ConvertHumidity(Dht[sensor].h);

to

    Dht[sensor].t = ConvertTemp(Dht[sensor].t + (Settings.temp_adjust / 10));
    Dht[sensor].h = ConvertHumidity(Dht[sensor].h + (Settings.hum_adjust / 10));

(for other sensors you kind of got an idea what is needed … just locate where your module is manipulating final data and do your edits.)

Save, compile, reflash and you are good to go.

Usage:
Console: TempOffset 20 or TempOffset -20 … HumOffset 100 or HumOffset -50

note: because of fact Tasmota loves integers, defining float in console payload have to be done as integer. eg. 1.2 = 12
so TempOffset 5 = 0.5 degrees, TempOffset 50 = 5 degrees etc.

Enjoy your adjusted data from Tasmota in webinterface, mqtt … :slight_smile:

Cheers

Tasmota doesn’t have a way to do this through the web UI? I’m surprised and I guess glad I’m using ESP Easy which had a field where you can apply an offset of some more complicated calculation to the sense reading before publication.

There is also offset profile to use in Item channel links

but of course this only fixes at openHAB and not at source, and then only on number channels

yes indeed, but for me it does not make much sense to correct values out of the original source, as then it is not usable on other places

unfortunately it doesnt have other than strange rules
with my modification you obviously do it from gui by commands since then :slight_smile:

My problem isn’t with the fact that you do it from the command line. My problem is that it pretty much eliminates the ability to update the firmware from now into the future. You will always have to download and remake those edits every time you upgrade the firmware.

if you are using compiled binaries by someone else, sure
if you are having git cloned repo and running versioning, no not at all

The vast majority of OH users are using compiled binaries.

then this guide is not for them and they have to find other firmwares which can do it by default

tasmota is not supporting it and from several discussions on github it does not look like it will

That’s a shame. Applying the correction at the point of origin is the right way to do it.

Wait, they do support this using rules.

With an example to do just this

if you read my first post, you will find out that I know… and if you ever seen those rules, you should be able to understand why those are very wrong way how to do it

They may be wrong but are they really more complicated than having people who don’t know git from a gnat climber a repo, modify source code, build, and flash custom firmware? Not to mention the problems with merging upstream changes as the coffee progresses?

I’m not saying you should use the Tasmota rules, but given there is a bear copy and paste example to do this without all that development stuff, I can’t say is recommend modifying source code for the car majority of oh users.

just bit of update
on vertsion 7+ tasmota, there is already TempOffset incorporated in the firmware, so you don’t need to hack it :wink:

Cheers