From c62ae679f3b0b66d044a868ba8ba4e0936007ac0 Mon Sep 17 00:00:00 2001 From: hunhejj Date: Tue, 21 Feb 2023 22:19:27 +0100 Subject: [PATCH] Migrate to new HA mqtt configuration The old way of configuring mqtt entities is not supported anymore since `v2022.12` --- MQTT.md | 83 ++++++++++++++++++++++++++------------------------------- 1 file changed, 38 insertions(+), 45 deletions(-) diff --git a/MQTT.md b/MQTT.md index 95779c76..7fa56b79 100644 --- a/MQTT.md +++ b/MQTT.md @@ -171,54 +171,47 @@ Examples of consuming "parsed" MQTT data in [Home Assistant](https://www.home-as The `active_start` and `active_end` have good potential use as triggers to turn on and off various connect receivers/zones. The messages published are empty and therefor no "payload_on" is set, "payload_off" however is set to prevent accidental triggering. ```yml -binary_sensor: - - - platform: mqtt - name: "shairport active start" - state_topic: "shairport/active_start" - payload_on: "" - payload_off: "OFF" - off_delay: 300 - - - platform: mqtt - name: "shairport active end" - state_topic: "shairport/active_end" - payload_on: "" - payload_off: "OFF" - off_delay: 300 +mqtt: + binary_sensor: + - name: "shairport active start" + state_topic: "shairport/active_start" + payload_on: "" + payload_off: "OFF" + off_delay: 300 + + - name: "shairport active end" + state_topic: "shairport/active_end" + payload_on: "" + payload_off: "OFF" + off_delay: 300 ``` Below parsed data is saved into the Home Assistant database as sensor data. Please note the conversion of the volume from dB to percentage. ```yml -sensor: - - platform: mqtt - name: "shairport album" - state_topic: "shairport/album" - expire_after: 600 - - - platform: mqtt - name: "shairport artist" - state_topic: "shairport/artist" - expire_after: 600 - - - platform: mqtt - name: "shairport title" - state_topic: "shairport/title" - expire_after: 600 - - - platform: mqtt - name: "shairport genre" - state_topic: "shairport/genre" - expire_after: 600 - - - platform: mqtt - name: "shairport volume (dB)" - state_topic: "shairport/volume" - - - platform: mqtt - name: "shairport volume (PCT)" - state_topic: "shairport/volume" - value_template: "{{ value | regex_findall_index(find='^(.+?),', index=0, ignorecase=False) | float / 30 + 1 }}" - unit_of_measurement: 'percent' +mqtt: + sensor: + - name: "shairport album" + state_topic: "shairport/album" + expire_after: 600 + + - name: "shairport artist" + state_topic: "shairport/artist" + expire_after: 600 + + - name: "shairport title" + state_topic: "shairport/title" + expire_after: 600 + + - name: "shairport genre" + state_topic: "shairport/genre" + expire_after: 600 + + - name: "shairport volume (dB)" + state_topic: "shairport/volume" + + - name: "shairport volume (PCT)" + state_topic: "shairport/volume" + value_template: "{{ value | regex_findall_index(find='^(.+?),', index=0, ignorecase=False) | float / 30 + 1 }}" + unit_of_measurement: 'percent' ``` -- 2.47.2