[DOCS] Modify home assistant configuration changes to reflect MQTT syntax that is required since HomeAssistant 2022.12.0 (#1511)

The MQTT YAML configuration change was optional in 2022.6, but the new syntax (updated above) is now mandatory, and now matches the already updated documentation provided at the top of the page.  I also added the force_update flag to help with the expire_after to give better graphing of temperature/humidity readings.
This commit is contained in:
Yogotech's GITHub account authored and GitHub committed 2023-03-08 05:25:12 -06:00
1 parent 8f47a80303
commit 2a8257d4ce
1 file changed
+121 -123
+121 -123
View File
@@ -81,143 +81,141 @@ From @123, @finity, @denniz03, @jrockstad, @anarchking, @dkluivingh
### Door sensor ### Door sensor
```yaml ```yaml
binary_sensor: mqtt:
- platform: mqtt binary_sensor:
name: "test" - name: "test"
state_topic: "home/OpenMQTTGateway/433toMQTT" state_topic: "home/OpenMQTTGateway/433toMQTT"
value_template: >- value_template: >-
{% if value_json.value == '7821834' %} {% if value_json.value == '7821834' %}
{{'ON'}} {{'ON'}}
{% elif value_json.value == '7821838' %} {% elif value_json.value == '7821838' %}
{{'OFF'}} {{'OFF'}}
{% else %} {% else %}
{{states('binary_sensor.test') | upper}} {{states('binary_sensor.test') | upper}}
{% endif %} {% endif %}
qos: 0 qos: 0
device_class: opening device_class: opening
``` ```
```yaml ```yaml
binary_sensor: mqtt:
- platform: mqtt binary_sensor:
name: doorbell - name: doorbell
state_topic: 'home/OpenMQTTGateway/SRFBtoMQTT' state_topic: 'home/OpenMQTTGateway/SRFBtoMQTT'
#value_template: "{{ value_json.raw }}" #value_template: "{{ value_json.raw }}"
value_template: >- value_template: >-
{% if value_json.value == '14163857' %} {% if value_json.value == '14163857' %}
{{'ON'}} {{'ON'}}
{% else %} {% else %}
{{states('binary_sensor.doorbell') | upper}} {{states('binary_sensor.doorbell') | upper}}
{% endif %} {% endif %}
off_delay: 30 off_delay: 30
device_class: 'sound' device_class: 'sound'
- binary_sensor:
platform: mqtt - name: light_back_sensor
name: light_back_sensor state_topic: 'home/OpenMQTTGateway/SRFBtoMQTT'
state_topic: 'home/OpenMQTTGateway/SRFBtoMQTT' #value_template: '{{ value_jason.value }}'
#value_template: '{{ value_jason.value }}' value_template: >-
value_template: >- {% if value_json.value == '1213858' %}
{% if value_json.value == '1213858' %} {{'ON'}}
{{'ON'}} {% else %}
{% else %} {{states('binary_sensor.light_back_sensor') | upper}}
{{states('binary_sensor.light_back_sensor') | upper}} {% endif %}
{% endif %} off_delay: 5
off_delay: 5
- binary_sensor: - name: rf_outlet_sensor
platform: mqtt state_topic: 'home/OpenMQTTGateway/SRFBtoMQTT'
name: rf_outlet_sensor value_template: >-
state_topic: 'home/OpenMQTTGateway/SRFBtoMQTT' {% if value_json.value == '16766303' %}
value_template: >- {{'ON'}}
{% if value_json.value == '16766303' %} {% else %}
{{'ON'}} {{states('binary_sensor.rf_outlet_sensor') | upper}}
{% else %} {% endif %}
{{states('binary_sensor.rf_outlet_sensor') | upper}}
{% endif %}
``` ```
### Motion sensor ### Motion sensor
```yaml ```yaml
binary_sensor: mqtt:
- platform: mqtt binary_sensor:
name: "Bewegung_Schlafzimmer" - name: "Bewegung_Schlafzimmer"
#device_class: motion #device_class: motion
state_topic: "home/OpenMQTTGateway1/HCSR501toMQTT" state_topic: "home/OpenMQTTGateway1/HCSR501toMQTT"
value_template: '{{ value_json["presence"] }}' value_template: '{{ value_json["presence"] }}'
payload_on: "true" payload_on: "true"
payload_off: "false" payload_off: "false"
``` ```
### Switches ### Switches
```yaml ```yaml
#switches #switches
switch: mqtt:
- platform: mqtt switch:
name: Plug1 - name: Plug1
state_topic: "home/OpenMQTTGateway/SRFBtoMQTT" state_topic: "home/OpenMQTTGateway/SRFBtoMQTT"
command_topic: "home/OpenMQTTGateway/commands/MQTTtoSRFB" command_topic: "home/OpenMQTTGateway/commands/MQTTtoSRFB"
value_template: "{{ value_json.value }}" value_template: "{{ value_json.value }}"
payload_on: '{"value":4546575}' payload_on: '{"value":4546575}'
payload_off: '{"value":4546572}' payload_off: '{"value":4546572}'
state_on: 4546575 state_on: 4546575
state_off: 4546572 state_off: 4546572
qos: "0" qos: "0"
retain: true retain: true
``` ```
### Mijia Thermometer BLE ### Mijia Thermometer BLE
```yaml ```yaml
Sensor: mqtt:
- platform: mqtt sensor:
state_topic: 'home/OpenMQTTGateway/BTtoMQTT/AAAAAAAAAAAA' # MQTT topic, check MQTT messages; replace AA... with id (BLE MAC) of your device - name: "mijia_thermometer_temperature"
name: "mijia_thermometer_temperature" state_topic: 'home/OpenMQTTGateway/BTtoMQTT/AAAAAAAAAAAA' # MQTT topic, check MQTT messages; replace AA... with id (BLE MAC) of your device
unit_of_measurement: '°C' unit_of_measurement: '°C'
value_template: '{{ value_json.tem | is_defined }}' value_template: '{{ value_json.tem | is_defined }}'
expire_after: 21600 # 6 hours expire_after: 21600 # 6 hours
- platform: mqtt force_update: true
state_topic: 'home/OpenMQTTGateway/BTtoMQTT/AAAAAAAAAAAA' - name: "mijia_thermometer_humidity"
name: "mijia_thermometer_humidity" state_topic: 'home/OpenMQTTGateway/BTtoMQTT/AAAAAAAAAAAA'
unit_of_measurement: '%' unit_of_measurement: '%'
value_template: '{{ value_json.hum | is_defined }}' value_template: '{{ value_json.hum | is_defined }}'
expire_after: 21600 # 6 hours expire_after: 21600 # 6 hours
- platform: mqtt force_update: true
state_topic: 'home/OpenMQTTGateway/BTtoMQTT/AAAAAAAAAAAA' - name: "mijia_thermometer_battery"
name: "mijia_thermometer_battery" state_topic: 'home/OpenMQTTGateway/BTtoMQTT/AAAAAAAAAAAA'
unit_of_measurement: '%' unit_of_measurement: '%'
value_template: '{{ value_json.batt | is_defined }}' value_template: '{{ value_json.batt | is_defined }}'
expire_after: 21600 # 6 hours expire_after: 21600 # 6 hours
``` force_update: true
```
### Xiaomi Mi Scale V2 BLE (XMTZC05HM) ### Xiaomi Mi Scale V2 BLE (XMTZC05HM)
```yaml ```yaml
sensor: mqtt:
- platform: mqtt sensor:
name: "Weight" - name: "Weight"
state_topic: "home/OpenMQTTGateway/BTtoMQTT/AAAAAAAAAAAA" # replace your MQTT topic here state_topic: "home/OpenMQTTGateway/BTtoMQTT/AAAAAAAAAAAA" # replace your MQTT topic here
value_template: '{{ value_json["weight"] }}' value_template: '{{ value_json["weight"] }}'
unit_of_measurement: "kg" unit_of_measurement: "kg"
icon: mdi:weight-kilogram icon: mdi:weight-kilogram
- platform: mqtt - name: "Impedance"
name: "Impedance" state_topic: "home/OpenMQTTGateway/BTtoMQTT/AAAAAAAAAAAA" # replace your MQTT topic here also
state_topic: "home/OpenMQTTGateway/BTtoMQTT/AAAAAAAAAAAA" # replace your MQTT topic here also value_template: '{{ value_json["impedance"] }}'
value_template: '{{ value_json["impedance"] }}' unit_of_measurement: "Ohm"
unit_of_measurement: "Ohm" icon: mdi:omega
icon: mdi:omega
- platform: template template:
sensors: sensor:
body_mass_index: - name: body_mass_index:
friendly_name: 'Body Mass Index' friendly_name: 'Body Mass Index'
value_template: >- value_template: >-
{% set HEIGHT = (1.76)|float %} # replace your height in meters {% set HEIGHT = (1.76)|float %} # replace your height in meters
{% set WEIGHT = states('sensor.xmtzc05hm_weight')|float %} {% set WEIGHT = states('sensor.xmtzc05hm_weight')|float %}
{{- (WEIGHT/(HEIGHT*HEIGHT))|float|round(1) -}} {{- (WEIGHT/(HEIGHT*HEIGHT))|float|round(1) -}}
icon_template: > icon_template: >
{{ 'mdi:human' }} {{ 'mdi:human' }}
``` ```
### MQTT Room Presence ### MQTT Room Presence
@@ -237,15 +235,15 @@ sensor:
### Temperature sensor ### Temperature sensor
```yaml ```yaml
sensor: mqtt:
- platform: mqtt sensor:
name: outdoor temp - name: outdoor temp
state_topic: "home/OpenMQTTGateway/433toMQTT" state_topic: "home/OpenMQTTGateway/433toMQTT"
unit_of_measurement: '°C' unit_of_measurement: '°C'
value_template: > value_template: >
{% if value_json is defined and value_json.sensor == 125 %} {% if value_json is defined and value_json.sensor == 125 %}
{{ value_json.tempc }} {{ value_json.tempc }}
{% else %} {% else %}
{{ states('sensor.outdoor_temp') }} {{ states('sensor.outdoor_temp') }}
{% endif %} {% endif %}
``` ```