MQTT_ROOM error

Hello All,

I’ve setup an ESP32 with ESPRESENSE.
I’ve added it to MQTT

Now when i try to add the YAML i get an error, so i might be doing something wrong.
I hade split-up my configuration.yaml so i have a seperate sensors.yaml

I already have some stuff there

But when i add:

- Platform: mqtt_room
  name: testst
  device_id: XXXXXXXX
  state_topic: espresense/rooms

i receive an error that “- Platform: mqtt_room” is not valid.

Error:

image

Where? What file are we looking at?
Also DO NOT POST IMAGES of code.
How to help us help you - or How to ask a good question - Configuration - Home Assistant Community (home-assistant.io)

Where? What file are you trying to add this to?

Do not post fragments, post the whole yaml file that is giving you problems.

Woops. Sorry!.

I have a seperate sensors.yaml so i split my configuration.yaml.

My current sensors.yaml is the following:

##  SolarEdge Templates  ##
- platform: template
  sensors:
    solaredge_energy_this_year_template:
      value_template: "{{ (states('sensor.solaredge_energy_this_year') | float / 1000) | round(0) }}"
      unit_of_measurement: "kWh"
    solaredge_current_power_template:
      value_template: "{{ (states('sensor.solaredge_current_power') | float / 1000) | round(2) }}"
      unit_of_measurement: "kW"
    solaredge_energy_today_template:
      value_template: "{{ (states('sensor.solaredge_energy_today') | float / 1000) | round(2) }}"
      unit_of_measurement: "kWh"
    solaredge_lifetime_energy_template:
      value_template: "{{ (states('sensor.solaredge_lifetime_energy') | float / 1000) | round(2) }}"
      unit_of_measurement: "kWh"

# Total Lights On
- platform: template
  sensors:
    total_lights:
      unique_id: total_light
      friendly_name: "Total Lights On"
      value_template: >-
        {{ states.light
          |selectattr('state','eq','on')
          |rejectattr('attributes.entity_id','defined')
          |list |count }}
      attribute_templates:
        light_entities: >-
          {% set domain = 'light' %}
          {% set entities = states[domain] | selectattr('state','eq','on') | map(attribute='entity_id') | list %}
          {%- for s in entities -%}
          - {{ s }},
          {%- endfor %}
          
- platform: mqtt_room
  sensors:
    name: "MDL"
    device_id: "apple:1006:10-12"
    state_topic: "espresense/rooms"
    away_timeout: 30
    timeout: 5

This give’s me the above error when restarting Home Assistant
Error: Invalid config for ‘sensor’ from integration ‘mqtt_room’ at sensors.yaml, line 96: required key ‘device_id’ not provided

I could be wrong, and often am, but I suspect that the sensors key is not in the mqtt_room platform. Try this:

sensor:
  - platform: mqtt_room
    name: "MDL"
    device_id: "apple:1006:10-12"
    state_topic: "espresense/rooms"
    away_timeout: 30
    timeout: 5
1 Like

I will.
But then i have to swoop all others also right?

Other what? There’s only one platform: mqtt_room in the yaml file you posted.

Cause my sensors.yaml file is build this way:

## Voor het batterij icoon in de person template van Maurice ##
- platform: template
  sensors:
    iphone_van_maurice_battery_icon:
      friendly_name: "iPhone van Maurice Battery Icon"
      value_template: >
        {% set state = states('sensor.iphone_van_maurice_battery_level')|float %}
        {% if state >= 0 and state < 10 %} mdi:battery-10
        {% elif state >= 10 and state < 20 %} mdi:battery-20
        {% elif state >= 20 and state < 30 %} mdi:battery-30
        {% elif state >= 30 and state < 40 %} mdi:battery-40
        {% elif state >= 40 and state < 50 %} mdi:battery-50
        {% elif state >= 50 and state < 60 %} mdi:battery-60
        {% elif state >= 60 and state < 70 %} mdi:battery-70
        {% elif state >= 70 and state < 80 %} mdi:battery-80
        {% elif state >= 80 and state < 95 %} mdi:battery-90
        {% else %} mdi:battery
        {% endif %}
