Hauptmenü

AM2301 on Tasmota 9.2

Begonnen von domo, 12 Februar 2021, 11:17:08

Vorheriges Thema - Nächstes Thema

domo

good day, I hope somebody could help me on a small issue which I am experiencing.  I am not a software guy, so I tend to just use scripts that have already been written and tested, my FHEM is very basic, but does what I need.  I hooked up a DHT22 which as far as I know should be set up as AM2301 on the tasmota device, so far so good, but it appears that mr Arendst is not concerned about the reading error.  https://github.com/arendst/Tasmota/issues/10867 so I found that when the temperature drops below 0 degrees, the readings sent from the tasmota device need to have 3276.8 subtracted from them, so that the correct temperature is shown.  This must be possible to do in FHEM so that the final submitted reading is correct.  Could somebody with PERL knowledge post a simple one liner which can be bound to the device readings so that temperatures under 0 turn out correct ?
Best regards Domo

domo

2021-02-11_19:28:13 MQTT2_DVES_DA79F7 SENSOR_AM2301_Temperature: 0.2
2021-02-11_19:33:13 MQTT2_DVES_DA79F7 SENSOR_AM2301_Humidity: 59.9
2021-02-11_19:33:13 MQTT2_DVES_DA79F7 SENSOR_AM2301_Temperature: 0.2
2021-02-11_19:38:13 MQTT2_DVES_DA79F7 SENSOR_AM2301_Humidity: 60.4
2021-02-11_19:38:13 MQTT2_DVES_DA79F7 SENSOR_AM2301_Temperature: 0.0
2021-02-11_19:43:13 MQTT2_DVES_DA79F7 SENSOR_AM2301_Humidity: 60.7
2021-02-11_19:43:13 MQTT2_DVES_DA79F7 SENSOR_AM2301_Temperature: 0.0
2021-02-11_19:48:12 MQTT2_DVES_DA79F7 SENSOR_AM2301_Temperature: -3276.1
2021-02-11_19:48:12 MQTT2_DVES_DA79F7 SENSOR_AM2301_Humidity: 62.7
2021-02-11_19:53:13 MQTT2_DVES_DA79F7 SENSOR_AM2301_Humidity: 64.5
2021-02-11_19:53:13 MQTT2_DVES_DA79F7 SENSOR_AM2301_Temperature: -3275.7

yersinia

#2
I guess adding 3276.8 makes more sense when the value is below 0 and convert it into a negative value, or did I get it wrong?

What about an userReading?
Being no PERL expert, I could imagine something like this (not tested; RAW definition):
attr MQTT2_DVES_DA79F7 userReadings tempCalculated { if(ReadingsNum($name,"SENSOR_AM2301_Temperature",0) < 0) {\
return ((ReadingsNum($name,"SENSOR_AM2301_Temperature",0)+3276.8) * (-1));;\
} else {\
return ReadingsNum($name,"SENSOR_AM2301_Temperature",0);;\
}\
}


The reading tempCalculated should then provide the corrected temperature if the value is below 0 - or the correct value (else case).
viele Grüße, yersinia
----
FHEM 6.4 (SVN) on RPi 4B with RasPi OS Bookworm (perl 5.36.0) | FTUI
nanoCUL->2x868(1x ser2net)@tsculfw, 1x433@Sduino | MQTT2 | Tasmota | ESPEasy
VCCU->14xSEC-SCo, 7xCC-RT-DN, 5xLC-Bl1PBU-FM, 3xTC-IT-WM-W-EU, 1xPB-2-WM55, 1xLC-Sw1PBU-FM, 1xES-PMSw1-Pl

domo

hello Yersinia, I inserted that line ,and it looks good, but at the moment that sensor is reading +0,3 so the tempCalculated is also +0.3, which is as it should be.  I think later on the temperature will drop bellow zero again, so I will be able to say if it has worked.  Thanks for the quick solution. :) best regards Domo

yersinia

yeah, give it a try. I have to apologize, but I suggested the wrong function. *doh* Use ReadingsNum instead of ReadingsVal when comparing/calculating with numbers. ::)

