Change to MQTT configuration

I currently have this entry in my config file

sensor: !include sensor.yaml

and I have a sensor file with a load of MQTT calculations etc., each of which starts along the lines of…

- platform: mqtt
  name: "Oil Last Time Stamp"
  state_topic: "home/rtl_433"`
#etc etc

The new regime wants

sensor:
  platform: mqtt
    state_topic: "home/bedroom/temperature"

but how & where would I do this? Do I need to create a new file (called mqtt?), and put all of my calculations in that file, and then reference the new mqtt file in my config file?

TIA

That’s not what it wants at all…

have you read the docs? it shows the old and new config there.

also see this post I just made ion another thread:

everything (sensors, binary sensors, lights, covers, fans, everything mqtt) now goes under the “mqtt:” key instead of using a “- platform: mqtt”

yes.

you do it just like you did with sensors only it’s under mqtt: instead now.

This is the “new regime”.

mqtt:
  sensor:
    - name: "Oil Last Time Stamp"
      state_topic: "home/rtl_433"

Thanks both.

I have created a new file called mqtt, and put this line in my config file

mqtt: !include mqtt.yaml

Within the mqtt file I have a load of sections similar to this

### OIL TANK SENSOR ############################################################
### Time Stamp ######
sensor
  - name: "Oil Last Time Stamp"
    state_topic: "home/rtl_433"
    value_template: >
      {% if value_json is defined and value_json.id == 136628653 %}
        {{ (value_json.time) }}
      {% else %}
        {{ states('sensor.oil_last_time_stamp') }}
      {% endif %}
    unit_of_measurement: 'UTC'
  - name: "Oil Tank Quantity"
#etc etc etc

This is slightly different from what @123 Taras wrote above, but my thinking is that the line mqtt is omitted because the code is within a file called mqtt instead. But it does seem to be working! :grinning:

EDITED TO ADD: I spoke too soon - I am unable to restart HA due to it not liking this line within my config.yaml file

mqtt: !include mqtt.yaml

but I am not sure why :sob:

That’s the rule for all cases where you redirect a domain key to use a separate file. For example, open the automations.yaml file and you’ll see the first line does not contain automation:

What’s the error message?

Failed to restart Home Assistant
The system cannot restart because the configuration is not valid: 
Error loading /config/configuration.yaml: in "/config/configuration.yaml", line 18, column 7: 
Unable to read file /config/mqtt.yaml.

This occurs whether or not I include the first line of
mqtt
within my mqtt.yaml file - which I tried in case it made a difference.
The mqtt code continues to run, as my Dashboard is updating as I would expect.

The correct key word is

sensor:

as opposed to what is present in your mqtt.yaml file

sensor

Thanks @123 ; line 18 of my config file is

mqtt: !include mqtt.yaml

So I take it that the above error is for some reason not able to read my config/mqtt.yaml file, which now starts

### OIL TANK SENSOR ############################################################
### Time Stamp ######
#mqtt
sensor:
  - name: "Oil Last Time Stamp"
    state_topic: "home/rtl_433"
    value_template: >
      {% if value_json is defined and value_json.id == 136628653 %}
        {{ (value_json.time) }}
      {% else %}
        {{ states('sensor.oil_last_time_stamp') }}
      {% endif %}
    unit_of_measurement: 'UTC'
### Air At Top ######    
#etc etc etc

Presumably I have still made an error with the syntax, but can’t see where. :cry:

I don’t see a syntax error. I used your example in my system and it was able to find mqtt.yaml and create the sensor without any complaints.

Here’s the relevant entry in configuration.yaml telling Home Assistant where manually configured MQTT entities are located.
image

Here are the contents of mqtt.yaml containing your sensor configuration:
image

After a restart (restarted because my configuration.yaml file did not originally have an mqtt: key) here is the sensor as it appears in Developer Tools > States. Its value is unknown because I have not published a value to its state_topic.

Are you sure you have the mqtt.yaml file in the same directory as configuration.yaml?

Apologies for the delay in replying but I have been away. It would appear that I had called my mqtt file mqtt and not mqtt.yaml, but I have now changed it and everything works. So thanks again, and sorry for being so stupid! :scream: