Skip to content

Commit

Permalink
Merge pull request #360 from shbatm/hassio_discovery_patch_1
Browse files Browse the repository at this point in the history
Update HA Discovery Payloads
  • Loading branch information
sfeakes authored Nov 10, 2024
2 parents f62f7f7 + 1b785e0 commit 0491f2a
Showing 1 changed file with 36 additions and 55 deletions.
91 changes: 36 additions & 55 deletions source/hassio.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ const char *HASSIO_CLIMATE_DISCOVER = "{"
"\"mode_state_template\": \"{%% set values = { '0':'off', '1':'heat'} %%}{{ values[value] if value in values.keys() else 'off' }}\","
"\"temperature_command_topic\": \"%s/%s/setpoint/set\","
"\"temperature_state_topic\": \"%s/%s/setpoint\","
"\"action_template\": \"{%% set values = { '0':'off', '1':'heating'} %%}{{ values[value] if value in values.keys() else 'off' }}\","
"\"action_topic\": \"%s/%s\","
/*"\"temperature_state_template\": \"{{ value_json }}\","*/
"%s"
"}";
Expand All @@ -72,6 +74,8 @@ const char *HASSIO_FREEZE_PROTECT_DISCOVER = "{"
"\"mode_state_template\": \"{%% set values = { '0':'off', '1':'auto'} %%}{{ values[value] if value in values.keys() else 'off' }}\","
"\"temperature_command_topic\": \"%s/%s/setpoint/set\","
"\"temperature_state_topic\": \"%s/%s/setpoint\","
"\"action_template\": \"{%% set values = { '0':'off', '1':'cooling'} %%}{{ values[value] if value in values.keys() else 'off' }}\","
"\"action_topic\": \"%s/%s\","
/*"\"temperature_state_template\": \"{{ value_json }}\""*/
"%s"
"}";
Expand Down Expand Up @@ -206,6 +210,19 @@ const char *HASSIO_SENSOR_DISCOVER = "{"
"\"icon\": \"%s\""
"}";

const char *HASSIO_SERVICE_MODE_ENUM_SENSOR_DISCOVER = "{"
"\"device\": {" HASS_DEVICE "},"
"\"availability\": {" HASS_AVAILABILITY "},"
"\"type\": \"sensor\","
"\"unique_id\": \"aqualinkd_%s\","
"\"name\": \"%s\","
"\"state_topic\": \"%s/%s\","
"\"device_class\": \"enum\","
"\"options\": [\"auto\",\"service\",\"timeout\"],"
"\"value_template\": \"{%% set values = { '0':'auto', '1':'service', '2':'timeout'} %%}{{ values[value] if value in values.keys() }}\","
"\"icon\": \"%s\""
"}";

const char *HASSIO_ONOFF_SENSOR_DISCOVER = "{"
"\"device\": {" HASS_DEVICE "},"
"\"availability\": {" HASS_AVAILABILITY "},"
Expand All @@ -232,6 +249,18 @@ const char *HASSIO_PUMP_SENSOR_DISCOVER = "{"
"\"icon\": \"mdi:pump\""
"}";

const char *HASSIO_BATTERY_SENSOR_DISCOVER = "{"
"\"device\": {" HASS_DEVICE "},"
"\"availability\": {" HASS_AVAILABILITY "},"
"\"type\": \"binary_sensor\","
"\"unique_id\": \"aqualinkd_%s\","
"\"name\": \"%s\","
"\"state_topic\": \"%s/%s\","
"\"payload_on\": \"0\","
"\"payload_off\": \"1\","
"\"device_class\": \"battery\""
"}";

// Same as above but no UOM
const char *HASSIO_PUMP_SENSOR_DISCOVER2 = "{"
"\"device\": {" HASS_DEVICE "},"
Expand Down Expand Up @@ -311,63 +340,11 @@ const char *HASSIO_SWG_TEXT_SENSOR_DISCOVER = "{"
"'128':'Check PCB',"
"'253':'General Fault',"
"'254':'Unknown',"
"'255':'Off'} %%}"
"'255':'off'} %%}"
"{{ values[value] if value in values.keys() else 'off' }}\","
"\"icon\": \"mdi:card-text\""
"}";

/*
char *HASSIO_TEXT_DISCOVER = "{"
"\"device\": {" HASS_DEVICE "},"
"\"type\": \"text\","
"\"unique_id\": \"aqualinkd_%s\","
"\"name\": \"%s\","
"\"command_topic\": \"junk/null\","
"\"state_topic\": \"%s/%s\""
"}";
*/
/*
char *HASSIO_SERVICE_MODE_DISCOVER = "{"
"\"type\": \"sensor\","
"\"unique_id\": \"aqualinkd_Service_Mode\","
"\"name\": \"Service Mode\","
"\"state_topic\": \"aqualinkd/Service_Mode\","
"\"value_template\": \"{% set values = { '0':'off', '1':'on'} %}{{ values[value] if value in values.keys() else 'off' }}\","
"\"icon\": \"mdi:account-wrench\""
"}";
*/

