Enhance homeassistant discovery (V5) (#1275)

* manual re-creation of #1246

* removed non-working approach to get interval

* postpone the MQTT service start until the ClassFlowControll::ReadParameter() gets called

* Increase the max_uri_handlers to 35 (was 30)

* removed newlines in logs

* added parameter to UI

* Register handler to re-start MQTT Discovery

* fix param
This commit is contained in:
CaCO3
2022-11-05 19:32:58 +01:00
committed by GitHub
parent 22fe50f80a
commit 3e082ed06e
10 changed files with 429 additions and 193 deletions

View File

@@ -625,10 +625,15 @@ textarea {
Enable or disable the retain flag for all MQTT entries
</td>
</tr>
<tr>
<td colspan="3" style="padding-left: 20px;"><h4>Homeassistant Discovery (using MQTT)</h4>
<span style="font-size: 80%;">The discovery topics and the static topics (IP, MAC, Hostname, Interval, ...) only get sent on startup.
To send them again, you can call the following URL: <a href=mqtt_publish_discovery target="_blank">http://&lt;IP&gt;/mqtt_publish_discovery</a></span></td>
</tr>
<tr>
<td class="indent1">
<input type="checkbox" id="MQTT_HomeassistantDiscovery_enabled" value="1" onclick = 'InvertEnableItem("MQTT", "HomeassistantDiscovery")' unchecked >
<label for=MQTT_HomeassistantDiscovery_enabled><class id="MQTT_HomeassistantDiscovery_text" style="color:black;">Enable Homeassistant Discovery</class></label>
<label for=MQTT_HomeassistantDiscovery_enabled><class id="MQTT_HomeassistantDiscovery_text" style="color:black;">Homeassistant Discovery</class></label>
</td>
<td>
<select id="MQTT_HomeassistantDiscovery_value1">
@@ -637,7 +642,31 @@ textarea {
</select>
</td>
<td style="font-size: 80%;">
Enable or disable the <a href=https://www.home-assistant.io/docs/mqtt/discovery/ target=_blank>Homeassistand Discovery</a>
Enable or disable the <a href=https://www.home-assistant.io/docs/mqtt/discovery/ target=_blank>Homeassistant Discovery</a>
</td>
</tr>
<tr>
<td class="indent1">
<input type="checkbox" id="MQTT_MeterType_enabled" value="1" onclick = 'InvertEnableItem("MQTT", "MeterType")' unchecked >
<label for=MQTT_MeterType_enabled><class id="MQTT_MeterType_text" style="color:black;">Meter Type</class></label>
</td>
<td>
<select id="MQTT_MeterType_value1"> <!-- See https://developers.home-assistant.io/docs/core/entity/sensor/#available-device-classes -->
<option value="other" selected>Other (no Units)</option>
<option value="water_m3">Watermeter (Value: m³, Rate: m³/h)</option>
<option value="water_l">Watermeter (Value: l, Rate: l/h)</option>
<option value="water_gal">Watermeter (Value: gal, Rate: gal/h)</option>
<option value="water_ft3">Watermeter (Value: ft³, Rate: ft³/m)</option>
<option value="gas_m3">Gasmeter (Value: m³, Rate: m³/h)</option>
<option value="gas_ft3">Gasmeter (Value: ft³, Rate: ft³/m)</option>
<option value="energy_wh">Energymeter (Value: Wh, Rate: W)</option>
<option value="energy_kwh">Energymeter (Value: kWh, Rate: kW)</option>
<option value="energy_mwh">Energymeter (Value: MWh, Rate: MW)</option>
</select>
</td>
<td style="font-size: 80%;">
Select the meter type so the sensors have the right units in Homeassistant.<br>
Note: For 'Watermeter' you need to have Homeassistant 2022.11 or never!
</td>
</tr>
@@ -1734,6 +1763,7 @@ function UpdateInput() {
WriteParameter(param, category, "MQTT", "password", true);
WriteParameter(param, category, "MQTT", "SetRetainFlag", true);
WriteParameter(param, category, "MQTT", "HomeassistantDiscovery", true);
WriteParameter(param, category, "MQTT", "MeterType", true);
WriteParameter(param, category, "InfluxDB", "Uri", true);
WriteParameter(param, category, "InfluxDB", "Database", true);
@@ -1851,6 +1881,7 @@ function ReadParameterAll()
ReadParameter(param, "MQTT", "password", true);
ReadParameter(param, "MQTT", "SetRetainFlag", true);
ReadParameter(param, "MQTT", "HomeassistantDiscovery", true);
ReadParameter(param, "MQTT", "MeterType", true);
ReadParameter(param, "InfluxDB", "Uri", true);
ReadParameter(param, "InfluxDB", "Database", true);