MACCHINA_A0 Running->Charging
This commit is contained in:
parent
8a013fd635
commit
8ac38bb1f0
10
src/main.cpp
10
src/main.cpp
|
@ -34,8 +34,8 @@ bool sendTelemetry(int totalSeen, int totalFpSeen, int totalFpQueried, int total
|
|||
&& sendDeleteDiscovery("switch", "OTA Update")
|
||||
&& Motion::SendDiscovery(doc)
|
||||
#ifdef MACCHINA_A0
|
||||
&& sendTeleSensorDiscovery("Battery", "", "{{ value_json.batt }}", "%")
|
||||
&& sendTeleBinarySensorDiscovery("Running", "", "{{ value_json.run }}", "running")
|
||||
&& sendTeleSensorDiscovery("Battery", "", "{{ value_json.batt }}", "%", "battery")
|
||||
&& sendTeleBinarySensorDiscovery("Charging", "", "{{ value_json.charging }}", "battery_charging")
|
||||
#endif
|
||||
#ifdef SENSORS
|
||||
&& sendDiscoveryHumidity()
|
||||
|
@ -72,10 +72,10 @@ bool sendTelemetry(int totalSeen, int totalFpSeen, int totalFpQueried, int total
|
|||
#ifdef MACCHINA_A0
|
||||
auto mv = a0_read_batt_mv();
|
||||
doc["mV"] = mv;
|
||||
bool run = (mv > 13200);
|
||||
bool charging = (mv > 13200);
|
||||
unsigned int soc = round(-13275.04 + 2.049731 * mv - (0.00007847975 * mv) * mv);
|
||||
doc["batt"] = run ? (unsigned int)100 : max((unsigned int)0, min((unsigned int)100, soc));
|
||||
doc["run"] = run ? "ON" : "OFF";
|
||||
doc["batt"] = charging ? (unsigned int)100 : max((unsigned int)0, min((unsigned int)100, soc));
|
||||
doc["charging"] = charging ? "ON" : "OFF";
|
||||
#endif
|
||||
#ifdef VERSION
|
||||
doc["ver"] = String(VERSION);
|
||||
|
|
|
@ -379,14 +379,14 @@ bool sendTeleBinarySensorDiscovery(const String &name, const String &entityCateg
|
|||
doc["stat_t"] = "~/telemetry";
|
||||
if (!entityCategory.isEmpty()) doc["entity_category"] = entityCategory;
|
||||
doc["value_template"] = temp;
|
||||
doc["dev_cla"] = devClass;
|
||||
if (!devClass.isEmpty()) doc["dev_cla"] = devClass;
|
||||
serializeJson(doc, buffer);
|
||||
String discoveryTopic = "homeassistant/binary_sensor/espresense_" + ESPMAC + "/" + slug + "/config";
|
||||
|
||||
return pub(discoveryTopic.c_str(), 0, true, buffer);
|
||||
}
|
||||
|
||||
bool sendTeleSensorDiscovery(const String &name, const String &entityCategory, const String &temp, const String &units)
|
||||
bool sendTeleSensorDiscovery(const String &name, const String &entityCategory, const String &temp, const String &units, const String &devClass = "")
|
||||
{
|
||||
auto slug = slugify(name);
|
||||
|
||||
|
@ -399,6 +399,7 @@ bool sendTeleSensorDiscovery(const String &name, const String &entityCategory, c
|
|||
if (!entityCategory.isEmpty()) doc["entity_category"] = entityCategory;
|
||||
doc["value_template"] = temp;
|
||||
if (!units.isEmpty()) doc["unit_of_measurement"] = units;
|
||||
if (!devClass.isEmpty()) doc["dev_cla"] = devClass;
|
||||
serializeJson(doc, buffer);
|
||||
String discoveryTopic = "homeassistant/sensor/espresense_" + ESPMAC + "/" + slug + "/config";
|
||||
|
||||
|
|
Loading…
Reference in New Issue