From dcb4d5551eb16c82404620d2bbc85a98a1aed380 Mon Sep 17 00:00:00 2001 From: Northern Man <19808920+NorthernMan54@users.noreply.github.com> Date: Wed, 25 Jan 2023 10:58:18 -0500 Subject: [PATCH] Add device_class to MQTT Discovery for rtl_433_ESP (#1419) * Add device_class to rtl_433_ESP discovery --- main/ZgatewayRTL_433.ino | 6 +-- main/config_RF.h | 82 ++++++++++++++++++++-------------------- 2 files changed, 44 insertions(+), 44 deletions(-) diff --git a/main/ZgatewayRTL_433.ino b/main/ZgatewayRTL_433.ino index 8c0fbf6..84fad06 100644 --- a/main/ZgatewayRTL_433.ino +++ b/main/ZgatewayRTL_433.ino @@ -144,7 +144,7 @@ void launchRTL_433Discovery(bool overrideDiscovery) { if (strcmp(parameters[i][0], "tamper") == 0 || strcmp(parameters[i][0], "alarm") == 0 || strcmp(parameters[i][0], "motion") == 0) { createDiscovery("binary_sensor", //set Type (char*)topic.c_str(), parameters[i][1], pdevice->uniqueId, //set state_topic,name,uniqueId - "", "", (char*)value_template.c_str(), //set availability_topic,device_class,value_template, + "", parameters[i][3], (char*)value_template.c_str(), //set availability_topic,device_class,value_template, "1", "0", parameters[i][2], //set,payload_on,payload_off,unit_of_meas, 0, //set off_delay "", "", false, "", //set,payload_available,payload_not available ,is a gateway entity, command topic @@ -154,7 +154,7 @@ void launchRTL_433Discovery(bool overrideDiscovery) { } else if (strcmp(parameters[i][0], "strike_count") == 0) { createDiscovery("sensor", //set Type (char*)topic.c_str(), parameters[i][1], pdevice->uniqueId, //set state_topic,name,uniqueId - "", "", (char*)value_template.c_str(), //set availability_topic,device_class,value_template, + "", parameters[i][3], (char*)value_template.c_str(), //set availability_topic,device_class,value_template, "1", "0", parameters[i][2], //set,payload_on,payload_off,unit_of_meas, 0, //set off_delay "", "", false, "", //set,payload_available,payload_not available ,is a gateway entity, command topic @@ -164,7 +164,7 @@ void launchRTL_433Discovery(bool overrideDiscovery) { } else { createDiscovery("sensor", //set Type (char*)topic.c_str(), parameters[i][1], pdevice->uniqueId, //set state_topic,name,uniqueId - "", "", (char*)value_template.c_str(), //set availability_topic,device_class,value_template, + "", parameters[i][3], (char*)value_template.c_str(), //set availability_topic,device_class,value_template, "", "", parameters[i][2], //set,payload_on,payload_off,unit_of_meas, 0, //set off_delay "", "", false, "", //set,payload_available,payload_not available ,is a gateway entity, command topic diff --git a/main/config_RF.h b/main/config_RF.h index f563fcf..587519e 100644 --- a/main/config_RF.h +++ b/main/config_RF.h @@ -82,47 +82,47 @@ struct RTL_433device { extern std::vector RTL_433devices; -const char parameters[39][3][16] = { - // RTL_433 key, name, unit - {"temperature_C", "temperature", "°C"}, - {"temperature_1_C", "temperature", "°C"}, - {"temperature_2_C", "temperature", "°C"}, - {"temperature_F", "temperature", "°F"}, - {"time", "timestamp", ""}, - {"battery_ok", "battery", ""}, - {"humidity", "humidity", "%"}, - {"moisture", "moisture", "%"}, - {"pressure_hPa", "pressure", "hPa"}, - {"pressure_kPa", "pressure", "kPa"}, - {"wind_speed_km_h", "wind speed", "km/h"}, - {"wind_avg_km_h", "wind average", "km/h"}, - {"wind_avg_mi_h", "wind average", "mi/h"}, - {"wind_avg_m_s", "wind average", "m/s"}, - {"wind_speed_m_s", "wind speed", "m/s"}, - {"gust_speed_km_h", "gust speed", "km/h"}, - {"wind_max_km_h", "wind max", "km/h"}, - {"wind_max_m_s", "wind max", "m/s"}, - {"gust_speed_m_s", "gust speed", "m/s"}, - {"wind_dir_deg", "wind direction", "°"}, - {"rain_mm", "rain", "mm"}, - {"rain_mm_h", "rain", "mm/h"}, - {"rain_in", "rain", "in"}, - {"rain_rate_in_h", "rain", "in/h"}, - {"rssi", "rssi", "dB"}, - {"snr", "snr", "dB"}, - {"noise", "noise", "dB"}, - {"depth_cm", "depth", "cm"}, - {"power_W", "power", "W"}, - {"light_lux", "light", "lx"}, - {"lux", "lux", "lx"}, - {"uv", "uv", "UV index"}, - {"uvi", "uvi", "UV index"}, - {"storm_dist", "storm distance", "mi"}, - {"strike_distance", "strike distance", "mi"}, - {"tamper", "tamper", ""}, - {"alarm", "alarm", ""}, - {"motion", "motion", ""}, - {"strike_count", "strike count", ""}}; // from rtl_433_mqtt_hass.py +const char parameters[39][4][24] = { + // RTL_433 key, name, unit, device_class + {"temperature_C", "temperature", "°C", "temperature"}, + {"temperature_1_C", "temperature", "°C", "temperature"}, + {"temperature_2_C", "temperature", "°C", "temperature"}, + {"temperature_F", "temperature", "°F", "temperature"}, + {"time", "timestamp", "", "timestamp"}, + {"battery_ok", "battery", "", "battery"}, + {"humidity", "humidity", "%", "humidity"}, + {"moisture", "moisture", "%", "humidity"}, + {"pressure_hPa", "pressure", "hPa", "pressure"}, + {"pressure_kPa", "pressure", "kPa", "pressure"}, + {"wind_speed_km_h", "wind speed", "km/h", "wind_speed"}, + {"wind_avg_km_h", "wind average", "km/h", "wind_speed"}, + {"wind_avg_mi_h", "wind average", "mi/h", "wind_speed"}, + {"wind_avg_m_s", "wind average", "m/s", "wind_speed"}, + {"wind_speed_m_s", "wind speed", "m/s", "wind_speed"}, + {"gust_speed_km_h", "gust speed", "km/h", "wind_speed"}, + {"wind_max_km_h", "wind max", "km/h", "wind_speed"}, + {"wind_max_m_s", "wind max", "m/s", "wind_speed"}, + {"gust_speed_m_s", "gust speed", "m/s", "wind_speed"}, + {"wind_dir_deg", "wind direction", "°", ""}, + {"rain_mm", "rain", "mm", "precipitation"}, + {"rain_mm_h", "rain", "mm/h", "precipitation"}, + {"rain_in", "rain", "in", "precipitation_intensity"}, + {"rain_rate_in_h", "rain", "in/h", "precipitation_intensity"}, + {"rssi", "rssi", "dB", "signal_strength"}, + {"snr", "snr", "dB", ""}, + {"noise", "noise", "dB", ""}, + {"depth_cm", "depth", "cm", ""}, + {"power_W", "power", "W", "power"}, + {"light_lux", "light", "lx", ""}, + {"lux", "lux", "lx", ""}, + {"uv", "uv", "UV index", ""}, + {"uvi", "uvi", "UV index", ""}, + {"storm_dist", "storm distance", "mi", ""}, + {"strike_distance", "strike distance", "mi", ""}, + {"tamper", "tamper", "", ""}, + {"alarm", "alarm", "", ""}, + {"motion", "motion", "", "motion"}, + {"strike_count", "strike count", "", ""}}; // from rtl_433_mqtt_hass.py # endif #endif /*-------------------RF topics & parameters----------------------*/