- platform: template
  sensors:
    iphone_van_maurice_battery_color:
      friendly_name: "iPhone van Maurice Battery Color"
      value_template: >
        {% set state = states('sensor.iphone_van_maurice_battery_level')|float %}
        {% if state >= 0 and state < 20 %} red
        {% elif state >= 20 and state < 50 %} orange
        {% elif state >= 50 and state < 70 %} yellow
        {% else %} green
        {% endif %}

## Voor het batterij icoon in de person template van Yvette ##
- platform: template
  sensors:
    iphone_van_yvette_battery_icon:
      friendly_name: "iPhone van Yvette Battery Icon"
      value_template: >
        {% set state = states('sensor.iphone_van_maurice_battery_level')|float %}
        {% if state >= 0 and state < 10 %} mdi:battery-10
        {% elif state >= 10 and state < 20 %} mdi:battery-20
        {% elif state >= 20 and state < 30 %} mdi:battery-30
        {% elif state >= 30 and state < 40 %} mdi:battery-40
        {% elif state >= 40 and state < 50 %} mdi:battery-50
        {% elif state >= 50 and state < 60 %} mdi:battery-60
        {% elif state >= 60 and state < 70 %} mdi:battery-70
        {% elif state >= 70 and state < 80 %} mdi:battery-80
        {% elif state >= 80 and state < 95 %} mdi:battery-90
        {% else %} mdi:battery
        {% endif %}
- platform: template
  sensors:
    iphone_van_yvette_battery_color:
      friendly_name: "iPhone van Yvette Battery Color"
      value_template: >
        {% set state = states('sensor.iphone_van_maurice_battery_level')|float %}
        {% if state >= 0 and state < 20 %} red
        {% elif state >= 20 and state < 50 %} orange
        {% elif state >= 50 and state < 70 %} yellow
        {% else %} green
        {% endif %}

##  SolarEdge Templates  ##
- platform: template
  sensors:
    solaredge_energy_this_year_template:
      value_template: "{{ (states('sensor.solaredge_energy_this_year') | float / 1000) | round(0) }}"
      unit_of_measurement: "kWh"
    solaredge_current_power_template:
      value_template: "{{ (states('sensor.solaredge_current_power') | float / 1000) | round(2) }}"
      unit_of_measurement: "kW"
    solaredge_energy_today_template:
      value_template: "{{ (states('sensor.solaredge_energy_today') | float / 1000) | round(2) }}"
      unit_of_measurement: "kWh"
    solaredge_lifetime_energy_template:
      value_template: "{{ (states('sensor.solaredge_lifetime_energy') | float / 1000) | round(2) }}"
      unit_of_measurement: "kWh"

# Total Lights On
- platform: template
  sensors:
    total_lights:
      unique_id: total_light
      friendly_name: "Total Lights On"
      value_template: >-
        {{ states.light
          |selectattr('state','eq','on')
          |rejectattr('attributes.entity_id','defined')
          |list |count }}
      attribute_templates:
        light_entities: >-
          {% set domain = 'light' %}
          {% set entities = states[domain] | selectattr('state','eq','on') | map(attribute='entity_id') | list %}
          {%- for s in entities -%}
          - {{ s }},
          {%- endfor %}

Adding this will also error:

sensor:
  - platform: mqtt_room
    name: "MDL"
    device_id: "apple:1006:10-12"
    state_topic: "espresense/rooms"
    away_timeout: 30
    timeout: 5

So i think i need to convert some things but i don’t know exactly how…

No you don’t. Just add that code without the sensor: first line so that you have:

- platform: template
  sensors:
    [config]

- platform: mqtt_room
  [config]