Automatically add new sensors to area

It would be great if newly created sensors could be added to an Area in HA automatically. I don’t think this is possible, but maybe a future update to the MQTT integration could have such functionality?

In one application that I am working on we have many smart marine sensors provided through MQTT. There is already metadata with the sensor that could be used to both create and assign an area. It is tedious to manually assign the area, and we also have new sensors created as they are deployed which could also automatically be assigned to an area or otherwise labeled.

For example the salinity sensor below is formatted as described in MQTT - Home Assistant and subsequently auto discovered by HA when the sensor is posted to mosquitto MQTT:

As you can see we already have a site attribute, a source attribute and a description attribute which are all suitable for label, area, or category.

The feature I am looking for would use an attribute as specified by the user to create if necessary a new area named in the attribute and then assign the sensor to the new area. This could be done when a config topic is received. So using the example in the current documentation for a config payload I have added the area field below:

{
   "device_class":"temperature",
   "state_topic":"homeassistant/sensor/sensorBedroom/state",
   "unit_of_measurement":"°C",
   "value_template":"{{ value_json.temperature}}",
   "unique_id":"temp01ae",
   "device":{
      "area": "Bedroom",
      "identifiers":[
          "bedroom01ae"
      ],
      "name":"Bedroom",
      "manufacturer": "Example sensors Ltd.",
      "model": "K9",
      "serial_number": "12AE3010545",
      "hw_version": "1.01a",
      "sw_version": "2024.1.0",
      "configuration_url": "https://example.com/sensor_portal/config"
   }
}

Could this be considered as a feature request for MQTT? Please?

:slight_smile:

Hi Jeremy Cook,

The suggested_area tag is added to the device section of the discovery topic.
MQTT - Home Assistant.

'cu':                  'configuration_url',
'cns':                 'connections',
'ids':                 'identifiers',
'name':                'name',
'mf':                  'manufacturer',
'mdl':                 'model',
'hw':                  'hw_version',
'sw':                  'sw_version',
'sa':                  'suggested_area',
'sn':                  'serial_number',

I have used it many times. If you want to see my use of it look at my Octoprint automation blueprint in my blueprint link in the footer of this message.

Based on this I am changing yout [FR] into a configuration question.

1 Like

Great, and thanks.

This is working well. If the area doesn’t exist then it is created, and the incoming sensor is added to the correct area. If I rename the created area to something else then the area is not recreated and the sensor is not subsequently moved back (which is how you would want it).

From what I can see from my rudimentary tests, if I remove an area, then I need to restart HA to have it recreated by the incoming MQTT.