diff --git a/TeslaLogger/MQTT.cs b/TeslaLogger/MQTT.cs index b8ea54f0f..399a8e9be 100644 --- a/TeslaLogger/MQTT.cs +++ b/TeslaLogger/MQTT.cs @@ -549,7 +549,16 @@ internal void PublishDiscovery(string vin) foreach (string entity in MQTTAutoDiscovery.autoDiscovery.Keys) { Dictionary entitycontainer = MQTTAutoDiscovery.autoDiscovery[entity]; - Dictionary device = new Dictionary + + //mandotory + entitycontainer.TryGetValue("name", out string entityName); + entitycontainer.TryGetValue("type", out string entityType); + + entitycontainer.TryGetValue("discovery_active", out string active); + if (active == "true") + { + + Dictionary device = new Dictionary { { "ids", vin }, { "mf", "Tesla" }, @@ -557,75 +566,82 @@ internal void PublishDiscovery(string vin) { "name", name }, { "sw", sw } }; - Dictionary entityConfig = new Dictionary + Dictionary entityConfig = new Dictionary { { "dev", device } }; - //mandotory - entitycontainer.TryGetValue("name", out string entityName); - entitycontainer.TryGetValue("type", out string entityType); - //optional - entitycontainer.TryGetValue("icon", out string entityIcon); - entitycontainer.TryGetValue("class", out string entityClass); - entitycontainer.TryGetValue("unit", out string entityUnit); - //type dependent: - //switch - entitycontainer.TryGetValue("pl_on", out string entityTextOn); - entitycontainer.TryGetValue("pl_off", out string entityTextOff); - entitycontainer.TryGetValue("cmd_topic", out string entityControlTopic); - //switch - entitycontainer.TryGetValue("min", out string entityMin); - entitycontainer.TryGetValue("max", out string entityMax); - entitycontainer.TryGetValue("step", out string entityStep); - - entityConfig.Add("name", entityName); - entityConfig.Add("uniq_id", vin + "_" + entity); - entityConfig.Add("stat_t", $"{topic}/car/{vin}/{entity}"); - + + //optional + entitycontainer.TryGetValue("icon", out string entityIcon); + entitycontainer.TryGetValue("class", out string entityClass); + entitycontainer.TryGetValue("unit", out string entityUnit); + //type dependent: + //switch + entitycontainer.TryGetValue("pl_on", out string entityTextOn); + entitycontainer.TryGetValue("pl_off", out string entityTextOff); + entitycontainer.TryGetValue("cmd_topic", out string entityControlTopic); + //number + entitycontainer.TryGetValue("min", out string entityMin); + entitycontainer.TryGetValue("max", out string entityMax); + entitycontainer.TryGetValue("step", out string entityStep); + + entityConfig.Add("name", entityName); + entityConfig.Add("uniq_id", vin + "_" + entity); + entityConfig.Add("stat_t", $"{topic}/car/{vin}/{entity}"); + + + if (entityIcon != null) + { + entityConfig.Add("icon", entityIcon); + } + if (entityClass != null) + { + entityConfig.Add("dev_cla", entityClass); + } + if (entityUnit != null) + { + entityConfig.Add("unit_of_meas", entityUnit); + } + if (entityTextOn != null) + { + entityConfig.Add("pl_on", entityTextOn); + } + if (entityTextOff != null) + { + entityConfig.Add("pl_off", entityTextOff); + } + if (entityControlTopic != null) + { + entityConfig.Add("cmd_t", $"{topic}/command/{vin}/{entityControlTopic}"); + } + if (entityMin != null) + { + entityConfig.Add("min", entityMin); + } + if (entityMax != null) + { + entityConfig.Add("max", entityMax); + } + if (entityStep != null) + { + entityConfig.Add("step", entityStep); + } + var configJson = JsonConvert.SerializeObject(entityConfig); - if (entityIcon != null) - { - entityConfig.Add("icon", entityIcon); + client.Publish($"{discoverytopic}/{entityType}/{vin}/{entity}/config", Encoding.UTF8.GetBytes(configJson ?? "NULL"), + uPLibrary.Networking.M2Mqtt.Messages.MqttMsgBase.QOS_LEVEL_AT_LEAST_ONCE, true); + + Tools.DebugLog($"MQTT: AutoDiscovery for {vin}: " + entity); } - if (entityClass != null) - { - entityConfig.Add("dev_cla", entityClass); - } - if (entityUnit != null) - { - entityConfig.Add("unit_of_meas", entityUnit); - } - if (entityTextOn != null) - { - entityConfig.Add("pl_on", entityTextOn); - } - if (entityTextOff != null) - { - entityConfig.Add("pl_off", entityTextOff); - } - if (entityControlTopic != null) - { - entityConfig.Add("cmd_t", $"{topic}/command/{vin}/{entityControlTopic}"); - } - if (entityMin != null) - { - entityConfig.Add("min", entityMin); - } - if (entityMax != null) - { - entityConfig.Add("max", entityMax); - } - if (entityStep != null) + else { - entityConfig.Add("step", entityStep); + //if discovery_active is false or null, delete retainded discovery message from broker: send "null" to discovery config topic + client.Publish($"{discoverytopic}/{entityType}/{vin}/{entity}/config", null, + uPLibrary.Networking.M2Mqtt.Messages.MqttMsgBase.QOS_LEVEL_AT_LEAST_ONCE, false); + Tools.DebugLog($"MQTT: AutoDiscovery removed {vin}: " + entity); } - var configJson = JsonConvert.SerializeObject(entityConfig); - - client.Publish($"{discoverytopic}/{entityType}/{vin}/{entity}/config", Encoding.UTF8.GetBytes(configJson ?? "NULL"), - uPLibrary.Networking.M2Mqtt.Messages.MqttMsgBase.QOS_LEVEL_AT_LEAST_ONCE, true); - - Tools.DebugLog($"MQTT: AutoDiscovery for {vin}: " + entity); + } //special case: GPS Tracker diff --git a/TeslaLogger/MQTTAutoDiscovery.cs b/TeslaLogger/MQTTAutoDiscovery.cs index 59e24fa6d..cd326b77a 100644 --- a/TeslaLogger/MQTTAutoDiscovery.cs +++ b/TeslaLogger/MQTTAutoDiscovery.cs @@ -26,168 +26,198 @@ static MQTTAutoDiscovery() // https://pictogrammers.com/library/mdi/ autoDiscovery["battery_level"] = new Dictionary(); + autoDiscovery["battery_level"]["discovery_active"] = "true"; autoDiscovery["battery_level"]["type"] = "sensor"; autoDiscovery["battery_level"]["name"] = "Battery Level"; autoDiscovery["battery_level"]["unit"] = "%"; autoDiscovery["battery_level"]["class"] = "battery"; autoDiscovery["power"] = new Dictionary(); + autoDiscovery["power"]["discovery_active"] = "false"; //telemetry, missing signal autoDiscovery["power"]["type"] = "sensor"; autoDiscovery["power"]["name"] = "Power"; autoDiscovery["power"]["unit"] = "kW"; autoDiscovery["power"]["class"] = "power"; autoDiscovery["charger_power"] = new Dictionary(); + autoDiscovery["charger_power"]["discovery_active"] = "true"; autoDiscovery["charger_power"]["type"] = "sensor"; autoDiscovery["charger_power"]["name"] = "Charge power"; autoDiscovery["charger_power"]["unit"] = "kW"; autoDiscovery["charger_power"]["class"] = "power"; autoDiscovery["charger_power_calc_w"] = new Dictionary(); + autoDiscovery["charger_power_calc_w"]["discovery_active"] = "false"; //not needed anymore autoDiscovery["charger_power_calc_w"]["type"] = "sensor"; autoDiscovery["charger_power_calc_w"]["name"] = "Charge power calculated"; autoDiscovery["charger_power_calc_w"]["unit"] = "W"; autoDiscovery["charger_power_calc_w"]["class"] = "power"; - + autoDiscovery["charger_voltage"] = new Dictionary(); + autoDiscovery["charger_voltage"]["discovery_active"] = "false"; //telemetry, missing signal autoDiscovery["charger_voltage"]["type"] = "sensor"; autoDiscovery["charger_voltage"]["name"] = "Charge voltage"; autoDiscovery["charger_voltage"]["unit"] = "V"; autoDiscovery["charger_voltage"]["class"] = "voltage"; autoDiscovery["charger_actual_current"] = new Dictionary(); + autoDiscovery["charger_actual_current"]["discovery_active"] = "false"; //telemetry, missing signal autoDiscovery["charger_actual_current"]["type"] = "sensor"; autoDiscovery["charger_actual_current"]["name"] = "Charge current"; autoDiscovery["charger_actual_current"]["unit"] = "A"; autoDiscovery["charger_actual_current"]["class"] = "current"; autoDiscovery["charger_actual_current_calc"] = new Dictionary(); + autoDiscovery["charger_actual_current_calc"]["discovery_active"] = "false"; //not needed anymore autoDiscovery["charger_actual_current_calc"]["type"] = "sensor"; autoDiscovery["charger_actual_current_calc"]["name"] = "Charge current calculated"; autoDiscovery["charger_actual_current_calc"]["unit"] = "A"; autoDiscovery["charger_actual_current_calc"]["class"] = "current"; autoDiscovery["charge_energy_added"] = new Dictionary(); + autoDiscovery["charge_energy_added"]["discovery_active"] = "true"; autoDiscovery["charge_energy_added"]["type"] = "sensor"; autoDiscovery["charge_energy_added"]["name"] = "Energy added"; autoDiscovery["charge_energy_added"]["unit"] = "kWh"; autoDiscovery["charge_energy_added"]["class"] = "energy"; autoDiscovery["charger_phases"] = new Dictionary(); + autoDiscovery["charger_phases"]["discovery_active"] = "false"; //telemetry, missing signal autoDiscovery["charger_phases"]["type"] = "sensor"; autoDiscovery["charger_phases"]["name"] = "Charge phases"; autoDiscovery["charger_phases"]["icon"] = "mdi:lightning-bolt"; autoDiscovery["charger_phases_calc"] = new Dictionary(); + autoDiscovery["charger_phases_calc"]["discovery_active"] = "false"; //not needed anymore autoDiscovery["charger_phases_calc"]["type"] = "sensor"; autoDiscovery["charger_phases_calc"]["name"] = "Charge phases calculated"; autoDiscovery["charger_phases_calc"]["icon"] = "mdi:lightning-bolt"; autoDiscovery["charge_rate_km"] = new Dictionary(); + autoDiscovery["charge_rate_km"]["discovery_active"] = "true"; autoDiscovery["charge_rate_km"]["type"] = "sensor"; autoDiscovery["charge_rate_km"]["name"] = "Charge rate"; autoDiscovery["charge_rate_km"]["unit"] = "km/h"; autoDiscovery["charge_rate_km"]["class"] = "speed"; autoDiscovery["time_to_full_charge"] = new Dictionary(); + autoDiscovery["time_to_full_charge"]["discovery_active"] = "true"; autoDiscovery["time_to_full_charge"]["type"] = "sensor"; autoDiscovery["time_to_full_charge"]["name"] = "Time to full charge"; autoDiscovery["time_to_full_charge"]["class"] = "duration"; autoDiscovery["car_version"] = new Dictionary(); + autoDiscovery["car_version"]["discovery_active"] = "true"; autoDiscovery["car_version"]["type"] = "sensor"; autoDiscovery["car_version"]["name"] = "Firmware version"; autoDiscovery["car_version"]["icon"] = "mdi:cellphone-information"; autoDiscovery["software_update_version"] = new Dictionary(); + autoDiscovery["software_update_version"]["discovery_active"] = "true"; autoDiscovery["software_update_version"]["type"] = "sensor"; autoDiscovery["software_update_version"]["name"] = "Firmware update version"; autoDiscovery["software_update_version"]["icon"] = "mdi:cellphone-arrow-down"; autoDiscovery["software_update_status"] = new Dictionary(); + autoDiscovery["software_update_status"]["discovery_active"] = "true"; autoDiscovery["software_update_status"]["type"] = "sensor"; autoDiscovery["software_update_status"]["name"] = "Firmware update status"; autoDiscovery["software_update_status"]["icon"] = "mdi:cellphone-arrow-down"; autoDiscovery["display_name"] = new Dictionary(); + autoDiscovery["display_name"]["discovery_active"] = "true"; autoDiscovery["display_name"]["type"] = "sensor"; autoDiscovery["display_name"]["name"] = "Car name"; autoDiscovery["display_name"]["icon"] = "mdi:tag"; autoDiscovery["latitude"] = new Dictionary(); + autoDiscovery["latitude"]["discovery_active"] = "true"; autoDiscovery["latitude"]["type"] = "sensor"; autoDiscovery["latitude"]["name"] = "Latitude"; autoDiscovery["latitude"]["unit"] = "°"; autoDiscovery["latitude"]["icon"] = "mdi:latitude"; autoDiscovery["longitude"] = new Dictionary(); + autoDiscovery["longitude"]["discovery_active"] = "true"; autoDiscovery["longitude"]["type"] = "sensor"; autoDiscovery["longitude"]["name"] = "Longitude"; autoDiscovery["longitude"]["unit"] = "°"; autoDiscovery["longitude"]["icon"] = "mdi:longitude"; autoDiscovery["heading"] = new Dictionary(); + autoDiscovery["heading"]["discovery_active"] = "true"; autoDiscovery["heading"]["type"] = "sensor"; autoDiscovery["heading"]["name"] = "Heading"; autoDiscovery["heading"]["unit"] = "°"; autoDiscovery["heading"]["icon"] = "mdi:compass"; autoDiscovery["country_code"] = new Dictionary(); + autoDiscovery["country_code"]["discovery_active"] = "true"; autoDiscovery["country_code"]["type"] = "sensor"; autoDiscovery["country_code"]["name"] = "Country code"; autoDiscovery["country_code"]["icon"] = "mdi:flag"; autoDiscovery["state"] = new Dictionary(); + autoDiscovery["state"]["discovery_active"] = "true"; autoDiscovery["state"]["type"] = "sensor"; autoDiscovery["state"]["name"] = "State"; autoDiscovery["state"]["icon"] = "mdi:map"; autoDiscovery["TLGeofence"] = new Dictionary(); + autoDiscovery["TLGeofence"]["discovery_active"] = "true"; autoDiscovery["TLGeofence"]["type"] = "sensor"; autoDiscovery["TLGeofence"]["name"] = "Location"; autoDiscovery["odometer"] = new Dictionary(); + autoDiscovery["odometer"]["discovery_active"] = "true"; autoDiscovery["odometer"]["type"] = "sensor"; autoDiscovery["odometer"]["name"] = "Odometer"; autoDiscovery["odometer"]["unit"] = "km"; autoDiscovery["odometer"]["class"] = "distance"; autoDiscovery["battery_range_km"] = new Dictionary(); + autoDiscovery["battery_range_km"]["discovery_active"] = "true"; autoDiscovery["battery_range_km"]["type"] = "sensor"; autoDiscovery["battery_range_km"]["name"] = "Battery range"; autoDiscovery["battery_range_km"]["unit"] = "km"; autoDiscovery["battery_range_km"]["class"] = "distance"; autoDiscovery["ideal_battery_range_km"] = new Dictionary(); + autoDiscovery["ideal_battery_range_km"]["discovery_active"] = "true"; autoDiscovery["ideal_battery_range_km"]["type"] = "sensor"; autoDiscovery["ideal_battery_range_km"]["name"] = "Ideal battery range"; autoDiscovery["ideal_battery_range_km"]["unit"] = "km"; autoDiscovery["ideal_battery_range_km"]["class"] = "distance"; autoDiscovery["inside_temperature"] = new Dictionary(); + autoDiscovery["inside_temperature"]["discovery_active"] = "true"; autoDiscovery["inside_temperature"]["type"] = "sensor"; autoDiscovery["inside_temperature"]["name"] = "Inside temperature"; autoDiscovery["inside_temperature"]["unit"] = "°C"; autoDiscovery["inside_temperature"]["class"] = "temperature"; autoDiscovery["outside_temp"] = new Dictionary(); + autoDiscovery["outside_temp"]["discovery_active"] = "true"; autoDiscovery["outside_temp"]["type"] = "sensor"; autoDiscovery["outside_temp"]["name"] = "Outside temperature"; autoDiscovery["outside_temp"]["unit"] = "°C"; autoDiscovery["outside_temp"]["class"] = "temperature"; autoDiscovery["ts"] = new Dictionary(); + autoDiscovery["ts"]["discovery_active"] = "true"; autoDiscovery["ts"]["type"] = "sensor"; autoDiscovery["ts"]["name"] = "Time stamp"; autoDiscovery["ts"]["class"] = "timestamp"; autoDiscovery["speed"] = new Dictionary(); + autoDiscovery["speed"]["discovery_active"] = "true"; autoDiscovery["speed"]["type"] = "sensor"; autoDiscovery["speed"]["name"] = "Speed"; autoDiscovery["speed"]["unit"] = "km/h"; autoDiscovery["speed"]["class"] = "speed"; autoDiscovery["sleeping"] = new Dictionary(); + autoDiscovery["sleeping"]["discovery_active"] = "true"; autoDiscovery["sleeping"]["type"] = "binary_sensor"; autoDiscovery["sleeping"]["name"] = "Sleeping"; autoDiscovery["sleeping"]["pl_on"] = "true"; @@ -195,6 +225,7 @@ static MQTTAutoDiscovery() autoDiscovery["sleeping"]["icon"] = "mdi:sleep"; autoDiscovery["driving"] = new Dictionary(); + autoDiscovery["driving"]["discovery_active"] = "true"; autoDiscovery["driving"]["type"] = "binary_sensor"; autoDiscovery["driving"]["name"] = "Driving"; autoDiscovery["driving"]["pl_on"] = "true"; @@ -202,12 +233,14 @@ static MQTTAutoDiscovery() autoDiscovery["driving"]["class"] = "moving"; autoDiscovery["falling_asleep"] = new Dictionary(); + autoDiscovery["falling_asleep"]["discovery_active"] = "true"; autoDiscovery["falling_asleep"]["type"] = "binary_sensor"; autoDiscovery["falling_asleep"]["name"] = "Falling Asleep"; autoDiscovery["falling_asleep"]["pl_on"] = "true"; autoDiscovery["falling_asleep"]["pl_off"] = "false"; autoDiscovery["plugged_in"] = new Dictionary(); + autoDiscovery["plugged_in"]["discovery_active"] = "true"; autoDiscovery["plugged_in"]["type"] = "binary_sensor"; autoDiscovery["plugged_in"]["name"] = "Plugged in"; autoDiscovery["plugged_in"]["pl_on"] = "true"; @@ -215,6 +248,7 @@ static MQTTAutoDiscovery() autoDiscovery["plugged_in"]["class"] = "plug"; autoDiscovery["battery_heater"] = new Dictionary(); + autoDiscovery["battery_heater"]["discovery_active"] = "true"; autoDiscovery["battery_heater"]["type"] = "binary_sensor"; autoDiscovery["battery_heater"]["name"] = "Battery heater"; autoDiscovery["battery_heater"]["pl_on"] = "true"; @@ -222,6 +256,7 @@ static MQTTAutoDiscovery() autoDiscovery["battery_heater"]["class"] = "heat"; autoDiscovery["locked"] = new Dictionary(); + autoDiscovery["locked"]["discovery_active"] = "true"; autoDiscovery["locked"]["type"] = "binary_sensor"; autoDiscovery["locked"]["name"] = "Locked"; autoDiscovery["locked"]["pl_on"] = "false"; @@ -229,24 +264,29 @@ static MQTTAutoDiscovery() autoDiscovery["locked"]["class"] = "lock"; autoDiscovery["open_windows"] = new Dictionary(); + autoDiscovery["open_windows"]["discovery_active"] = "true"; autoDiscovery["open_windows"]["type"] = "sensor"; autoDiscovery["open_windows"]["name"] = "Windows opened"; autoDiscovery["open_windows"]["icon"] = "mdi:car-door"; autoDiscovery["open_doors"] = new Dictionary(); + autoDiscovery["open_doors"]["discovery_active"] = "true"; autoDiscovery["open_doors"]["type"] = "sensor"; autoDiscovery["open_doors"]["name"] = "Doors opened"; autoDiscovery["open_doors"]["icon"] = "mdi:car-door"; autoDiscovery["frunk"] = new Dictionary(); + autoDiscovery["frunk"]["discovery_active"] = "true"; autoDiscovery["frunk"]["type"] = "sensor"; autoDiscovery["frunk"]["name"] = "Frunk opened"; autoDiscovery["trunk"] = new Dictionary(); + autoDiscovery["trunk"]["discovery_active"] = "true"; autoDiscovery["trunk"]["type"] = "sensor"; autoDiscovery["trunk"]["name"] = "Trunk opened"; autoDiscovery["TLGeofenceIsHome"] = new Dictionary(); + autoDiscovery["TLGeofenceIsHome"]["discovery_active"] = "true"; autoDiscovery["TLGeofenceIsHome"]["type"] = "binary_sensor"; autoDiscovery["TLGeofenceIsHome"]["name"] = "Is Home"; autoDiscovery["TLGeofenceIsHome"]["pl_on"] = "true"; @@ -254,6 +294,7 @@ static MQTTAutoDiscovery() autoDiscovery["TLGeofenceIsHome"]["icon"] = "mdi:home"; autoDiscovery["TLGeofenceIsWork"] = new Dictionary(); + autoDiscovery["TLGeofenceIsWork"]["discovery_active"] = "true"; autoDiscovery["TLGeofenceIsWork"]["type"] = "binary_sensor"; autoDiscovery["TLGeofenceIsWork"]["name"] = "Is Work"; autoDiscovery["TLGeofenceIsWork"]["pl_on"] = "true"; @@ -261,6 +302,7 @@ static MQTTAutoDiscovery() autoDiscovery["TLGeofenceIsWork"]["icon"] = "mdi:briefcase"; autoDiscovery["TLGeofenceIsCharger"] = new Dictionary(); + autoDiscovery["TLGeofenceIsCharger"]["discovery_active"] = "true"; autoDiscovery["TLGeofenceIsCharger"]["type"] = "binary_sensor"; autoDiscovery["TLGeofenceIsCharger"]["name"] = "Is Charger"; autoDiscovery["TLGeofenceIsCharger"]["pl_on"] = "true"; @@ -268,6 +310,7 @@ static MQTTAutoDiscovery() autoDiscovery["TLGeofenceIsCharger"]["icon"] = "mdi:ev-station"; autoDiscovery["charge_port_door_open"] = new Dictionary(); + autoDiscovery["charge_port_door_open"]["discovery_active"] = "true"; autoDiscovery["charge_port_door_open"]["type"] = "binary_sensor"; autoDiscovery["charge_port_door_open"]["name"] = "Charge port opened"; autoDiscovery["charge_port_door_open"]["pl_on"] = "true"; @@ -276,6 +319,7 @@ static MQTTAutoDiscovery() autoDiscovery["charge_port_door_open"]["class"] = "opening"; autoDiscovery["fast_charger_present"] = new Dictionary(); + autoDiscovery["fast_charger_present"]["discovery_active"] = "true"; autoDiscovery["fast_charger_present"]["type"] = "binary_sensor"; autoDiscovery["fast_charger_present"]["name"] = "Fast charger"; autoDiscovery["fast_charger_present"]["pl_on"] = "true"; @@ -283,11 +327,13 @@ static MQTTAutoDiscovery() autoDiscovery["fast_charger_present"]["icon"] = "mdi:ev-station"; autoDiscovery["fast_charger_brand"] = new Dictionary(); + autoDiscovery["fast_charger_brand"]["discovery_active"] = "true"; autoDiscovery["fast_charger_brand"]["type"] = "sensor"; autoDiscovery["fast_charger_brand"]["name"] = "Fastcharger brand"; autoDiscovery["fast_charger_brand"]["icon"] = "mdi:ev-station"; autoDiscovery["sentry_mode"] = new Dictionary(); + autoDiscovery["sentry_mode"]["discovery_active"] = "true"; autoDiscovery["sentry_mode"]["type"] = "switch"; autoDiscovery["sentry_mode"]["name"] = "Sentry mode"; autoDiscovery["sentry_mode"]["pl_on"] = "true"; @@ -296,6 +342,7 @@ static MQTTAutoDiscovery() autoDiscovery["sentry_mode"]["icon"] = "mdi:cctv"; autoDiscovery["is_preconditioning"] = new Dictionary(); + autoDiscovery["is_preconditioning"]["discovery_active"] = "true"; autoDiscovery["is_preconditioning"]["type"] = "switch"; autoDiscovery["is_preconditioning"]["name"] = "Preconditioning"; autoDiscovery["is_preconditioning"]["pl_on"] = "true"; @@ -304,6 +351,7 @@ static MQTTAutoDiscovery() autoDiscovery["is_preconditioning"]["icon"] = "mdi:heat-wave"; autoDiscovery["charging"] = new Dictionary(); + autoDiscovery["charging"]["discovery_active"] = "true"; autoDiscovery["charging"]["type"] = "switch"; autoDiscovery["charging"]["name"] = "Charging"; autoDiscovery["charging"]["pl_on"] = "true"; @@ -311,6 +359,7 @@ static MQTTAutoDiscovery() autoDiscovery["charging"]["cmd_topic"] = "charge_start_stop"; autoDiscovery["online"] = new Dictionary(); + autoDiscovery["online"]["discovery_active"] = "true"; autoDiscovery["online"]["type"] = "switch"; autoDiscovery["online"]["name"] = "Online"; autoDiscovery["online"]["pl_on"] = "true"; @@ -319,6 +368,7 @@ static MQTTAutoDiscovery() autoDiscovery["online"]["icon"] = "mdi:car-connected"; autoDiscovery["charge_limit_soc"] = new Dictionary(); + autoDiscovery["charge_limit_soc"]["discovery_active"] = "true"; autoDiscovery["charge_limit_soc"]["type"] = "number"; autoDiscovery["charge_limit_soc"]["name"] = "Charge limit SoC"; autoDiscovery["charge_limit_soc"]["cmd_topic"] = "set_charge_limit"; @@ -329,6 +379,7 @@ static MQTTAutoDiscovery() autoDiscovery["charge_limit_soc"]["step"] = "1"; autoDiscovery["charge_current_request"] = new Dictionary(); + autoDiscovery["charge_current_request"]["discovery_active"] = "true"; autoDiscovery["charge_current_request"]["type"] = "number"; autoDiscovery["charge_current_request"]["name"] = "Charge current request"; autoDiscovery["charge_current_request"]["cmd_topic"] = "set_charging_amps"; @@ -339,81 +390,95 @@ static MQTTAutoDiscovery() autoDiscovery["charge_current_request"]["step"] = "1"; autoDiscovery["trip_start"] = new Dictionary(); + autoDiscovery["trip_start"]["discovery_active"] = "true"; autoDiscovery["trip_start"]["type"] = "sensor"; autoDiscovery["trip_start"]["name"] = "Trip start"; autoDiscovery["trip_start"]["icon"] = "mdi:car-clock"; autoDiscovery["trip_duration_sec"] = new Dictionary(); + autoDiscovery["trip_duration_sec"]["discovery_active"] = "true"; autoDiscovery["trip_duration_sec"]["type"] = "sensor"; autoDiscovery["trip_duration_sec"]["name"] = "Trip Duration"; autoDiscovery["trip_duration_sec"]["unit"] = "s"; autoDiscovery["trip_duration_sec"]["class"] = "duration"; autoDiscovery["trip_start_dt"] = new Dictionary(); + autoDiscovery["trip_start_dt"]["discovery_active"] = "true"; autoDiscovery["trip_start_dt"]["type"] = "sensor"; autoDiscovery["trip_start_dt"]["name"] = "Trip timestamp"; autoDiscovery["trip_start_dt"]["class"] = "timestamp"; autoDiscovery["trip_start_dt"]["icon"] = "mdi:car-clock"; autoDiscovery["trip_max_speed"] = new Dictionary(); + autoDiscovery["trip_max_speed"]["discovery_active"] = "true"; autoDiscovery["trip_max_speed"]["type"] = "sensor"; autoDiscovery["trip_max_speed"]["name"] = "Trip max. speed"; autoDiscovery["trip_max_speed"]["unit"] = "km/h"; autoDiscovery["trip_max_speed"]["class"] = "speed"; autoDiscovery["trip_max_power"] = new Dictionary(); + autoDiscovery["trip_max_power"]["discovery_active"] = "true"; autoDiscovery["trip_max_power"]["type"] = "sensor"; autoDiscovery["trip_max_power"]["name"] = "Trip max. power"; autoDiscovery["trip_max_power"]["unit"] = "kW"; autoDiscovery["trip_max_power"]["class"] = "power"; autoDiscovery["trip_kwh"] = new Dictionary(); + autoDiscovery["trip_kwh"]["discovery_active"] = "true"; autoDiscovery["trip_kwh"]["type"] = "sensor"; autoDiscovery["trip_kwh"]["name"] = "Trip energy consumed"; autoDiscovery["trip_kwh"]["unit"] = "kWh"; autoDiscovery["trip_kwh"]["class"] = "energy"; autoDiscovery["trip_avg_kwh"] = new Dictionary(); + autoDiscovery["trip_avg_kwh"]["discovery_active"] = "true"; autoDiscovery["trip_avg_kwh"]["type"] = "sensor"; autoDiscovery["trip_avg_kwh"]["name"] = "Trip energy cunsuption"; autoDiscovery["trip_avg_kwh"]["unit"] = "Wh/km"; autoDiscovery["trip_avg_kwh"]["class"] = "energy"; autoDiscovery["trip_distance"] = new Dictionary(); + autoDiscovery["trip_distance"]["discovery_active"] = "true"; autoDiscovery["trip_distance"]["type"] = "sensor"; autoDiscovery["trip_distance"]["name"] = "Trip distance"; autoDiscovery["trip_distance"]["unit"] = "km"; autoDiscovery["trip_distance"]["class"] = "distance"; autoDiscovery["active_route_destination"] = new Dictionary(); + autoDiscovery["active_route_destination"]["discovery_active"] = "true"; autoDiscovery["active_route_destination"]["type"] = "sensor"; autoDiscovery["active_route_destination"]["name"] = "Route destination"; autoDiscovery["active_route_energy_at_arrival"] = new Dictionary(); + autoDiscovery["active_route_energy_at_arrival"]["discovery_active"] = "true"; autoDiscovery["active_route_energy_at_arrival"]["type"] = "sensor"; autoDiscovery["active_route_energy_at_arrival"]["name"] = "Route energy at arrival"; autoDiscovery["active_route_energy_at_arrival"]["unit"] = "%"; autoDiscovery["active_route_energy_at_arrival"]["class"] = "battery"; autoDiscovery["active_route_minutes_to_arrival"] = new Dictionary(); + autoDiscovery["active_route_minutes_to_arrival"]["discovery_active"] = "true"; autoDiscovery["active_route_minutes_to_arrival"]["type"] = "sensor"; autoDiscovery["active_route_minutes_to_arrival"]["name"] = "Route minutes until destination"; autoDiscovery["active_route_minutes_to_arrival"]["unit"] = "min"; autoDiscovery["active_route_minutes_to_arrival"]["class"] = "duration"; autoDiscovery["active_route_traffic_minutes_delay"] = new Dictionary(); + autoDiscovery["active_route_traffic_minutes_delay"]["discovery_active"] = "true"; autoDiscovery["active_route_traffic_minutes_delay"]["type"] = "sensor"; autoDiscovery["active_route_traffic_minutes_delay"]["name"] = "Route traffic delay"; autoDiscovery["active_route_traffic_minutes_delay"]["unit"] = "min"; autoDiscovery["active_route_traffic_minutes_delay"]["class"] = "duration"; autoDiscovery["active_route_latitude"] = new Dictionary(); + autoDiscovery["active_route_latitude"]["discovery_active"] = "true"; autoDiscovery["active_route_latitude"]["type"] = "sensor"; autoDiscovery["active_route_latitude"]["name"] = "Route destination latitude"; autoDiscovery["active_route_latitude"]["unit"] = "°"; autoDiscovery["active_route_latitude"]["icon"] = "mdi:latitude"; autoDiscovery["active_route_longitude"] = new Dictionary(); + autoDiscovery["active_route_longitude"]["discovery_active"] = "true"; autoDiscovery["active_route_longitude"]["type"] = "sensor"; autoDiscovery["active_route_longitude"]["name"] = "Route destination longitude"; autoDiscovery["active_route_longitude"]["unit"] = "°"; diff --git a/TeslaLogger/TelemetryParser.cs b/TeslaLogger/TelemetryParser.cs index 6029015a1..07e60aec7 100644 --- a/TeslaLogger/TelemetryParser.cs +++ b/TeslaLogger/TelemetryParser.cs @@ -117,7 +117,7 @@ public bool Driving if (driving) { var ts = DateTime.Now - lastDriving; - if (ts.TotalMinutes > 30) + if (ts.TotalMinutes > 60) { Log("Stop Driving by timeout 30 minutes ***"); driving = false; @@ -1636,7 +1636,7 @@ private void CheckDriving() if (Driving) { var ts = DateTime.Now - lastDriving; - if (ts.TotalMinutes > 15) + if (ts.TotalMinutes > 60) { Log("Driving stop by speed " + lastDriving.ToString()); Driving = false; diff --git a/TeslaLogger/bin/changelog.md b/TeslaLogger/bin/changelog.md index 7414d11d8..4097cd637 100644 --- a/TeslaLogger/bin/changelog.md +++ b/TeslaLogger/bin/changelog.md @@ -1,4 +1,6 @@ # Version 1.62.14 +- New Wallboxes: SmartEVSE 3 and WARP +- EVCC supports multiple loadpoints and cars now. You can find a loadpoint by car name (EVCC should be configured correctly) - Bugfixes # Version 1.62.13 diff --git a/TeslaLogger/www/admin/dashboard.php b/TeslaLogger/www/admin/dashboard.php index 21408ad92..dd29c1dbe 100644 --- a/TeslaLogger/www/admin/dashboard.php +++ b/TeslaLogger/www/admin/dashboard.php @@ -80,7 +80,7 @@ function GetCurrentData() if (jsonData["charging"]) { $('#car_statusLabel').text(":"); - $('#car_status').html(jsonData["charger_power"] + " kW / +" + jsonData["charge_energy_added"] + " kWh
" + jsonData["charger_voltage"]+"V / " + jsonData["charger_actual_current"]+"A / "+ jsonData["charger_phases"]+"P"); + $('#car_status').html(jsonData["charger_power"] + " kW / +" + jsonData["charge_energy_added"] + " kWh"); } else if (jsonData["driving"]) { diff --git a/TeslaLogger/www/admin/index.php b/TeslaLogger/www/admin/index.php index 56005ed6a..35479bd04 100644 --- a/TeslaLogger/www/admin/index.php +++ b/TeslaLogger/www/admin/index.php @@ -193,17 +193,8 @@ function GetCurrentData() var datetime = at.toLocaleTimeString(loc, { hour: '2-digit', minute: '2-digit' }); $('#car_statusLabel').text(":"); - if(jsonData["charger_phases_calc"] > 0) - { - $('#car_status').html(jsonData["charger_power_calc_w"] + " W / +" + jsonData["charge_energy_added"] + " kWh
" + - jsonData["charger_voltage"]+"V / " + jsonData["charger_actual_current_calc"]+"A / "+ jsonData["charger_phases_calc"]+"P
" + + $('#car_status').html(jsonData["charger_power"] + " kW / +" + jsonData["charge_energy_added"] + " kWh
" + ": "+ hour +"h "+minute+"m
: " + datetime + " / " + jsonData["charge_limit_soc"] +"%"); - } - else - { - $('#car_status').html(jsonData["charger_power"] + " kW / +" + jsonData["charge_energy_added"] + " kWh
" + - ": "+ hour +"h "+minute+"m
: " + datetime + " / " + jsonData["charge_limit_soc"] +"%"); - } updateSMT(jsonData); } @@ -212,14 +203,9 @@ function GetCurrentData() $('#car_statusLabel').text(":"); var str = ""; if (LengthUnit == "mile") - str = (jsonData["speed"]/ km2mls).toFixed(0) + " mph / " - else - str = jsonData["speed"] + " / "; - - if (PowerUnit == "kw") - str += (jsonData["power"] / 1.35962).toFixed(0) + " "; + str = (jsonData["speed"]/ km2mls).toFixed(0) + " mph" else - str += jsonData["power"] + " "; + str = jsonData["speed"] + " "; if (jsonData["active_route_destination"]) { @@ -296,17 +282,6 @@ function GetCurrentData() $("#trip_distance").text(jsonData["trip_distance"].toLocaleString(loc,{maximumFractionDigits:1, minimumFractionDigits: 1})); } - if (PowerUnit == "kw") - { - $("#max_power").text((jsonData["trip_max_power"] / 1.35962).toFixed(0)); - $("#lt_trip_PS").text(""); - } - else - { - $("#max_power").text(jsonData["trip_max_power"]); - $("#lt_trip_PS").text(""); - } - var ts2 = new Date(Date.parse(jsonData["trip_start_dt"])); $("#trip_start").text(ts2.toLocaleTimeString(loc, { day: '2-digit', month: '2-digit', year: 'numeric' })); @@ -527,7 +502,7 @@ function updateSMT(jsonData) :--- :--- :--- - / :--- / --- + :--- diff --git a/wallbox.md b/wallbox.md index 2a15a970e..7086be4bb 100644 --- a/wallbox.md +++ b/wallbox.md @@ -7,7 +7,9 @@ You can connect your Teslalogger to your Wallbox to calculate the efficiency of - KEBA KeContact P30 (P20?) - Shelly 3EM for all unsupported wallboxes or without build in meter: https://amzn.to/3nUEuO0 - Shelly EM for 1 phase charging +- SmartEVSE 3 - EVCC +- WARP # Settings Go to admin panel and select the car you want to use for the wallbox. Go to Extras / Wallbox. @@ -35,7 +37,16 @@ C2 for channel 2 # EVCC ### Param: -Wallbox title from EVCC +Wallbox or Car title from EVCC +# WARP +### Param: +Per default and without params TeslaLogger assumes, that wallbox has internal meter with ID 0, value_id=209 and grid meter with ID 1, value_id=209 + +If it's not a case, provide paramas in this format: +- "W:2:210": only Wallbox meter with ID 2 and value_id=210 +- "G:2|W:0:210": Grid meter with ID 2 and default value_id=209, wallbox meter with ID 0 and value_id=210 + +For more information about value_ids: https://github.com/Tinkerforge/esp32-firmware/blob/master/software/src/modules/meters/meter_value_id.csv # Dashboard In Charging History you can see the efficiency of charging and percentage of photovoltaics if the wallbox supports this value.