mirror of
https://github.com/openshwprojects/OpenBK7231T_App.git
synced 2026-02-14 00:35:25 +00:00
BL0492 Frequency to HASS (MQTT) + Energy calculation in TWIN_BL_ENABLED mode for channel 2 (#1578)
* twinbl energy for channel 2 * . * removed movavg * Added HASS MQTT frequency (both standard and TWIN_MODE) * . * simplify, store total only IX0 * Ext BugFix: addChangeHandler Power < 20 appears broken #1543
This commit is contained in:
@ -292,6 +292,9 @@ HassDeviceInfo* hass_init_device_info(ENTITY_TYPE type, int index, const char* p
|
||||
isSensor = (type == BATTERY_VOLTAGE_SENSOR);
|
||||
sprintf(g_hassBuffer, "Voltage");
|
||||
break;
|
||||
case FREQUENCY_SENSOR:
|
||||
sprintf(g_hassBuffer, "Frequency");
|
||||
break;
|
||||
case ILLUMINANCE_SENSOR:
|
||||
sprintf(g_hassBuffer, "Illuminance");
|
||||
break;
|
||||
@ -474,7 +477,12 @@ HassDeviceInfo* hass_init_energy_sensor_device_info(int index, int asensdataseti
|
||||
//device_class automatically assigns unit,icon
|
||||
if (index > OBK__LAST) return info;
|
||||
if (index >= OBK_CONSUMPTION__DAILY_FIRST && !DRV_IsRunning("NTP")) return info; //include daily stats only when time is valid
|
||||
|
||||
#ifdef ENABLE_BL_TWIN
|
||||
//in twin mode, for ix1 is possible to skip OBK_VOLTAGE, dont skip for now
|
||||
//if ((asensdatasetix>0) && (index==OBK_VOLTAGE)) return info;
|
||||
//in twin mode, for ix0 is last OBK_CONSUMPTION_YESTERDAY, for ix1 ,OBK_CONSUMPTION_TODAY
|
||||
if ((index > OBK_CONSUMPTION_STORED_LAST[asensdatasetix]) && (index <= OBK_CONSUMPTION__DAILY_LAST)) return info;
|
||||
#endif
|
||||
info = hass_init_device_info(ENERGY_METER_SENSOR, index, NULL, NULL, asensdatasetix);
|
||||
|
||||
cJSON_AddStringToObject(info->root, "dev_cla", DRV_GetEnergySensorNamesEx(asensdatasetix,index)->hass_dev_class); //device_class=voltage,current,power, energy, timestamp
|
||||
|
||||
@ -1890,15 +1890,21 @@ void doHomeAssistantDiscovery(const char* topic, http_request_t* request) {
|
||||
hass_free_device_info(dev_info);
|
||||
discoveryQueued = true;
|
||||
}
|
||||
if (i == OBK_VOLTAGE) {
|
||||
//20250319 XJIKKA to simplify and save space in flash frequency together with voltage
|
||||
dev_info = hass_init_sensor_device_info(FREQUENCY_SENSOR, SPECIAL_CHANNEL_OBK_FREQUENCY, -1, -1, -1);
|
||||
if (dev_info) {
|
||||
MQTT_QueuePublish(topic, dev_info->channel, hass_build_discovery_json(dev_info), OBK_PUBLISH_FLAG_RETAIN);
|
||||
hass_free_device_info(dev_info);
|
||||
discoveryQueued = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
#if ENABLE_BL_TWIN
|
||||
//BL_SENSORS_IX_1 - mqtt hass discovery using hass_uniq_id_suffix (_b) from drv_bl_shared.c
|
||||
if (BL_IsMeteringDeviceIndexActive(BL_SENSORS_IX_1)) {
|
||||
for (i = OBK__FIRST; i <= OBK__LAST; i++)
|
||||
{
|
||||
//BL_SENSORS_IX_1 does not have energy yet, just base OBK_VOLTAGE..OBK_POWER_FACTOR
|
||||
if (i < OBK_VOLTAGE) continue;
|
||||
if (i > OBK_POWER_FACTOR) continue;
|
||||
dev_info = hass_init_energy_sensor_device_info(i, BL_SENSORS_IX_1);
|
||||
if (dev_info) {
|
||||
MQTT_QueuePublish(topic, dev_info->channel, hass_build_discovery_json(dev_info), OBK_PUBLISH_FLAG_RETAIN);
|
||||
|
||||
Reference in New Issue
Block a user