Skip to content

Commit

Permalink
fix HA discovery
Browse files Browse the repository at this point in the history
  • Loading branch information
softwarecrash committed Nov 9, 2023
1 parent e13c2eb commit 16deaf3
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 62 deletions.
123 changes: 62 additions & 61 deletions src/VeDirectDataList.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,66 +66,67 @@ static const char * VePrettyData[][3] PROGMEM {
};
static const char * haDescriptor[][4] PROGMEM {
// state_topic, icon, unit_ofmeasurement, class
{"Voltage", "mdi:car-battery", "V", "voltage"},
{"Voltage_2", "mdi:car-battery", "V", "voltage"},
{"Voltage_3", "mdi:car-battery", "V", "voltage"},
{"Starter_voltage", "mdi:flash-triangle-outline", "V", "voltage"},
{"Mid_voltage", "mdi:battery-outline", "V", "voltage"},
{"Voltage", "car-battery", "V", "voltage"},
{"Voltage_2", "car-battery", "V", "voltage"},
{"Voltage_3", "car-battery", "V", "voltage"},
{"Starter_voltage", "flash-triangle-outline", "V", "voltage"},
{"Mid_voltage", "battery-outline", "V", "voltage"},
{"Mid_deviation", "", "%", ""},
{"Panel_voltage", "mdi:solar-panel", "V", "voltage"},
{"Battery_current", "mdi:current-dc", "A", "current"},
{"Battery_current_2", "mdi:current-dc", "A", "current"},
{"Battery_current_3", "mdi:current-dc", "A", "current"},
{"Load_current", "mdi:battery-charging", "A", "current"},
{"Load_output_state", "mdi:export", "", ""},
{"Battery_temperature", "mdi:thermometer", "C", "thermometer"},
{"Instantaneous_power", "mdi:solar-power", "W", "power"},
{"Consumed_Amp_Hours", "mdi:home-battery-outline", "Ah", ""},
{"SOC", "mdi:battery-charging", "%", "battery"},
{"Time_to_go", "mdi:camera-timer", "min", "duration"},
{"Alarm", "mdi:alarm-light-outline", "", ""},
{"Relay", "mdi:electric-switch", "", ""},
{"Alarm_code", "mdi:alarm-panel-outline", "", ""},
{"Off_reason", "mdi:alarm-panel-outline", "", ""},
{"Deepest_discharge", "mdi:battery-outline", "Ah", ""},
{"Last_discharge", "mdi:battery-outline", "Ah", ""},
{"Average_discharge", "mdi:battery-outline", "Ah", ""},
{"Charge_cycles", "mdi:counter", "", ""},
{"Full_discharges", "mdi:counter", "", ""},
{"Cumulative_Ah_drawn", "mdi:battery-outline", "Ah", ""},
{"Minimum_voltage", "mdi:battery-charging-outline", "V", "voltage"},
{"Maximum_voltage", "mdi:battery-charging-high", "V", "voltage"},
{"Last_full_charge", "mdi:clock-time-eight-outline", "h", "duration"},
{"Num_automatic_sync", "mdi:counter", "", ""},
{"Num_low_volt_alarms", "mdi:counter", "", ""},
{"Num_high_volt_alarms", "mdi:counter", "", ""},
{"Num_low_aux_vol_alarms", "mdi:counter", "", ""},
{"Num_high_aux_vol_alarms", "mdi:counter", "", ""},
{"Min_aux_volt", "mdi:battery-low", "V", "voltage"},
{"Max_aux_volt", "mdi:battery-high", "V", "voltage"},
{"Amount_discharged_energy", "mdi:battery-arrow-down-outline", "kWh", "energy"},
{"Amount_charged_energy", "mdi:battery-arrow-up-outline", "kWh", "energy"},
{"total_kWh", "mdi:solar-power", "kWh", "energy"},
{"today_kWh", "mdi:solar-power", "kWh", "energy"},
{"Max_pow_today", "mdi:solar-power-variant-outline", "W", "power"},
{"Yesterday_kWh", "mdi:solar-power", "kWh", "energy"},
{"Max_pow_yesterday", "mdi:solar-power-variant-outline", "W", "power"},
{"Current_error", "mdi:alert-circle-outline", "", ""},
{"Operation_state", "", "", ""},
{"Model_description", "", "", ""},
{"Firmware_version_16", "", "", ""},
{"Firmware_version_24", "", "", ""},
{"Device_model", "", "", ""},
{"Serial_number", "", "", ""},
{"Day", "", "", ""},
{"Device_mode", "", "", ""},
{"AC_out_volt", "mdi:current-ac", "V", "voltage"},
{"AC_out_current", "mdi:current-ac", "A", "current"},
{"AC_out_apparent_pow", "mdi:current-ac", "VA", "apparent_power"},
{"Warning_reason", "", "", ""},
{"Tracker_operation_mode", "", "", ""},
{"DC_monitor_mode", "", "", ""},
{"DC_input_voltage", "mdi:current-dc", "V", "voltage"},
{"DC_input_current", "mdi:current-dc", "A", "current"},
{"DC_input_power", "mdi:current-dc", "W", "power"}
{"Panel_voltage", "solar-panel", "V", "voltage"},
{"Panel_power","solar-power","W","power"},
{"Battery_current", "current-dc", "A", "current"},
{"Battery_current_2", "current-dc", "A", "current"},
{"Battery_current_3", "current-dc", "A", "current"},
{"Load_current", "battery-charging", "A", "current"},
{"Load_output_state", "export", "", ""},
{"Battery_temperature", "thermometer", "C", "thermometer"},
{"Instantaneous_power", "solar-power", "W", "power"},
{"Consumed_Amp_Hours", "home-battery-outline", "Ah", ""},
{"SOC", "battery-charging", "%", "battery"},
{"Time_to_go", "camera-timer", "min", "duration"},
{"Alarm", "alarm-light-outline", "", ""},
{"Relay", "electric-switch", "", ""},
{"Alarm_code", "alarm-panel-outline", "", ""},
{"Off_reason", "alarm-panel-outline", "", ""},
{"Deepest_discharge", "battery-outline", "Ah", ""},
{"Last_discharge", "battery-outline", "Ah", ""},
{"Average_discharge", "battery-outline", "Ah", ""},
{"Charge_cycles", "counter", "", ""},
{"Full_discharges", "counter", "", ""},
{"Cumulative_Ah_drawn", "battery-outline", "Ah", ""},
{"Minimum_voltage", "battery-charging-outline", "V", "voltage"},
{"Maximum_voltage", "battery-charging-high", "V", "voltage"},
{"Last_full_charge", "clock-time-eight-outline", "h", "duration"},
{"Num_automatic_sync", "counter", "", ""},
{"Num_low_volt_alarms", "counter", "", ""},
{"Num_high_volt_alarms", "counter", "", ""},
{"Num_low_aux_vol_alarms", "counter", "", ""},
{"Num_high_aux_vol_alarms", "counter", "", ""},
{"Min_aux_volt", "battery-low", "V", "voltage"},
{"Max_aux_volt", "battery-high", "V", "voltage"},
{"Amount_discharged_energy", "battery-arrow-down-outline", "kWh", "energy"},
{"Amount_charged_energy", "battery-arrow-up-outline", "kWh", "energy"},
{"total_kWh", "solar-power", "kWh", "energy"},
{"today_kWh", "solar-power", "kWh", "energy"},
{"Max_pow_today", "solar-power-variant-outline", "W", "power"},
{"Yesterday_kWh", "solar-power", "kWh", "energy"},
{"Max_pow_yesterday", "solar-power-variant-outline", "W", "power"},
{"Current_error", "alert-circle-outline", "", ""},
{"Operation_state", "eye", "", ""},
{"Model_description", "eye", "", ""},
{"Firmware_version_16", "eye", "", ""},
{"Firmware_version_24", "eye", "", ""},
{"Device_model", "eye", "", ""},
{"Serial_number", "eye", "", ""},
{"Day", "eye", "", ""},
{"Device_mode", "eye", "", ""},
{"AC_out_volt", "current-ac", "V", "voltage"},
{"AC_out_current", "current-ac", "A", "current"},
{"AC_out_apparent_pow", "current-ac", "VA", "apparent_power"},
{"Warning_reason", "eye", "", ""},
{"Tracker_operation_mode", "eye", "", ""},
{"DC_monitor_mode", "eye", "", ""},
{"DC_input_voltage", "current-dc", "V", "voltage"},
{"DC_input_current", "current-dc", "A", "current"},
{"DC_input_power", "current-dc", "W", "power"}
};
2 changes: 1 addition & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -717,7 +717,7 @@ bool sendHaDiscovery()
{
sprintf(topBuff, "homeassistant/sensor/%s/%s/config", _settings.data.deviceName, haDescriptor[i][0]); // build the topic

mqttContentLength = sprintf(configBuff, "{\"state_topic\": \"%s/%s\",\"unique_id\": \"sensor.%s_%s\",\"name\": \"%s\",\"icon\": \"%s\",\"unit_of_measurement\": \"%s\",\"device_class\":\"%s\",\"device\":{\"identifiers\":[\"%s\"], \"configuration_url\":\"http://%s\",\"name\":\"%s\", \"model\":\"%s\",\"manufacturer\":\"SoftWareCrash\",\"sw_version\":\"Victron2MQTT %s\"}}",
mqttContentLength = sprintf(configBuff, "{\"state_topic\": \"%s/%s\",\"unique_id\": \"sensor.%s_%s\",\"name\": \"%s\",\"icon\": \"mdi:%s\",\"unit_of_measurement\": \"%s\",\"device_class\":\"%s\",\"device\":{\"identifiers\":[\"%s\"], \"configuration_url\":\"http://%s\",\"name\":\"%s\", \"model\":\"%s\",\"manufacturer\":\"SoftWareCrash\",\"sw_version\":\"Victron2MQTT %s\"}}",
_settings.data.mqttTopic, haDescriptor[i][0], _settings.data.deviceName, haDescriptor[i][0], haDescriptor[i][0], haDescriptor[i][1], haDescriptor[i][2], haDescriptor[i][3], Json["Serial_number"].as<String>().c_str(), jsonESP["IP"].as<String>().c_str(), _settings.data.deviceName, Json["Model_description"].as<String>().c_str(), SOFTWARE_VERSION);

mqttclient.beginPublish(topBuff, mqttContentLength, true);
Expand Down

0 comments on commit 16deaf3

Please sign in to comment.