|
@ -13,6 +13,17 @@ Copyright (C) 2017-2018 by Xose Pérez <xose dot perez at gmail dot com> |
|
|
bool _haEnabled = false; |
|
|
bool _haEnabled = false; |
|
|
bool _haSendFlag = false; |
|
|
bool _haSendFlag = false; |
|
|
|
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
|
// UTILS
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
String _haFixName(String name) { |
|
|
|
|
|
for (unsigned char i=0; i<name.length(); i++) { |
|
|
|
|
|
if (!isalnum(name.charAt(i))) name.setCharAt(i, '_'); |
|
|
|
|
|
} |
|
|
|
|
|
return name; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
// -----------------------------------------------------------------------------
|
|
|
// SENSORS
|
|
|
// SENSORS
|
|
|
// -----------------------------------------------------------------------------
|
|
|
// -----------------------------------------------------------------------------
|
|
@ -22,7 +33,7 @@ bool _haSendFlag = false; |
|
|
void _haSendMagnitude(unsigned char i, JsonObject& config) { |
|
|
void _haSendMagnitude(unsigned char i, JsonObject& config) { |
|
|
|
|
|
|
|
|
unsigned char type = magnitudeType(i); |
|
|
unsigned char type = magnitudeType(i); |
|
|
config["name"] = getSetting("hostname") + String(" ") + magnitudeTopic(type); |
|
|
|
|
|
|
|
|
config["name"] = _haFixName(getSetting("hostname") + String(" ") + magnitudeTopic(type)); |
|
|
config.set("platform", "mqtt"); |
|
|
config.set("platform", "mqtt"); |
|
|
config["state_topic"] = mqttTopic(magnitudeTopicIndex(i).c_str(), false); |
|
|
config["state_topic"] = mqttTopic(magnitudeTopicIndex(i).c_str(), false); |
|
|
config["unit_of_measurement"] = magnitudeUnits(type); |
|
|
config["unit_of_measurement"] = magnitudeUnits(type); |
|
@ -64,10 +75,10 @@ void _haSendSwitch(unsigned char i, JsonObject& config) { |
|
|
|
|
|
|
|
|
String name = getSetting("hostname"); |
|
|
String name = getSetting("hostname"); |
|
|
if (relayCount() > 1) { |
|
|
if (relayCount() > 1) { |
|
|
name += String(" #") + String(i); |
|
|
|
|
|
|
|
|
name += String("_") + String(i); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
config.set("name", name); |
|
|
|
|
|
|
|
|
config.set("name", _haFixName(name)); |
|
|
config.set("platform", "mqtt"); |
|
|
config.set("platform", "mqtt"); |
|
|
|
|
|
|
|
|
if (relayCount()) { |
|
|
if (relayCount()) { |
|
|