Help needed with MQTT 2022.6 breaking change

thank you for your answer.
So I should move all mqtt and template sensor in configuration yaml under
MQTT: and Template : is it correct?
Can I have on separate file using !include comand?
Something like

mqtt: !include mqtt:yaml
template:  !include template:yaml

Please excuse me for this dumb question I am trying my best to understand this stuff but I have zero background in programming YAML

Yes, you can definitely do that.


EDIT

Correction. The file names should contain a period, not a colon.

mqtt: !include mqtt.yaml
template:  !include template.yaml

Thanks to petro for pointing out the typo.

For template:, be aware that both the syntax and the functionality have changed with the new configuration format, it’s not just a matter of moving the sensor configurations over :frowning:

1 Like

I want to cry :sob:

Are you able to tell me if there is a source where I can understand how I have to change my sintax?

I made a template.yaml as follows and the configuration is valid but if I restart HA I receive an error. I am surely missing something. Is there an example I can follow?

Invalid config for [template]: [template] is an invalid option for [template]. Check: template->template. (See /config/template.yaml, line 1).
template :
    sensors:
      my_wupws_humidity:
        unit_of_measurement: "%"
        value_template: "{{states('sensor.wupws_humidity') | int }}"

    sensors:
      andrea_phone:
        friendly_name: "Batteria Andrea"
        unit_of_measurement: '%'
        value_template: "{{ state_attr('device_tracker.life360_andrea_bb', 'battery') }}"
        device_class: battery
        

    sensors:
      elisa_phone:
        friendly_name: "Batteria Elisa"
        unit_of_measurement: '%'
        value_template: "{{ state_attr('device_tracker.life360_elisa_vv', 'battery') }}"
        device_class: battery
              

    sensors:
      neri_phone:
        friendly_name: "Batteria Neri"
        unit_of_measurement: '%'
        value_template: "{{ state_attr('device_tracker.life360_neri_me', 'battery') }}"
        device_class: battery              
   
    

    sensors:
      shelly_em_corrente_ch1:
        friendly_name: "Corrente casa"
        value_template: '{{ (states("sensor.Assorbimento_casa")|float / states("sensor.tensione_condominio")|float)|float|round(1) }}'
        unit_of_measurement: "Ampere"
        icon_template: mdi:current-ac
      shelly_em_corrente_ch2:
        friendly_name: "Corrente condominio"
        value_template: '{{ (states("sensor.Assorbimento_condominio")|float / states("sensor.tensione_condominio")|float)|float|round(1) }}'
        unit_of_measurement: "Ampere"
        icon_template: mdi:current-ac

It’s in the documentation for the Template integration. However, you are not obligated to convert your existing Template Sensors, which are defined in what is now known as ‘legacy format’, into the new “modern format”. Just leave them in sensors.yaml.

In addition, if you do this:

sensor: !include sensors.yaml
mqtt: !include mqtt.yaml
template:  !include template.yaml

then the first line in sensors.yaml should not contain sensor: key word (or mqtt: for mqtt.yaml or template: for templates.yaml). If you do include the key word on the first line, you are effectively duplicating it and it will fail Configuration Check.

EDIT

Correction. Replaced colon with period in file name.

2 Likes

thank you for your reply, I was just trying to update all the configurations while I was fixing the MQTT stuff.
Maybe I’ll try to update the “template question” in the future for now I fixed the MQTT config for the incoming 2022.9

thank you

Op keeps adding : in his includes and you must have copied it. Op should make sure he specifies actual file names not template:yaml

2 Likes

Thank you guys for all your effort in helping me. really appreciated!

1 Like

Looks Like I’m need some help also moving to this new format. I have everything setup with my include to mqtt.yaml.

I tried to follow the example here, but I’m obviously missing something with the formatting.

You only need the first -sensor: . Remove the others.
Like:

  sensor:
    - name: "Teckin01 Energia Hoy"
      state_topic: "tele/teckin01/SENSOR"
      value_template: '{{ value_json["ENERGY"]["Today"] }}'
      unit_of_measurement: "kWh"
    - name: "Teckin01 Energia Ayer"
      state_topic: "tele/teckin01/SENSOR"
      value_template: '{{ value_json["ENERGY"]["Yesterday"] }}'
      unit_of_measurement: "kWh"
    - name: "Teckin01 Energia Total"
      state_topic: "tele/teckin01/SENSOR"
      value_template: '{{ value_json["ENERGY"]["Total"] }}'
      unit_of_measurement: "kWh"
1 Like

Thank You.

EDIT: I was so close, but… :slight_smile:

OK, another one with problems converting to the new syntax.

My manual config is split across a number of “theme”-based yaml files in packages
Two of them have mqtt configured sensors. I am seeing the same problem in both. One will serve as an example.

mqtt:
  sensor:
    # Temperatures
    - name: "Shed Temperature"
      state_topic: "emon/emonth4/temperature"
      unit_of_measurement: "°C"
      device_class: temperature
      value_template: "{{ value | float | round(1) }}"
      expire_after: 300

    - name: "Bedroom1 Temperature"
      state_topic: "emon/emonth5/temperature"
      unit_of_measurement: "°C"
      device_class: temperature
      value_template: "{{ value | float | round(1) }}"
      expire_after: 300

