Can I assign an MQTT room sensor to an area?

I would like to collect my ESPresense devices and sensors in the same group in the default UI (the one that comes when you haven’t defined any custom UI’s). I tried this, which doesn’t work:

  - platform: mqtt_room
    device_id: "iBeacon:2f234454-cf6d-4a0f-adf2-f4911ba9ffa6-1-1"
    state_topic: 'espresense/rooms'
    name: 'Tor'
    away_timeout: 30
    area: 'ESPresense'

So obviously I can’t put the area in the sensor. But at the same time I can’t change anything in the UI, there are no options for that. So is it possible in any way?

1 Like

Could you share a screenshot of the device?

Similar to the following:

Next to the device name at the top of my screenshot is what I click to set the area of the device, which sets the area of the sensors.

No, can’t. Sensors that are defined in configuration.yaml does not have a device, it seems. If they did, it wouldn’t be a problem. I do know how to set the area of devices. :wink:

Set the unique id, and it should work.

1 Like

It should, yes. But it doesn’t seem to:

Invalid config for [sensor.mqtt_room]: [unique_id] is an invalid option for [sensor.mqtt_room]. Check: sensor.mqtt_room->unique_id. (See /home/homeassistant/.homeassistant/configuration.yaml, line 9). Please check the docs at MQTT room presence - Home Assistant

Edit: It is possible that this is only possible for regular mqtt sensors, and not for mqtt_room sensors.

1 Like

Use MQTT Discovery to create the sensor. It allows you to define more options (like device and suggested_area) than manual configuration.

The following post contains an example of how to compose a script that creates sensors via MQTT Discovery:

Thanks! I will look at that later, it seems like it takes a bit of time. Just to make sure first, you are sure that this will work for mqtt_room sensors too, and not just physical sensors like the temp sensors in the script?

I have 41 MQTT-based entities (light, switch, binary_sensor, sensor, lock, alarm_control_panel, and climate) and they have all been created via MQTT Discovery using scripts like in the example.

Screenshot from 2022-02-06 12-10-22

FWIW, other users in this forum employ the same technique and have even more entities and devices.

OK, thanks again! I will try to get the script working for me.

Uh-oh! I may have to retract the advice I offered.

I just double-checked MQTT Discovery’s documentation and now I have my doubts it supports MQTT Room Presence. The two options called timeout and away_timeout are not in the list. That implies you won’t be able to define a Room Presence sensor using MQTT Discovery (or the documentation isn’t up to date). Give it a try but if it fails with an error (in the log) then it probably means it can’t be done (in which case you’re limited to using manual configuration and its limitations).

OK, thanks. I’ll see when I have the time to test. Probably not today, I have a ton of work still to do before I go to bed…

Hi,
123, sorry to hijack this topic a bit but I have exactly the same issue with being unable to have anything more than an entity (that doesn’t work nicely with area card)

I have a home automation that produces it’s mqtt logic:

this is how i get a normal light to work with homassistant:

  - platform: mqtt
    schema: template
    name: "Licht Tafel 2"
    command_topic: "cloudapp/QBUSMQTTGW/UL1/UL30/setState"
    state_topic: "cloudapp/QBUSMQTTGW/UL1/UL30/state"
    state_template: >-
          {% if value_json.properties.value == true %}
            on
            {% else %}
            off
            {% endif %}
    command_on_template: '{"id": "UL30","type": "state","properties": {"value": true}}'
    command_off_template: '{"id": "UL30","type": "state","properties": {"value": false}}'

is this something that can easily be converted to autodiscovery? (the ULxx part is the unique light id) (UL1 is the controller)

Yes; try it.

i want to :slight_smile:
would you mind pointing me in the right direction, (a how to with examples or something :slight_smile: )
greatly appreciated, and thx in advance

Follow the link in my first post.

1 Like

Ok will do

quick shorts (if you have the time)

  • am I right to say the person in that topic didn’t use auto discovery at the end?
  • am I right to say home assistant needs to ‘create’ the topic too even though my ‘hardware’ is the ‘original creator’?

