Add support for IKEA VINDRIKTNING

Add support for IKEA VINDRIKTNING particle concentration sensor (#12976)
This commit is contained in:
Theo Arends 2021-08-26 11:16:28 +02:00
parent d4f444a85a
commit 454d4601b4
33 changed files with 210 additions and 4 deletions

View File

@ -10,6 +10,7 @@ All notable changes to this project will be documented in this file.
- Berry support for vararg
- Command ``Subscribe2 ...`` to subscribe to a MQTT topic without appended "/#" (#12858)
- Support for Hydreon RG-15 Solid State Rain sensor (#12974)
- Support for IKEA VINDRIKTNING particle concentration sensor (#12976)
### Changed
- Shelly EM template needs to use GPIO ADE7953_IRQ_2

View File

@ -123,6 +123,7 @@ The latter links can be used for OTA upgrades too like ``OtaUrl http://ota.tasmo
- Command ``Subscribe2 ...`` to subscribe to a MQTT topic without appended "/#" [#12858](https://github.com/arendst/Tasmota/issues/12858)
- Support for IEM3155 Wattmeter [#12940](https://github.com/arendst/Tasmota/issues/12940)
- Support for Hydreon RG-15 Solid State Rain sensor [#12974](https://github.com/arendst/Tasmota/issues/12974)
- Support for IKEA VINDRIKTNING particle concentration sensor [#12976](https://github.com/arendst/Tasmota/issues/12976)
### Changed
- Move firmware binaries to https://github.com/arendst/Tasmota-firmware/tree/main/release-firmware

View File

@ -838,6 +838,7 @@
#define D_SENSOR_MCP2515_CS "MCP2515 CS"
#define D_SENSOR_HRG15_RX "HRG15 Rx"
#define D_SENSOR_HRG15_TX "HRG15 Tx"
#define D_SENSOR_VINDRIKTNING_RX "VINDRIKTNING"
// Units
#define D_UNIT_AMPERE "A"

View File

@ -837,6 +837,7 @@
#define D_SENSOR_MCP2515_CS "MCP2515 CS"
#define D_SENSOR_HRG15_RX "HRG15 Rx"
#define D_SENSOR_HRG15_TX "HRG15 Tx"
#define D_SENSOR_VINDRIKTNING_RX "VINDRIKTNING"
// Units
#define D_UNIT_AMPERE "A"

View File

@ -838,6 +838,7 @@
#define D_SENSOR_MCP2515_CS "MCP2515 CS"
#define D_SENSOR_HRG15_RX "HRG15 Rx"
#define D_SENSOR_HRG15_TX "HRG15 Tx"
#define D_SENSOR_VINDRIKTNING_RX "VINDRIKTNING"
// Units
#define D_UNIT_AMPERE "A"

View File

@ -838,6 +838,7 @@
#define D_SENSOR_MCP2515_CS "MCP2515 CS"
#define D_SENSOR_HRG15_RX "HRG15 Rx"
#define D_SENSOR_HRG15_TX "HRG15 Tx"
#define D_SENSOR_VINDRIKTNING_RX "VINDRIKTNING"
// Units
#define D_UNIT_AMPERE "A"

View File

@ -838,6 +838,7 @@
#define D_SENSOR_MCP2515_CS "MCP2515 CS"
#define D_SENSOR_HRG15_RX "HRG15 Rx"
#define D_SENSOR_HRG15_TX "HRG15 Tx"
#define D_SENSOR_VINDRIKTNING_RX "VINDRIKTNING"
// Units
#define D_UNIT_AMPERE "A"

View File

@ -838,6 +838,7 @@
#define D_SENSOR_MCP2515_CS "MCP2515 CS"
#define D_SENSOR_HRG15_RX "HRG15 Rx"
#define D_SENSOR_HRG15_TX "HRG15 Tx"
#define D_SENSOR_VINDRIKTNING_RX "VINDRIKTNING"
// Units
#define D_UNIT_AMPERE "A"

View File

@ -838,6 +838,7 @@
#define D_SENSOR_MCP2515_CS "MCP2515 CS"
#define D_SENSOR_HRG15_RX "HRG15 Rx"
#define D_SENSOR_HRG15_TX "HRG15 Tx"
#define D_SENSOR_VINDRIKTNING_RX "VINDRIKTNING"
// Units
#define D_UNIT_AMPERE "A"

View File

@ -838,6 +838,7 @@
#define D_SENSOR_MCP2515_CS "MCP2515 CS"
#define D_SENSOR_HRG15_RX "HRG15 Rx"
#define D_SENSOR_HRG15_TX "HRG15 Tx"
#define D_SENSOR_VINDRIKTNING_RX "VINDRIKTNING"
// Units
#define D_UNIT_AMPERE "A"

View File

@ -838,6 +838,7 @@
#define D_SENSOR_MCP2515_CS "MCP2515 CS"
#define D_SENSOR_HRG15_RX "HRG15 Rx"
#define D_SENSOR_HRG15_TX "HRG15 Tx"
#define D_SENSOR_VINDRIKTNING_RX "VINDRIKTNING"
// Units
#define D_UNIT_AMPERE "A"

View File

@ -838,6 +838,7 @@
#define D_SENSOR_MCP2515_CS "MCP2515 CS"
#define D_SENSOR_HRG15_RX "HRG15 Rx"
#define D_SENSOR_HRG15_TX "HRG15 Tx"
#define D_SENSOR_VINDRIKTNING_RX "VINDRIKTNING"
// Units
#define D_UNIT_AMPERE "A"

View File

@ -838,6 +838,7 @@
#define D_SENSOR_MCP2515_CS "MCP2515 CS"
#define D_SENSOR_HRG15_RX "HRG15 Rx"
#define D_SENSOR_HRG15_TX "HRG15 Tx"
#define D_SENSOR_VINDRIKTNING_RX "VINDRIKTNING"
// Units
#define D_UNIT_AMPERE "A"

View File

@ -838,6 +838,7 @@
#define D_SENSOR_MCP2515_CS "MCP2515 - CS"
#define D_SENSOR_HRG15_RX "HRG15 Rx"
#define D_SENSOR_HRG15_TX "HRG15 Tx"
#define D_SENSOR_VINDRIKTNING_RX "VINDRIKTNING"
// Units
#define D_UNIT_AMPERE "A"

View File

@ -838,6 +838,7 @@
#define D_SENSOR_MCP2515_CS "MCP2515 CS"
#define D_SENSOR_HRG15_RX "HRG15 Rx"
#define D_SENSOR_HRG15_TX "HRG15 Tx"
#define D_SENSOR_VINDRIKTNING_RX "VINDRIKTNING"
// Units
#define D_UNIT_AMPERE "A"

View File

@ -838,6 +838,7 @@
#define D_SENSOR_MCP2515_CS "MCP2515 CS"
#define D_SENSOR_HRG15_RX "HRG15 Rx"
#define D_SENSOR_HRG15_TX "HRG15 Tx"
#define D_SENSOR_VINDRIKTNING_RX "VINDRIKTNING"
// Units
#define D_UNIT_AMPERE "A"

View File

@ -838,6 +838,7 @@
#define D_SENSOR_MCP2515_CS "MCP2515 CS"
#define D_SENSOR_HRG15_RX "HRG15 Rx"
#define D_SENSOR_HRG15_TX "HRG15 Tx"
#define D_SENSOR_VINDRIKTNING_RX "VINDRIKTNING"
// Units
#define D_UNIT_AMPERE "A"

View File

@ -838,6 +838,7 @@
#define D_SENSOR_MCP2515_CS "MCP2515 CS"
#define D_SENSOR_HRG15_RX "HRG15 Rx"
#define D_SENSOR_HRG15_TX "HRG15 Tx"
#define D_SENSOR_VINDRIKTNING_RX "VINDRIKTNING"
// Units
#define D_UNIT_AMPERE "A"

View File

@ -838,6 +838,7 @@
#define D_SENSOR_MCP2515_CS "MCP2515 CS"
#define D_SENSOR_HRG15_RX "HRG15 Rx"
#define D_SENSOR_HRG15_TX "HRG15 Tx"
#define D_SENSOR_VINDRIKTNING_RX "VINDRIKTNING"
// Units
#define D_UNIT_AMPERE "A"

View File

@ -838,6 +838,7 @@
#define D_SENSOR_MCP2515_CS "MCP2515 CS"
#define D_SENSOR_HRG15_RX "HRG15 Rx"
#define D_SENSOR_HRG15_TX "HRG15 Tx"
#define D_SENSOR_VINDRIKTNING_RX "VINDRIKTNING"
// Units
#define D_UNIT_AMPERE "A"

View File

@ -838,6 +838,7 @@
#define D_SENSOR_MCP2515_CS "MCP2515 CS"
#define D_SENSOR_HRG15_RX "HRG15 Rx"
#define D_SENSOR_HRG15_TX "HRG15 Tx"
#define D_SENSOR_VINDRIKTNING_RX "VINDRIKTNING"
// Units
#define D_UNIT_AMPERE "А"

View File

@ -838,6 +838,7 @@
#define D_SENSOR_MCP2515_CS "MCP2515 CS"
#define D_SENSOR_HRG15_RX "HRG15 Rx"
#define D_SENSOR_HRG15_TX "HRG15 Tx"
#define D_SENSOR_VINDRIKTNING_RX "VINDRIKTNING"
// Units
#define D_UNIT_AMPERE "A"

View File

@ -838,6 +838,7 @@
#define D_SENSOR_MCP2515_CS "MCP2515 CS"
#define D_SENSOR_HRG15_RX "HRG15 Rx"
#define D_SENSOR_HRG15_TX "HRG15 Tx"
#define D_SENSOR_VINDRIKTNING_RX "VINDRIKTNING"
// Units
#define D_UNIT_AMPERE "A"

View File

@ -838,6 +838,7 @@
#define D_SENSOR_MCP2515_CS "MCP2515 CS"
#define D_SENSOR_HRG15_RX "HRG15 Rx"
#define D_SENSOR_HRG15_TX "HRG15 Tx"
#define D_SENSOR_VINDRIKTNING_RX "VINDRIKTNING"
// Units
#define D_UNIT_AMPERE "A"

View File

@ -838,6 +838,7 @@
#define D_SENSOR_MCP2515_CS "MCP2515 CS"
#define D_SENSOR_HRG15_RX "HRG15 Rx"
#define D_SENSOR_HRG15_TX "HRG15 Tx"
#define D_SENSOR_VINDRIKTNING_RX "VINDRIKTNING"
// Units
#define D_UNIT_AMPERE "А"

View File

@ -838,6 +838,7 @@
#define D_SENSOR_MCP2515_CS "MCP2515 CS"
#define D_SENSOR_HRG15_RX "HRG15 Rx"
#define D_SENSOR_HRG15_TX "HRG15 Tx"
#define D_SENSOR_VINDRIKTNING_RX "VINDRIKTNING"
// Units
#define D_UNIT_AMPERE "A"

View File

@ -838,6 +838,7 @@
#define D_SENSOR_MCP2515_CS "MCP2515 CS"
#define D_SENSOR_HRG15_RX "HRG15 Rx"
#define D_SENSOR_HRG15_TX "HRG15 Tx"
#define D_SENSOR_VINDRIKTNING_RX "VINDRIKTNING"
// Units
#define D_UNIT_AMPERE "A"

View File

@ -838,6 +838,7 @@
#define D_SENSOR_MCP2515_CS "MCP2515 CS"
#define D_SENSOR_HRG15_RX "HRG15 Rx"
#define D_SENSOR_HRG15_TX "HRG15 Tx"
#define D_SENSOR_VINDRIKTNING_RX "VINDRIKTNING"
// Units
#define D_UNIT_AMPERE "安培"

View File

@ -744,6 +744,7 @@
// #define USE_AS608_MESSAGES // Add verbose error messages (+0k4 code)
//#define USE_TFMINIPLUS // Add support for TFmini Plus (TFmini, TFmini-S) LiDAR modules via UART interface (+0k8)
//#define USE_HRG15 // Add support for Hydreon RG-15 Solid State Rain sensor (+1k5 code)
//#define USE_VINDRIKTNING // Add support for IKEA VINDRIKTNING particle concentration sensor (+1k code)
// -- Power monitoring sensors --------------------
#define USE_ENERGY_SENSOR // Add support for Energy Monitors (+14k code)

View File

@ -765,7 +765,9 @@ void ResponseAppendFeatures(void)
#ifdef USE_HRG15
feature8 |= 0x00001000; // xsns_90_hrg15.ino
#endif
// feature8 |= 0x00002000;
#ifdef USE_VINDRIKTNING
feature8 |= 0x00002000; // xsns_91_vindriktning.ino
#endif
// feature8 |= 0x00004000;
// feature8 |= 0x00008000;

View File

@ -171,6 +171,7 @@ enum UserSelectablePins {
GPIO_INTERRUPT,
GPIO_MCP2515_CS, // MCP2515 Chip Select
GPIO_HRG15_TX, GPIO_HRG15_RX, // Hydreon RG-15 rain sensor serial interface
GPIO_VINDRIKTNING_RX, // IKEA VINDRIKTNING Serial interface
GPIO_SENSOR_END };
enum ProgramSelectablePins {
@ -361,7 +362,8 @@ const char kSensorNames[] PROGMEM =
D_SENSOR_I2S_IN_DATA "|" D_SENSOR_I2S_IN_CLK "|" D_SENSOR_I2S_IN_SLCT "|"
D_SENSOR_INTERRUPT "|"
D_SENSOR_MCP2515_CS "|"
D_SENSOR_HRG15_TX "|" D_SENSOR_HRG15_RX
D_SENSOR_HRG15_TX "|" D_SENSOR_HRG15_RX "|"
D_SENSOR_VINDRIKTNING_RX
;
const char kSensorNamesFixed[] PROGMEM =
@ -797,6 +799,9 @@ const uint16_t kGpioNiceList[] PROGMEM = {
AGPIO(GPIO_HRG15_TX),
AGPIO(GPIO_HRG15_RX),
#endif
#ifdef USE_VINDRIKTNING
AGPIO(GPIO_VINDRIKTNING_RX),
#endif
/*-------------------------------------------------------------------------------------------*\
* Other sensors

View File

@ -0,0 +1,170 @@
/*
xsns_91_vindriktning.ino - IKEA vindriktning particle concentration sensor support for Tasmota
Copyright (C) 2021 Marcel Ritter and Theo Arends
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifdef USE_VINDRIKTNING
/*********************************************************************************************\
* IKEA VINDRIKTNING particle concentration sensor
\*********************************************************************************************/
#define XSNS_91 91
#include <TasmotaSerial.h>
#ifndef MIN_INTERVAL_PERIOD
#define MIN_INTERVAL_PERIOD 60 // minimum interval period in seconds required for passive mode
#endif
#define VINDRIKTNING_DATASET_SIZE 20
TasmotaSerial *VindriktningSerial;
struct VINDRIKTNING {
uint16_t pm2_5 = 0;
uint16_t pm1_0 = 0;
uint16_t pm10 = 0;
uint8_t type = 1;
uint8_t valid = 0;
bool discovery_triggered = false;
} Vindriktning;
bool VindriktningReadData(void) {
if (!VindriktningSerial->available()) {
return false;
}
int serial_in_byte_counter = 0;
uint8_t buffer[VINDRIKTNING_DATASET_SIZE];
uint8_t crc = 0;
while (VindriktningSerial->available()) {
uint8_t serial_in_byte = VindriktningSerial->read();
if (serial_in_byte_counter <= VINDRIKTNING_DATASET_SIZE -1) {
buffer[serial_in_byte_counter++] = serial_in_byte;
crc += serial_in_byte;
}
}
VindriktningSerial->flush(); // Make room for another burst
AddLogBuffer(LOG_LEVEL_DEBUG_MORE, buffer, VINDRIKTNING_DATASET_SIZE);
if (serial_in_byte_counter < VINDRIKTNING_DATASET_SIZE) {
AddLog(LOG_LEVEL_DEBUG, PSTR("VDN: Not enough data (%d < 20)"), serial_in_byte_counter);
return false;
}
if (crc != 0) {
AddLog(LOG_LEVEL_DEBUG, PSTR("VDN: " D_CHECKSUM_FAILURE));
return false;
}
// sample data:
// 16 11 0b 00 00 00 0c 00 00 03 cb 00 00 00 0c 01 00 00 00 e7
// |pm2_5| |pm1_0| |pm10 | | CRC |
Vindriktning.pm2_5 = (buffer[5] << 8) | buffer[6];
Vindriktning.pm1_0 = (buffer[9] << 8) | buffer[10];
Vindriktning.pm10 = (buffer[13] << 8) | buffer[14];
if (!Vindriktning.discovery_triggered) {
TasmotaGlobal.discovery_counter = 1; // force TasDiscovery()
Vindriktning.discovery_triggered = true;
}
return true;
}
/*********************************************************************************************/
void VindriktningSecond(void) { // Every second
if (VindriktningReadData()) {
Vindriktning.valid = MIN_INTERVAL_PERIOD;
} else {
if (Vindriktning.valid) {
Vindriktning.valid--;
}
}
}
/*********************************************************************************************/
void VindriktningInit(void) {
Vindriktning.type = 0;
if (PinUsed(GPIO_VINDRIKTNING_RX)) {
VindriktningSerial = new TasmotaSerial(Pin(GPIO_VINDRIKTNING_RX), -1, 1);
if (VindriktningSerial->begin(9600)) {
if (VindriktningSerial->hardwareSerial()) { ClaimSerial(); }
Vindriktning.type = 1;
}
}
}
#ifdef USE_WEBSERVER
const char HTTP_VINDRIKTNING_SNS[] PROGMEM =
"{s}VINDRIKTNING " D_ENVIRONMENTAL_CONCENTRATION " 1.0 " D_UNIT_MICROMETER "{m}%d " D_UNIT_MICROGRAM_PER_CUBIC_METER "{e}"
"{s}VINDRIKTNING " D_ENVIRONMENTAL_CONCENTRATION " 2.5 " D_UNIT_MICROMETER "{m}%d " D_UNIT_MICROGRAM_PER_CUBIC_METER "{e}"
"{s}VINDRIKTNING " D_ENVIRONMENTAL_CONCENTRATION " 10 " D_UNIT_MICROMETER "{m}%d " D_UNIT_MICROGRAM_PER_CUBIC_METER "{e}"; // {s} = <tr><th>, {m} = </th><td>, {e} = </td></tr>
#endif // USE_WEBSERVER
void VindriktningShow(bool json) {
if (Vindriktning.valid) {
if (json) {
ResponseAppend_P(PSTR(",\"VINDRIKTNING\":{\"PM1\":%d,\"PM2.5\":%d,\"PM10\":%d}"),
Vindriktning.pm1_0, Vindriktning.pm2_5, Vindriktning.pm10);
#ifdef USE_DOMOTICZ
if (0 == TasmotaGlobal.tele_period) {
DomoticzSensor(DZ_COUNT, Vindriktning.pm1_0); // PM1.0
DomoticzSensor(DZ_VOLTAGE, Vindriktning.pm2_5); // PM2.5
DomoticzSensor(DZ_CURRENT, Vindriktning.pm10); // PM10
}
#endif // USE_DOMOTICZ
#ifdef USE_WEBSERVER
} else {
WSContentSend_PD(HTTP_VINDRIKTNING_SNS, Vindriktning.pm1_0, Vindriktning.pm2_5, Vindriktning.pm10);
#endif // USE_WEBSERVER
}
}
}
/*********************************************************************************************\
* Interface
\*********************************************************************************************/
bool Xsns91(uint8_t function) {
bool result = false;
if (Vindriktning.type) {
switch (function) {
case FUNC_EVERY_SECOND:
VindriktningSecond();
break;
case FUNC_JSON_APPEND:
VindriktningShow(1);
break;
#ifdef USE_WEBSERVER
case FUNC_WEB_SENSOR:
VindriktningShow(0);
break;
#endif // USE_WEBSERVER
case FUNC_INIT:
VindriktningInit();
break;
}
}
return result;
}
#endif // USE_VINDRIKTNING

View File

@ -256,7 +256,7 @@ a_features = [[
"USE_MPU_ACCEL","USE_TFMINIPLUS","USE_CSE7761","USE_BERRY",
"USE_BM8563","USE_ENERGY_DUMMY","USE_AM2320","USE_T67XX",
"USE_MCP2515","USE_TASMESH","USE_WIFI_RANGE_EXTENDER","USE_INFLUXDB",
"USE_HRG15","","","",
"USE_HRG15","USE_VINDRIKTNING","","",
"","","","",
"","","","",
"","","","",
@ -288,7 +288,7 @@ else:
obj = json.load(fp)
def StartDecode():
print ("\n*** decode-status.py v20210825 by Theo Arends and Jacek Ziolkowski ***")
print ("\n*** decode-status.py v20210826 by Theo Arends and Jacek Ziolkowski ***")
# print("Decoding\n{}".format(obj))