Skip to content

Commit

Permalink
Home Assistant Integration Updates
Browse files Browse the repository at this point in the history
As Home Assistant now sends an MQTT birth message by default on homeassistant/status. config.inc.php has been updated to reflect this.
Additionally the MQTT Discovery routines have been updated to include the needed nodes for the Device Registry so that devices will show up as devices and not just entities under the MQTT Integration
  • Loading branch information
sktaylortrash committed Feb 16, 2021
1 parent 9ebdf03 commit bae6bee
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 15 deletions.
2 changes: 1 addition & 1 deletion config.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,5 +85,5 @@
$MQTT_control = "tcp"; // Control topic identifier for host and script control ie control/<MQTT_control>
$ENABLE_HA_DISCO = 1; // Enable MQTT Publishing of Home Assistant Discovery Topics (1 = true, 0 = false)
$HASSTopic_id = "homeassistant"; // Topic prefix for Home Assistant Discovery Topics - this must match with HASS
$HASSOnline = "hass/status"; // Topic Home Assistant publishes to, to announce its online
$HASSOnline = "homeassistant/status"; // Topic Home Assistant publishes to, to announce its online
?>
35 changes: 21 additions & 14 deletions mqttdiscovery.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,20 +92,27 @@
foreach($DEVICES as $device){
$DeviceName = str_replace(' ', '', $device['name']);
$DeviceCommand = $RoomName."/".$DeviceName."/".$device['did'];
$myObj->name = $device["name"];
$myObj->unique_id = $device['did'];
$myObj->command_topic = $MQTT_prefix."/".$DeviceCommand."/switch";
$myObj->state_topic = $MQTT_prefix."/".$DeviceCommand."/status";
$myObj->brightness_command_topic = $MQTT_prefix."/".$DeviceCommand."/brightness/set";
$myObj->brightness_state_topic = $MQTT_prefix."/".$DeviceCommand."/brightness";
$myObj->availability_topic = $MQTT_prefix."/".$DeviceCommand."/LWT";
$myObj->brightness_scale = 100;
$myObj->qos = 0;
$myObj->payload_on = "1";
$myObj->payload_off = "0";
$myObj->optimistic = "false";

$myJSON = json_encode($myObj, JSON_UNESCAPED_SLASHES);
$array = array(
"name" => $device["name"],
"unique_id" => $device['did'],
"command_topic" => $MQTT_prefix."/".$DeviceCommand."/switch",
"state_topic" => $MQTT_prefix."/".$DeviceCommand."/status",
"brightness_command_topic" => $MQTT_prefix."/".$DeviceCommand."/brightness/set",
"brightness_state_topic" => $MQTT_prefix."/".$DeviceCommand."/brightness",
"availability_topic" => $MQTT_prefix."/".$DeviceCommand."/LWT",
"brightness_scale" => 100,
"qos" => 0,
"payload_on" => "1",
"payload_off" => "0",
"optimistic" => "false",
"device" => array(
"ids" => $device['did'],
"name" => $device["name"],
"mf" => "TCP",
"mdl" => "TCP Bulb"
)
);
$myJSON = json_encode($array, JSON_UNESCAPED_SLASHES);
$Topic = $HASSTopic_id."/light/".$device['did']."/config";
//echo $myJSON.'<br/>';
//echo $Topic.'<br/>';
Expand Down

0 comments on commit bae6bee

Please sign in to comment.