I get no errors when I run ha core check, but when HA restarts I see errors of the form:

The version platform for the sensor integration does not support platform setup. Please remove it from your config.
17:05:59 – (ERROR) Sensor - message first occurred at 17:05:59 and shows up 2 times
Unable to prepare setup for platform mqtt.switch: Unable to set up component.
17:05:57 – (ERROR) setup.py
Setup failed for mqtt: Invalid config.
17:05:57 – (ERROR) setup.py
Invalid config for [mqtt]: [sensor] is an invalid option for [mqtt]. Check: mqtt->mqtt->sensor. (See ?, line ?). Please check the docs at https://www.home-assistant.io/integrations/mqtt
17:05:57 – (ERROR) config.py

and

2022-06-02 17:05:57 ERROR (MainThread) [homeassistant.config] Invalid config for [mqtt]: [sensor] is an invalid option for [mqtt]. Check: mqtt->mqtt->sensor. (See ?, line ?). Please check the docs at https://www.home-assistant.io/integrations/mqtt
2022-06-02 17:05:57 ERROR (MainThread) [homeassistant.setup] Setup failed for mqtt: Invalid config.

Looks like you have it setup as

mqtt:
  mqtt:
    sensor:

Thanks. I saw that, but I can’t see where that first mqtt: is.
The Mosquitto integration is configured through the GUI - there’s no reference to it in configuration.yaml. All the real config takes in places in packages. The relevant one starts:

# Batteries.yaml
# Stuff to report battery state and raise an elert of a battery state gets low.
#
# Customisations to facilitate selecting the filtered battery levels
homeassistant:
  customize:
    sensor.filtered_shed_battery:
      type: "filtered"
    sensor.filtered_bedroom1_battery:
      type: "filtered"
    sensor.filtered_bedroom2_battery:
      type: "filtered"
    sensor.filtered_livingroom_battery:
      type: "filtered"
    sensor.filtered_shack_battery:
      type: "filtered"

# emonCMS battery sensors
mqtt:
  sensor:
    - name: "Shed Battery"
      state_topic: "emon/emonth4/battery"
      unit_of_measurement: "V"
      device_class: battery
      value_template: "{{ value | float | round(1) }}"
      expire_after: 300

I see no place where an extra level got added in. However, I do see that VSC (I’m using the VSC editor addon) does put a blue hash highlight on that whole section.

OK, panic over. I wasn’t running 2022.6.0 as I thought. Could have sworn I’d upgraded before I started tidying up.

Not sure about the terminology, but it looks like it’s not possible to have multiple instances of the mqtt: configuration key, each with a unique secondary identifier, the way you can with platform keys like binary_sensor, sensor, etc. This would be helpful (to me at least) to keep the YAML more manageable.

For example…

# this validates but has been deprecated

binary_sensor basement:
  - platform: mqtt
    name: Basement Motion 1
  - platform: mqtt
    name: Basement Motion 2

binary_sensor bedrooms:
  - platform: mqtt
    name: Hall Motion

# but this doesn't validate

mqtt basement:
  binary_sensor:
    - name: Basement Motion 1
    - name: Basement Motion 2

mqtt bedrooms:
  binary_sensor:
    - name: Hall Motion

# and neither does this

mqtt:
  binary_sensor basement:
    - name: Basement Motion 1
    - name: Basement Motion 2
  binary_sensor bedrooms:
    - name: Hall Motion

Hi,

I have hundreds of sensors and switches with MQTT. Is there a tool available which is changing the config in Bulk to the new concep?

Br,
Johannes

2 Likes

I have rewritten syntax in accordance to recent changes, but now when I check config before rebooting HA I get:

Invalid config for [mqtt]: [entity_id] is an invalid option for [mqtt]. Check: mqtt->mqtt->sensor->44->entity_id. (See /config/configuration.yaml, line 81).

Here’s the look of My config.yaml, line 81 corresponds to MQTT:

mqtt:
  broker: 192.168.0.3
  port: 1883
  discovery: true
  keepalive: 60
  username: user
  password: pass
  sensor:
    - name: "VoltageV1"
      state_topic: "1728053740.V1"
      unit_of_measurement: "В"
      value_template: "{{ value | round(0) }}"
    - name: "VoltageV2"
      state_topic: "1728053740.V2"
      unit_of_measurement: "В"
      value_template: "{{ value | round(0) }}"

What is wrong?

Did you ever figure this out?

I’m running into the same issue…

If you’re still experiencing this issue, take a look at this solution:
https://community.home-assistant.io/t/problem-with-new-mqtt-format/428745/19?u=ha_noobie
Which says to format the MQTT section of the “configuration.yaml” like so:

sensor:
  - name: "Outside Temperature"  
    state_topic: "building/dhjm/eobs/external/wx"
    unit_of_measurement: '°C'
    value_template: "{{ value_json['obs']['temperature'] }}"`

It resolved my issue.