Help with new MQTT Sensor 2022.6 YAML Syntax

Trying to get ahead of the MQTT YAML syntax change in the 2022.6 update, but can’t get it right without throwing a ton of errors. Can anyone help?

My working config section that doesn’t conform to the new format:

sensor:
  - platform: mqtt
    state_topic: "rtl_433/226d4b83cd4b/devices/LaCrosse-TX141THBv2/0/63/temperature_C"
    device_class: temperature
    unique_id: LaCrosse_temp
    name: outside_temp
    unit_of_measurement: '°C'
  - platform: mqtt
    state_topic: "rtl_433/226d4b83cd4b/devices/LaCrosse-TX141THBv2/0/63/humidity"
    device_class: humidity
    unique_id: LaCrosse_humidity
    name: outside_humidity
    unit_of_measurement: '%'
    #Sensor for dead Z-WaveJS nodes
  - platform: template
    sensors:
      failed_zwave:
        value_template: >
          {{ states | selectattr("entity_id", "search", "node_status") |
             selectattr('state', 'in', 'dead, unavailable, unknown') |
             map(attribute='entity_id') | list }}
binary_sensor:
  - platform: mqtt
    name: "BlueIris Doorbell Motion"
    state_topic: BlueIris/MotionAlarm/doorbell
    payload_on: "1"
    payload_off: "0"
    device_class: motion
  - platform: mqtt
    name: "BlueIris Driveway Motion"
    state_topic: BlueIris/MotionAlarm/driveway
    payload_on: "1"
    payload_off: "0"
    device_class: motion
  - platform: mqtt
    name: "BlueIris Backyard Motion"
    state_topic: BlueIris/MotionAlarm/backyard
    payload_on: "1"
    payload_off: "0"
    device_class: motion
  - platform: mqtt
    name: "BlueIris North Gate Motion"
    state_topic: BlueIris/MotionAlarm/northgate
    payload_on: "1"
    payload_off: "0"
    device_class: motion
  - platform: mqtt
    name: "BlueIris Back Patio Motion"
    state_topic: BlueIris/MotionAlarm/backpatio
    payload_on: "1"
    payload_off: "0"
    device_class: motion
  - platform: mqtt
    name: "BlueIris Shop Motion"
    state_topic: BlueIris/MotionAlarm/shop
    payload_on: "1"
    payload_off: "0"
    device_class: motion

My hacked up attempt that I can’t get working (I’m stuck on the -platform: template sensor section, and the binary_sensor section, specifically I think.

mqtt:
  - sensor:
    state_topic: "rtl_433/226d4b83cd4b/devices/LaCrosse-TX141THBv2/0/63/temperature_C"
    device_class: temperature
    unique_id: LaCrosse_temp
    name: outside_temp
    unit_of_measurement: '°C'
  - sensor:
    state_topic: "rtl_433/226d4b83cd4b/devices/LaCrosse-TX141THBv2/0/63/humidity"
    device_class: humidity
    unique_id: LaCrosse_humidity
    name: outside_humidity
    unit_of_measurement: '%'
binary_sensor:
  - platform: mqtt
    name: "BlueIris Doorbell Motion"
    state_topic: BlueIris/MotionAlarm/doorbell
    payload_on: "1"
    payload_off: "0"
    device_class: motion
  - platform: mqtt
    name: "BlueIris Driveway Motion"
    state_topic: BlueIris/MotionAlarm/driveway
    payload_on: "1"
    payload_off: "0"
    device_class: motion
  - platform: mqtt
    name: "BlueIris Backyard Motion"
    state_topic: BlueIris/MotionAlarm/backyard
    payload_on: "1"
    payload_off: "0"
    device_class: motion
  - platform: mqtt
    name: "BlueIris North Gate Motion"
    state_topic: BlueIris/MotionAlarm/northgate
    payload_on: "1"
    payload_off: "0"
    device_class: motion
  - platform: mqtt
    name: "BlueIris Back Patio Motion"
    state_topic: BlueIris/MotionAlarm/backpatio
    payload_on: "1"
    payload_off: "0"
    device_class: motion
  - platform: mqtt
    name: "BlueIris Shop Motion"
    state_topic: BlueIris/MotionAlarm/shop
    payload_on: "1"
    payload_off: "0"
    device_class: motion
#Sensor for dead Z-WaveJS nodes
  - platform: template
    sensors:
      failed_zwave:
        value_template: >
          {{ states | selectattr("entity_id", "search", "node_status") |
             selectattr('state', 'in', 'dead, unavailable, unknown') |
             map(attribute='entity_id') | list }}

Howdy,

You are redefining -sensor: multiple times.

It should be:

mqtt:
  sensor:
    - name: "snesor1"
      etc
    - name: "sensor2"
  binary_sensor:
    - name: "sensor1"
      etc
    - name: "sensor2"

Thank you! Can you help with the -platform part of this section? Where would that go in the template you gave?

  - platform: template
    sensors:
      failed_zwave:
        value_template: >
          {{ states | selectattr("entity_id", "search", "node_status") |
             selectattr('state', 'in', 'dead, unavailable, unknown') |
             map(attribute='entity_id') | list }}

Template sensors are to be moved to their own templates.yaml file, not under mqtt.yaml.

Example from my templates.yaml.

#Sensor Templates
- sensor:
    - name: "sun elevation"
      unique_id: templatesensorsunelevation
      unit_of_measurement: "°"
      state: >
        {{ state_attr('sun.sun', 'elevation') | float(default=0) | round(0) }}
    - name: "sun up"
      unique_id: templatesensorsunup
      unit_of_measurement: ""
      state: >
        {% if is_state('sun.sun', 'above_horizon') %}
          on
        {% else %}
          off
        {% endif %}
1 Like

Well but what am I then doing wrong here? I cannot follow the logic.

image

You see I get this error when checking my config - I try to avoid the coming breaking change:

I have not yet upgraded to 2022.6 maybe that’s my issue?

@MrBorg Correct, you need to be on 2022.6.x

1 Like

Hi,

Beginner to HomeAssistant. I have it on a raspberry pi in docker. I have mosquitto installed on the raspbian. I also have mysensors up and running on the rpi host and am receiving messages like

mysensors-pub/2/7/1/0/25 11.70 that also appear on homeassistant mqtt when I listen to the topic.

So how do I get this into homeassistant as actual data?

Hi!

Did you figure this out? I am stuck in the same place as you :slight_smile: