Skip to content

Commit

Permalink
test for emulating outdoor sensor, emsesp#2174
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelDvP committed Nov 9, 2024
1 parent 13c0707 commit 4d29dd1
Show file tree
Hide file tree
Showing 21 changed files with 142 additions and 23 deletions.
1 change: 1 addition & 0 deletions interface/src/app/main/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export interface Settings {
modbus_max_clients: number;
modbus_timeout: number;
developer_mode: boolean;
outdoorsensor: boolean;
}

export enum busConnectionStatus {
Expand Down
10 changes: 10 additions & 0 deletions interface/src/app/settings/ApplicationSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -697,6 +697,16 @@ const ApplicationSettings = () => {
}
label={LL.DEVELOPER_MODE()}
/>
<BlockFormControlLabel
control={
<Checkbox
checked={data.outdoorsensor}
onChange={updateFormValue}
name="outdoorsensor"
/>
}
label={LL.OUTDOORSENSOR()}
/>
<BlockFormControlLabel
control={
<Checkbox
Expand Down
3 changes: 2 additions & 1 deletion interface/src/i18n/cz/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,8 @@ const cz: Translation = {
DASHBOARD: 'Dashboard',
NO_DATA: 'Žádná data nejsou k dispozici',
DASHBOARD_1: 'Přizpůsobte si dashboard označením EMS entit jako Oblíbené pomocí modulu Přizpůsobení',
DEVELOPER_MODE: 'Režim vývojáře'
DEVELOPER_MODE: 'Režim vývojáře',
OUTDOORSENSOR: 'Emulate outdoorsensor' // TODO translate
};

export default cz;
3 changes: 2 additions & 1 deletion interface/src/i18n/de/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,8 @@ const de: Translation = {
DASHBOARD: 'Dashboard',
NO_DATA: 'Keine Daten verfügbar',
DASHBOARD_1: 'Passen Sie Ihr Dashboard an, indem Sie EMS-Entitäten mithilfe des Moduls „Anpassungen“ als Favorit markieren',
DEVELOPER_MODE: 'Entwicklermodus'
DEVELOPER_MODE: 'Entwicklermodus',
OUTDOORSENSOR: 'Emuliere Außentemperatursensor'
};

export default de;
3 changes: 2 additions & 1 deletion interface/src/i18n/en/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,8 @@ const en: Translation = {
DASHBOARD: 'Dashboard',
NO_DATA: 'No data available',
DASHBOARD_1: 'Customize your dashboard by marking EMS entities as Favorite using the Customizations module',
DEVELOPER_MODE: 'Developer Mode'
DEVELOPER_MODE: 'Developer Mode',
OUTDOORSENSOR: 'Emulate outdoorsensor'
};

export default en;
3 changes: 2 additions & 1 deletion interface/src/i18n/fr/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,8 @@ const fr: Translation = {
DASHBOARD: 'Dashboard', // TODO translate
NO_DATA: 'No data available', // TODO translate
DASHBOARD_1: 'Customize your dashboard by marking EMS entities as Favorite using the Customizations module', // TODO translate
DEVELOPER_MODE: 'Developer Mode' // TODO translate
DEVELOPER_MODE: 'Developer Mode', // TODO translate
OUTDOORSENSOR: 'Emulate outdoorsensor' // TODO translate
};

export default fr;
3 changes: 2 additions & 1 deletion interface/src/i18n/it/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,8 @@ const it: Translation = {
DASHBOARD: 'Dashboard', // TODO translate
NO_DATA: 'No data available', // TODO translate
DASHBOARD_1: 'Customize your dashboard by marking EMS entities as Favorite using the Customizations module', // TODO translate
DEVELOPER_MODE: 'Developer Mode' // TODO translate
DEVELOPER_MODE: 'Developer Mode', // TODO translate
OUTDOORSENSOR: 'Emulate outdoorsensor' // TODO translate
};

export default it;
3 changes: 2 additions & 1 deletion interface/src/i18n/nl/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,8 @@ const nl: Translation = {
DASHBOARD: 'Dashboard', // TODO translate
NO_DATA: 'No data available', // TODO translate
DASHBOARD_1: 'Customize your dashboard by marking EMS entities as Favorite using the Customizations module', // TODO translate
DEVELOPER_MODE: 'Developer Mode' // TODO translate
DEVELOPER_MODE: 'Developer Mode', // TODO translate
OUTDOORSENSOR: 'Emulate outdoorsensor' // TODO translate
};

export default nl;
3 changes: 2 additions & 1 deletion interface/src/i18n/no/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,8 @@ const no: Translation = {
DASHBOARD: 'Dashboard', // TODO translate
NO_DATA: 'No data available', // TODO translate
DASHBOARD_1: 'Customize your dashboard by marking EMS entities as Favorite using the Customizations module', // TODO translate
DEVELOPER_MODE: 'Developer Mode' // TODO translate
DEVELOPER_MODE: 'Developer Mode', // TODO translate
OUTDOORSENSOR: 'Emulate outdoorsensor' // TODO translate
};

export default no;
3 changes: 2 additions & 1 deletion interface/src/i18n/pl/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,8 @@ const pl: BaseTranslation = {
DASHBOARD: 'Dashboard', // TODO translate
NO_DATA: 'No data available', // TODO translate
DASHBOARD_1: 'Customize your dashboard by marking EMS entities as Favorite using the Customizations module', // TODO translate
DEVELOPER_MODE: 'Developer Mode' // TODO translate
DEVELOPER_MODE: 'Developer Mode', // TODO translate
OUTDOORSENSOR: 'Emulate outdoorsensor' // TODO translate
};

export default pl;
3 changes: 2 additions & 1 deletion interface/src/i18n/sk/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,8 @@ const sk: Translation = {
DASHBOARD: 'Panel',
NO_DATA: 'Nie sú k dispozícii žiadne údaje',
DASHBOARD_1: 'Prispôsobte si svoj informačný panel tak, že označíte entity EMS ako Obľúbené pomocou modulu Prispôsobenia',
DEVELOPER_MODE: 'Developer Mode' // TODO translate
DEVELOPER_MODE: 'Developer Mode', // TODO translate
OUTDOORSENSOR: 'Emulate outdoorsensor' // TODO translate
};

export default sk;
3 changes: 2 additions & 1 deletion interface/src/i18n/sv/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,8 @@ const sv: Translation = {
DASHBOARD: 'Dashboard', // TODO translate
NO_DATA: 'No data available', // TODO translate
DASHBOARD_1: 'Customize your dashboard by marking EMS entities as Favorite using the Customizations module', // TODO translate
DEVELOPER_MODE: 'Developer Mode' // TODO translate
DEVELOPER_MODE: 'Developer Mode', // TODO translate
OUTDOORSENSOR: 'Emulate outdoorsensor' // TODO translate
};

export default sv;
3 changes: 2 additions & 1 deletion interface/src/i18n/tr/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,8 @@ const tr: Translation = {
DASHBOARD: 'Dashboard', // TODO translate
NO_DATA: 'No data available', // TODO translate
DASHBOARD_1: 'Customize your dashboard by marking EMS entities as Favorite using the Customizations module', // TODO translate
DEVELOPER_MODE: 'Developer Mode' // TODO translate
DEVELOPER_MODE: 'Developer Mode', // TODO translate
OUTDOORSENSOR: 'Emulate outdoorsensor' // TODO translate
};

export default tr;
31 changes: 24 additions & 7 deletions src/devices/connect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,22 @@ Connect::Connect(uint8_t device_type, uint8_t device_id, uint8_t product_id, con
: EMSdevice(device_type, device_id, product_id, version, name, flags, brand) {
if (device_id == 0x50) { // RF Base
register_telegram_type(0xD1, "RFOutdoorTemp", false, MAKE_PF_CB(process_OutdoorTemp));
register_device_value(DeviceValueTAG::TAG_DEVICE_DATA,
&outdoorTemp_,
DeviceValueType::INT16,
DeviceValueNumOp::DV_NUMOP_DIV10,
FL_(outdoorTemp),
DeviceValueUOM::DEGREES);
if (Roomctrl::has_outdoorsensor()) {
register_device_value(DeviceValueTAG::TAG_DEVICE_DATA,
&outdoorTemp_,
DeviceValueType::INT16,
DeviceValueNumOp::DV_NUMOP_DIV10,
FL_(outdoorTemp),
DeviceValueUOM::DEGREES,
MAKE_CF_CB(set_outdoorTemp), -30, 80);
} else {
register_device_value(DeviceValueTAG::TAG_DEVICE_DATA,
&outdoorTemp_,
DeviceValueType::INT16,
DeviceValueNumOp::DV_NUMOP_DIV10,
FL_(outdoorTemp),
DeviceValueUOM::DEGREES);
}
}
}
/*
Expand All @@ -46,6 +56,13 @@ void Connect::process_OutdoorTemp(std::shared_ptr<const Telegram> telegram) {
(0x0880), data: 01 04
(0x0889), data: 00 80 80 01
*/

bool Connect::set_outdoorTemp(const char * value, const int8_t id) {
float v;
if (Roomctrl::has_outdoorsensor() && Helpers::value2temperature(value, v)) {
Roomctrl::set_outdoortemp(v * 10);
return true;
}
return false;
}

} // namespace emsesp
1 change: 1 addition & 0 deletions src/devices/connect.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class Connect : public EMSdevice {

private:
void process_OutdoorTemp(std::shared_ptr<const Telegram> telegram);
bool set_outdoorTemp(const char * value, const int8_t id);
int16_t outdoorTemp_;
};

Expand Down
3 changes: 3 additions & 0 deletions src/emsdevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,9 @@ uint8_t EMSdevice::device_name_2_device_type(const char * topic) {
if (!strcmp(lowtopic, F_(pool))) {
return DeviceType::POOL;
}
if (!strcmp(lowtopic, F_(connect))) {
return DeviceType::CONNECT;
}

// non EMS
if (!strcmp(lowtopic, F_(custom))) {
Expand Down
11 changes: 8 additions & 3 deletions src/emsesp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -685,7 +685,7 @@ void EMSESP::publish_thermostat_timer() {
const char * name[] = {FL_(switchprog)[0], FL_(circswitchprog)[0]};
for (uint8_t i = 0; i < sizeof(name) / sizeof(char *); i++) {
if (emsdevice->get_value_info(json, name[i], tag)) {
if (json.containsKey("value")) {
if (json["value"].is<JsonVariantConst>()) {
if ((Mqtt::is_nested())) {
if (circuit.isNull()) {
circuit = output[EMSdevice::tag_to_mqtt(tag)].to<JsonObject>();
Expand Down Expand Up @@ -715,9 +715,9 @@ void EMSESP::publish_other_values() {
publish_device_values(EMSdevice::DeviceType::EXTENSION);
publish_device_values(EMSdevice::DeviceType::ALERT);
publish_device_values(EMSdevice::DeviceType::POOL);
publish_device_values(EMSdevice::DeviceType::CONNECT);
// other EMS devices without values yet
// publish_device_values(EMSdevice::DeviceType::GATEWAY);
// publish_device_values(EMSdevice::DeviceType::CONNECT);
// publish_device_values(EMSdevice::DeviceType::GENERIC);

webSchedulerService.publish();
Expand Down Expand Up @@ -1501,6 +1501,11 @@ void EMSESP::incoming_telegram(uint8_t * data, const uint8_t length) {
} else if (first_value == TxService::TX_WRITE_FAIL) {
LOG_ERROR("Last Tx write rejected by host");
txservice_.send_poll(); // close the bus
txservice_.reset_retry_count();
tx_successful = true; // no retries
} else {
txservice_.send_poll(); // close the bus
LOG_ERROR("Last Tx write host reply: 0x%02X", first_value);
}
} else if (tx_state == Telegram::Operation::TX_READ && length == 1) {
EMSbus::tx_state(Telegram::Operation::TX_READ); // reset Tx wait state
Expand Down Expand Up @@ -1808,7 +1813,7 @@ void EMSESP::start_serial_console() {
#if defined(EMSESP_DEBUG)
shell_->log_level(uuid::log::Level::DEBUG);
#else
shell_->log_level(uuid::log::Level::TRACE);
shell_->log_level(uuid::log::Level::INFO);
#endif
}

Expand Down
58 changes: 56 additions & 2 deletions src/roomcontrol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,22 @@ int16_t Roomctrl::remotetemp_[HCS] = {EMS_VALUE_INT16_NOTSET, EMS_VALUE_INT16
uint8_t Roomctrl::remotehum_[HCS] = {EMS_VALUE_UINT8_NOTSET, EMS_VALUE_UINT8_NOTSET, EMS_VALUE_UINT8_NOTSET, EMS_VALUE_UINT8_NOTSET};
uint8_t Roomctrl::sendtype_[HCS] = {SendType::TEMP, SendType::TEMP, SendType::TEMP, SendType::TEMP};
uint8_t Roomctrl::type_[HCS] = {RemoteType::NONE, RemoteType::NONE, RemoteType::NONE, RemoteType::NONE};
int16_t Roomctrl::outdoortemp_ = 0; // EMS_VALUE_INT16_NOTSET;
uint32_t Roomctrl::outdoortime_ = 0;
bool Roomctrl::outdoorsensor_ = false;
uint32_t Roomctrl::timeout_ = 0;

/**
* set the temperature,
*/
void Roomctrl::set_outdoortemp(const int16_t temp) {
outdoortemp_ = temp < 1000 ? temp : EMS_VALUE_INT16_NOTSET;
}

void Roomctrl::set_timeout(uint8_t t) {
timeout_ = t * 3600000; // ms
}

void Roomctrl::set_remotetemp(const uint8_t type, const uint8_t hc, const int16_t temp) {
if (!type_[hc] && !type) {
return;
Expand Down Expand Up @@ -91,11 +99,22 @@ void Roomctrl::send(uint8_t addr) {
if (addr & 0x80) {
return;
}
if (addr == 0x50 && outdoorsensor_) {
if (uuid::get_uptime() - outdoortime_ > SEND_INTERVAL && outdoortemp_ != EMS_VALUE_INT16_NOTSET) {
outdoortemp(addr, 0);
outdoortime_ = uuid::get_uptime();
return;
} else {
EMSuart::send_poll(addr | EMSbus::ems_mask());
return;
}
}
uint8_t hc = get_hc(addr);
// check address, reply only on addresses 0x18..0x1B or 0x40..0x43
if (hc >= HCS) {
return;
}

// no reply if the temperature is not set
if (!switch_off_[hc] && remotetemp_[hc] == EMS_VALUE_INT16_NOTSET && remotehum_[hc] == EMS_VALUE_UINT8_NOTSET) {
return;
Expand Down Expand Up @@ -145,6 +164,15 @@ void Roomctrl::send(uint8_t addr) {
* check if there is a message for the remote room controller
*/
void Roomctrl::check(uint8_t addr, const uint8_t * data, const uint8_t length) {
// check for read of outdoor temp
if (addr == 0xD0 && outdoorsensor_) {
if (data[2] == 0xD1) {
outdoortemp(0x50, data[0]);
} else if (data[2] == 0x02) {
wirelessversion(0x50, data[0]);
}
return;
}
uint8_t hc = get_hc(addr);
if (hc >= HCS || length < 5) {
return;
Expand Down Expand Up @@ -252,6 +280,19 @@ void Roomctrl::version(uint8_t addr, uint8_t dst, uint8_t hc) {
}
}

void Roomctrl::wirelessversion(uint8_t addr, uint8_t dst) {
uint8_t data[20];
data[0] = addr | EMSbus::ems_mask();
data[1] = dst & 0x7F;
data[2] = 0x02;
data[3] = 0;
data[4] = 236; // product_id 236
data[5] = 3; // version 3.03
data[6] = 3;
data[7] = EMSbus::calculate_crc(data, 7); // append CRC
EMSuart::transmit(data, 8);
}

/**
* unknown message id, we reply with empty message
*/
Expand Down Expand Up @@ -308,7 +349,7 @@ void Roomctrl::temperature(uint8_t addr, uint8_t dst, uint8_t hc) {
data[5] = 0x2B + hc;
data[6] = (uint8_t)(remotetemp_[hc] >> 8);
data[7] = (uint8_t)(remotetemp_[hc] & 0xFF);
uint16_t t1 = remotetemp_[hc] * 10 + 3;
uint16_t t1 = remotetemp_[hc] * 10;
data[8] = (uint8_t)(t1 >> 8);
data[9] = (uint8_t)(t1 & 0xFF);
data[10] = 1; // not sure what this is and if we need it, maybe mode?
Expand Down Expand Up @@ -339,7 +380,7 @@ void Roomctrl::temperature(uint8_t addr, uint8_t dst, uint8_t hc) {
data[5] = 0x2B + hc;
data[6] = (uint8_t)(remotetemp_[hc] >> 8);
data[7] = (uint8_t)(remotetemp_[hc] & 0xFF);
uint16_t t1 = remotetemp_[hc] * 10 + 3;
uint16_t t1 = remotetemp_[hc] * 10;
data[8] = (uint8_t)(t1 >> 8);
data[9] = (uint8_t)(t1 & 0xFF);
data[10] = 1; // not sure what this is and if we need it, maybe mode?
Expand Down Expand Up @@ -422,5 +463,18 @@ int16_t Roomctrl::calc_dew(int16_t temp, uint8_t humi) {
return dt;
}

void Roomctrl::outdoortemp(uint8_t addr, uint8_t dst) {
uint8_t data[12];
data[0] = addr | EMSbus::ems_mask();
data[1] = dst & 0x7F;
data[2] = 0xD1;
data[3] = 0;
data[4] = (uint8_t)(outdoortemp_ >> 8);
data[5] = (uint8_t)(outdoortemp_ & 0xFF);
data[6] = 0;
data[7] = EMSbus::calculate_crc(data, 7); // apppend CRC
EMSuart::transmit(data, 8);
}


} // namespace emsesp
12 changes: 12 additions & 0 deletions src/roomcontrol.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ class Roomctrl {
static void check(uint8_t addr, const uint8_t * data, const uint8_t length);
static void set_remotetemp(const uint8_t type, const uint8_t hc, const int16_t temp);
static void set_remotehum(const uint8_t type, const uint8_t hc, const int8_t hum);
static void set_outdoorsensor(const bool enable) {
outdoorsensor_ = enable;
}
static bool has_outdoorsensor() {
return outdoorsensor_ ;
}
static void set_outdoortemp(const int16_t temp);
static bool is_remote(const uint8_t hc) {
return (hc < 4 && remotetemp_[hc] != EMS_VALUE_INT16_NOTSET);
}
Expand All @@ -51,6 +58,8 @@ class Roomctrl {
static void ack_write();
static void replyF7(uint8_t addr, uint8_t dst, uint8_t offset, uint8_t typehh, uint8_t typeh, uint8_t typel, uint8_t hc);
static int16_t calc_dew(int16_t temp, uint8_t hum);
static void outdoortemp(uint8_t addr, uint8_t dst);
static void wirelessversion(uint8_t addr, uint8_t dst);

static bool switch_off_[HCS];
static uint32_t send_time_[HCS];
Expand All @@ -59,6 +68,9 @@ class Roomctrl {
static uint8_t remotehum_[HCS];
static uint8_t sendtype_[HCS];
static uint8_t type_[HCS]; // type is product-id 113 for RC20 or 109 for Junkers FB10
static int16_t outdoortemp_;
static uint32_t outdoortime_;
static bool outdoorsensor_;
static uint32_t timeout_;
};

Expand Down
Loading

0 comments on commit 4d29dd1

Please sign in to comment.