attr MQTT2_DVES_DA79F7 userReadings tempCalculated { if(ReadingsNum($name,"SENSOR_AM2301_Temperature",0) < 0) {\
return ((ReadingsNum($name,"SENSOR_AM2301_Temperature",0)+3276.8) * (-1));;\
} else {\
return ReadingsNum($name,"SENSOR_AM2301_Temperature",0);;\
}\
}

My apologies.
viele Grüße, yersinia
----
FHEM 6.4 (SVN) on RPi 4B with RasPi OS Bookworm (perl 5.36.0) | FTUI
nanoCUL->2x868(1x ser2net)@tsculfw, 1x433@Sduino | MQTT2 | Tasmota | ESPEasy
VCCU->14xSEC-SCo, 7xCC-RT-DN, 5xLC-Bl1PBU-FM, 3xTC-IT-WM-W-EU, 1xPB-2-WM55, 1xLC-Sw1PBU-FM, 1xES-PMSw1-Pl

domo

ah, no problem, i noticed that in fact the temperature did just dip below 0 again, but the calculated seem to stay at 0, so may be it will work now with the modification, i'll post as soon as i know, thanks best regards domo

domo

hello Yersinia, it works !  just a few details, would it be possible to alter the code so that the calculation only takes place with the temperature reading, and would it be possible to get the output fixed to 1 decimal place ?
best regards
Domo
2021-02-12_18:34:24 MQTT2_DVES_DA79F7 SENSOR_AM2301_Humidity: 65.2
2021-02-12_18:34:24 MQTT2_DVES_DA79F7 tempCalculated: -1.20000000000027
2021-02-12_18:39:24 MQTT2_DVES_DA79F7 tempCalculated: -1.20000000000027
2021-02-12_18:39:24 MQTT2_DVES_DA79F7 SENSOR_AM2301_Humidity: 65.2
2021-02-12_18:39:24 MQTT2_DVES_DA79F7 SENSOR_AM2301_Temperature: -3275.5
2021-02-12_18:39:24 MQTT2_DVES_DA79F7 tempCalculated: -1.30000000000018
2021-02-12_18:44:24 MQTT2_DVES_DA79F7 tempCalculated: -1.30000000000018
2021-02-12_18:44:24 MQTT2_DVES_DA79F7 SENSOR_AM2301_Temperature: -3275.4

domo

Hello Yersinia, I think this might work:
   

tempCalculated { if(ReadingsNum($name,"SENSOR_AM2301_Temperature",0) < 0) {
return sprintf('%.1f',(ReadingsNum($name,"SENSOR_AM2301_Temperature",0,1)+3276.8) * (-1));
} if(ReadingsNum($name,"SENSOR_AM2301_Temperature",0) >= 0) {
return ReadingsNum($name,"SENSOR_AM2301_Temperature",0);
}
}

but i still get too many tempCalculated readings in the log.  I guess i'll need to look at what is going on there.
Best regards
Domo

yersinia

If this works for you, perfect.
Every time, when SENSOR_AM2301_Temperature is updated, the userReading is triggered as well (event based handling here).
You can limit the events/change the intervall between events with event-min-interval. Something like:
attr MQTT2_DVES_DA79F7 event-min-interval .*:300
defines the interval between two events as 300 seconds (5 minutes).

You can also use event-on-update-reading or event-on-change-reading to reduce events on specific readings.
viele Grüße, yersinia
----
FHEM 6.4 (SVN) on RPi 4B with RasPi OS Bookworm (perl 5.36.0) | FTUI
nanoCUL->2x868(1x ser2net)@tsculfw, 1x433@Sduino | MQTT2 | Tasmota | ESPEasy
VCCU->14xSEC-SCo, 7xCC-RT-DN, 5xLC-Bl1PBU-FM, 3xTC-IT-WM-W-EU, 1xPB-2-WM55, 1xLC-Sw1PBU-FM, 1xES-PMSw1-Pl

Beta-User

Also use the original reading name as trigger!tempCalculated:SENSOR_AM2301_Temperature.* ....
Server: HP-elitedesk@Debian 12, aktuelles FHEM@ConfigDB | CUL_HM (VCCU) | MQTT2: ZigBee2mqtt, MiLight@ESP-GW, BT@OpenMQTTGw | ZWave | SIGNALduino | MapleCUN | RHASSPY
svn: u.a Weekday-&RandomTimer, Twilight,  div. attrTemplate-files, MySensors