/*
Others to add
{
"type": "text",
"unique_id": "display",
"name": "AqualinkD Display Message",
"command_topic": "junk/null",
"state_topic": "aqualinkd/Display_Message"
}
{
"type": "sensor",
"unique_id": "Service_Mode",
"name": "Service Mode",
"state_topic": "aqualinkd/Service_Mode",
"value_template": "{% set values = { '0':'off', '1':'on'} %}{{ values[value] if value in values.keys() else 'off' }}",
"icon": "mdi:account-wrench"
}
mdi:pump
mdi:water-outline // orph, ph, ppm, swg
mdi:water-thermometer // water
mdi:thermometer // air
mdi:account-wrench // server
*/


void publish_mqtt_hassio_discover(struct aqualinkdata *aqdata, struct mg_connection *nc)
{
if (_aqconfig_.mqtt_hass_discover_topic == NULL)
Expand Down Expand Up @@ -396,6 +373,7 @@ void publish_mqtt_hassio_discover(struct aqualinkdata *aqdata, struct mg_connect
_aqconfig_.mqtt_aq_topic,aqdata->aqbuttons[i].name,
_aqconfig_.mqtt_aq_topic,aqdata->aqbuttons[i].name,
_aqconfig_.mqtt_aq_topic,aqdata->aqbuttons[i].name,
_aqconfig_.mqtt_aq_topic,aqdata->aqbuttons[i].name,
(_aqconfig_.convert_mqtt_temp?HASSIO_CONVERT_CLIMATE_TOF:HASSIO_NO_CONVERT_CLIMATE));
sprintf(topic, "%s/climate/aqualinkd/aqualinkd_%s/config", _aqconfig_.mqtt_hass_discover_topic, aqdata->aqbuttons[i].name);
send_mqtt(nc, topic, msg);
Expand Down Expand Up @@ -469,6 +447,7 @@ void publish_mqtt_hassio_discover(struct aqualinkdata *aqdata, struct mg_connect
_aqconfig_.mqtt_aq_topic,FREEZE_PROTECT_ENABELED,
_aqconfig_.mqtt_aq_topic,FREEZE_PROTECT,
_aqconfig_.mqtt_aq_topic,FREEZE_PROTECT,
_aqconfig_.mqtt_aq_topic,FREEZE_PROTECT,
(_aqconfig_.convert_mqtt_temp?HASSIO_CONVERT_CLIMATE_TOF:HASSIO_NO_CONVERT_CLIMATE));
sprintf(topic, "%s/climate/aqualinkd/aqualinkd_%s/config", _aqconfig_.mqtt_hass_discover_topic, FREEZE_PROTECT);
send_mqtt(nc, topic, msg);
Expand Down Expand Up @@ -637,7 +616,7 @@ void publish_mqtt_hassio_discover(struct aqualinkdata *aqdata, struct mg_connect
}

// Misc stuff
sprintf(msg, HASSIO_ONOFF_SENSOR_DISCOVER,_aqconfig_.mqtt_aq_topic,SERVICE_MODE_TOPIC,"Service Mode",_aqconfig_.mqtt_aq_topic,SERVICE_MODE_TOPIC, "mdi:account-wrench");
sprintf(msg, HASSIO_SERVICE_MODE_ENUM_SENSOR_DISCOVER,_aqconfig_.mqtt_aq_topic,SERVICE_MODE_TOPIC,"Service Mode",_aqconfig_.mqtt_aq_topic,SERVICE_MODE_TOPIC, "mdi:account-wrench");
sprintf(topic, "%s/sensor/aqualinkd/aqualinkd_%s/config", _aqconfig_.mqtt_hass_discover_topic, SERVICE_MODE_TOPIC);
send_mqtt(nc, topic, msg);

Expand All @@ -650,6 +629,8 @@ void publish_mqtt_hassio_discover(struct aqualinkdata *aqdata, struct mg_connect
sprintf(topic, "%s/sensor/aqualinkd/aqualinkd_%s/config", _aqconfig_.mqtt_hass_discover_topic, DISPLAY_MSG_TOPIC);
send_mqtt(nc, topic, msg);


sprintf(msg, HASSIO_BATTERY_SENSOR_DISCOVER,_aqconfig_.mqtt_aq_topic,BATTERY_STATE,BATTERY_STATE,_aqconfig_.mqtt_aq_topic,BATTERY_STATE);
sprintf(topic, "%s/binary_sensor/aqualinkd/aqualinkd_%s/config", _aqconfig_.mqtt_hass_discover_topic,BATTERY_STATE);
send_mqtt(nc, topic, msg);

}

0 comments on commit 0491f2a

Please sign in to comment.