(again sorry for the bombardment)

resulting in something like this:

      - service: mqtt.publish
        data:
          topic: cloudapp/QBUSMQTTGW/UL1/UL14/
          retain: true
          payload: >
            {
              "name": "first light test",
              "state_topic": "cloudapp/QBUSMQTTGW/UL1/UL14/state",
              "command_topic": "cloudapp/QBUSMQTTGW/UL1/UL14/setState",
              "payload_on": '{"id": "UL14","type": "state","properties": {"value": true}}',
              "payload_off": '{"id": "UL14","type": "state","properties": {"value": false}}',
              "state_on": '{"id":"UL44","properties":{"value":true},"type":"event"}',
              "state_off": '{"id":"UL44","properties":{"value":false},"type":"event"}',
              "unique_id": "first_light_test",
              "device": {
                  "name": "first test light"
              }
            }

They did use auto-discovery, and reported the loading time decreased dramatically.

I don’t know anything about your hardware and what it does so I can’t answer that question.

In the example you posted, the payload must contain valid JSON but it doesn’t. You can’t use single-quotes the way you did. Use a JSON validator to test and correct the payload’s syntax.

I’ll have to check into it further :slight_smile: missing something that makes it click for me…

Using this code now to use my mqtt light:

  - platform: mqtt
    schema: template
    name: "Licht Tafel 2"
    command_topic: "cloudapp/QBUSMQTTGW/UL1/UL30/setState"
    state_topic: "cloudapp/QBUSMQTTGW/UL1/UL30/state"
    state_template: >-
          {% if value_json.properties.value == true %}
            on
            {% else %}
            off
            {% endif %}
    command_on_template: '{"id": "UL30","type": "state","properties": {"value": true}}'
    command_off_template: '{"id": "UL30","type": "state","properties": {"value": false}}'

But the moment this starts to slow down auto discovery will force itself on me :slight_smile:

If you use this:

- service: mqtt.publish
  data:
    topic: homeassistant/light/first_test/config
    retain: true
    payload: >
      {
        "name": "first light test",
        "state_topic": "cloudapp/QBUSMQTTGW/UL1/UL14/state",
        "command_topic": "cloudapp/QBUSMQTTGW/UL1/UL14/setState",
        "payload_on": "{\"id\": \"UL14\",\"type\": \"state\",\"properties\": {\"value\": true}}",
        "payload_off": "{\"id\": \"UL14\",\"type\": \"state\",\"properties\": {\"value\": false}}",
        "state_on": "{\"id\":\"UL44\",\"properties\":{\"value\":true},\"type\":\"event\"}",
        "state_off": "{\"id\":\"UL44\",\"properties\":{\"value\":false},\"type\":\"event\"}",
        "unique_id": "first_light_test",
        "device": {
            "identifiers": ["test_lights"],
            "name": "first test light",
            "model": "ABC",
            "manufacturer": "XYZ",
            "sw_version": "1.0"
        }
      }

It will produce an entity:

and a device for the entity:

1 Like

superb! thx I’ll check it out,

pasted in my blank scripts yaml,
but I’m getting an error from a hacs plugin,

Invalid config for [script]: expected a dictionary. Got OrderedDict([('default_config', {}), ('sensor', [OrderedDict([('platform', 'rest'), ('name', 'Opelmokka'), ('resource', 'http://192.168.0.140:5000/get_vehicleinfo/?from_cache=1'), ('scan_interval', 60), ('timeout', 30), ('value_template', 'OK'), ('json_attributes', ['energy', 'timed_odometer', 'battery'])]), OrderedDict([('platform', 'template'), ('sensors', OrderedDict([('mokka_battery_voltage', OrderedDict([('friendly_name', 'Battery Voltage'), ('unit_of_measurement', 'V'),.... (See /config/configuration.yaml, line 12).

10:11:41 PM – (ERROR) config.py - message first occurred at 10:11:41 PM and shows up 2 times

but that will be something on my end i need to figure out!
thanks a bunch!