diff --git a/mqtt_discovery.cpp b/mqtt_discovery.cpp index dcf5134..a7c4465 100644 --- a/mqtt_discovery.cpp +++ b/mqtt_discovery.cpp @@ -75,12 +75,12 @@ bool publish_all_config(PubSubClient* mqtt, const char* ident) { }; publish_config(mqtt, TOPIC_CFG_TEMPERATURE, &temperature); struct sensor_config battery = { - .name = "Garden Sensor Battery Level", - .unique_id = "sensor.garden_sensor_battery_level", - .value_template = "{{ value_json.battery_level }}", + .name = "Garden Sensor Battery", + .unique_id = "sensor.garden_sensor_battery", + .value_template = "{{ value_json.battery }}", .identifier = ident, - .device_class = "voltage", - .unit = "V", + .device_class = "battery", + .unit = "%", .state_class = NULL, .entity_category = "diagnostic", }; diff --git a/values.cpp b/values.cpp index 97ed9ff..67dc8cc 100644 --- a/values.cpp +++ b/values.cpp @@ -20,6 +20,7 @@ bool Values::send(PubSubClient* mqtt, const char* topic) { doc["moisture"] = moisture; doc["temperature"] = round2(temperature); doc["battery_level"] = round2(battery); + doc["battery"] = (int)((battery - 3) / 0.95 * 100); doc["rssi"] = rssi; doc["boot_count"] = boot_count;