Problem with new MQTT format

Hi,

Can you let me know if the below works for you?

mqtt:
  sensor:
   name: "Refrigator Amps"
   state_topic: "tele/garageref/SENSOR"
   value_template: "{{value_json['ENERGY'].Current}}"
   unit_of_measurement: "A"
   unique_id: "testit" 

Thanks

Sorry it took me so long to respond, no excuse but life.

Yes - it worked and have migrated all my sensors to the correct format. Just be careful if you have many like I do you need to - name for each and indent.

Thanks

Yes, looking at your posted example - the problem was too many spaces after the -

As many here have struggled with the new MQTT format, so have I. Mine is related to it being part of a trigger for detecting the state and other various pieces of information from my Plex server. Hoping someone can help me figure out how to reformat this inside my templates.yaml file.

Here is what I currently have:

- trigger:
    - platform: mqtt
      topic: "plex/update"
  sensor:
    - name: "Webhook Plex State"
      state: >
        {% if (trigger.payload_json.event == 'media.play') %}
          playing
        {% elif (trigger.payload_json.event == 'media.pause') %}
          paused
        {% elif (trigger.payload_json.event == 'media.resume') %}
          resumed
        {% elif (trigger.payload_json.event == 'media.stop') %}
          stopped
        {% elif (trigger.payload_json.event == 'media.rate') %}
          rated
        {% elif (trigger.payload_json.event == 'media.scrobble') %}
          90% viewed
        {% endif %}

    - name: "Webhook Plex Player"
      state: "{{ trigger.payload_json.Player.title }}"

    - name: "Webhook Plex Media Type"
      state: "{{ trigger.payload_json.Metadata.type }}"

    - name: "Webhook Plex Media Title"
      state: "{{ trigger.payload_json.Metadata.title }}"

    - name: "Webhook Plex Media Length"
      state: "{{ ((trigger.payload_json.Metadata.duration|float)/60000) }}"

I have this other bit in my automations.yaml that publishes the data that the trigger reads:

- alias: Plex Webhook
  initial_state: 'on'
  trigger:
    platform: webhook
    webhook_id: ************************************
  action:
  - service: mqtt.publish
    data_template:
      topic: plex/update
      payload_template: '{{ (trigger.data[''payload''] | string)[12:][:-2] | replace
        ("\\\\", "\\") | replace ("\\\''", "''") | replace ("\\x","?") }}

        '

I am curious to what/how the new MQTT trigger would be formatted. Iā€™ve not tried it yet, but wondered if the beginning would be something like this:

- trigger:
    mqtt:
        topic: "plex/update"

Any help is appreciated as I donā€™t want to break things when I update. Thanks in advance.

Is anyoneā€™s HA install still complaining about MQTT switches and sensors even though theyā€™ve moved everything under the mqtt: label?

Iā€™ve moved all mine across and all are working, but I still get the following every time I start HA - and I cannot find anywhere that is still using the old format (Iā€™ve even tried a grep -r 'platform:mqtt' *.yaml in the config directory to be sure.

2022-07-17 20:20:28 WARNING (MainThread) [homeassistant.components.mqtt.mixins] Manually configured MQTT switch(s) found under platform key 'switch', please move to the mqtt integration key, see https://www.home-assistant.io/integrations/switch.mqtt/#new_format
2022-07-17 20:20:32 WARNING (MainThread) [homeassistant.components.mqtt.mixins] Manually configured MQTT sensor(s) found under platform key 'sensor', please move to the mqtt integration key, see https://www.home-assistant.io/integrations/sensor.mqtt/#new_format

You need a space after the colon. You couldā€™ve missed old files or sections.

Thatā€™s actually what I did in the console (just mistyped it here) and it shows nothing other than a couple of entries in automations.yaml where I use MQTT as a trigger for a couple of automations.

Other than that, thereā€™s nothing, yet HA still complains that there isā€¦

bet ya you have .yml files

Nope - all .yaml and no .yml.

Then I suggest you find another way to search your files. Only the old method via yaml will produce that warning.

Just tested that on my config which I KNOW has old format mqtt in it, and it just says it could find any files.

However:

grep -rnw '/config/cfg/' -e 'platform: mqtt'

returns loads of results.

(My config files are in /config/cfg/_components/)

Ah! Found it!

I think it comes from having followed the instructions here to setup zigbee2mqtt control.

Iā€™ll raise an issue on the Z2M github to have them update their docs/code.

Sorry to bother you as well with my config.
Actually I have this:

sensor:

  - platform: mqtt
    name: "WeinkellerTK_Temperatur"
    state_topic: "MobileAlerts/090ece9e9d9c/json"
    unit_of_measurement: 'Ā°C'
    value_template: "{{value_json.temperature[0]}}"
  - platform: mqtt
    name: "WeinkellerTK_Feuchte"
    state_topic: "MobileAlerts/090ece9e9d9c/json"
    unit_of_measurement: 'Ā°C'
    value_template: "{{value_json.humidity[0]}}"
  - platform: mqtt
    name: "Gefriertruhe_Temperatur"
    state_topic: "MobileAlerts/090ece9e9d9c/json"
    unit_of_measurement: 'Ā°C'
    value_template: "{{value_json.temperatureExt[0]}}"

and so on for some 20 Sensors more.
I tried several things but was not successful. Can anybody give me a running solution to this?

Thanks so much Peter

Solved with help from FB group.

Did anyone automate the conversion from the old format to the new format?

Tried to change binary_sensors, sensors and switches to the new format. No go. Heā€™s an example of what I now have for a binary_sensor

mqtt:
  binary_sensor:
    - name: "front_door_bsensor"
      device_class: door
      state_topic: "home-assistant/contact/front_door"
      payload_on: "ON"
      availability:
        - topic: "home-assistant/contact/front_door/availability"
          payload_available: "online"
          payload_not_available: "offline"
      qos: 0
      value_template: "{{ value_json.state }}"
      unique_id: 98F4ABD0B919A0

Iā€™m expecting to have an entity front_door_bsensor, but no go. No errors when loading configuration. It seems this should work, but no go. I have the latest HA 2022.9.2 installed. I enable mqtt logging. Nothing showing. Any thoughts?

What does the actual MQTT received data look like from home-assistant/contact/front_door - are you sure it is actually JSON?

You have a payload_on: but not a payload_off: the text you enter in to both, must match what is actually received.

This line simulates it

mosquitto_pub -u mqtt -P Hass10mqtt -h 127.0.0.1 -t home-assistant/contact/basement_door -m '{"state":"OFF"}'

so should be json. Iā€™m expecting some entity to be created even if there is no data, but I donā€™t even get the entity. I was using the old HA configuration for years and it worked fine. I changed the ā€œnameā€ and ā€œunique_idā€ in the new configuration expecting to get an entity for the new name. But no entity with the new name is showing up under the settings->entity page.

OK the next question is WHERE exactly are you adding this configuration? Is it directly in to configuration.yaml or an included file, or a split configuration format? Iā€™m asking because with no errors showing up, it appears that Home Assistant isnā€™t even loading the addition.

Itā€™s in configuration.yaml