wars:
platform: mqtt
name: ‘Toilet Motion’
state_topic: ‘tele/tasmota_8266F7/RESULT’
value_template: >-
{% if value_json.RfReceived.Data == ‘D49B1E’ %}
{{‘ON’}}
{% else %}
{{states(‘binary_sensor.toilet_motion’) | upper}}
{% endif %}
off_delay: 15
device_class: motion
platform: mqtt
state_topic: “tele/tasmota_8266F7/RESULT”
value_template: ‘{{value_json.RfReceived.Data}}’
payload_on: ‘8CA0B1’
payload_off: ‘8CA0B1’
name: “R1_Button_A”
off_delay: 1
mqtt:
binary_sensor:
- name: 'Toilet Motion'
state_topic: 'tele/tasmota_8266F7/RESULT'
value_template: >-
{% if value_json.RfReceived.Data == 'D49B1E' %}
{{'ON'}}
{% else %}
{{states('binary_sensor.toilet_motion') | upper}}
{% endif %}
off_delay: 15
device_class: motion
unique_id: mqtt-a979e8dadc7a49f295604f6342ad50b9
- name: "R1_Button_A"
state_topic: "tele/tasmota_8266F7/RESULT"
value_template: '{{value_json.RfReceived.Data}}'
payload_on: '8CA0B1'
payload_off: '8CA0B1'
off_delay: 1
unique_id: mqtt-176ae5ad468747aaa24665c3dc530083
That’s the best I can do because you didn’t use the code button in your post.
I’m not entirely sure about that second sensor - because the payload for on and off are the same, I think you might want to remove payload_off:
because that’s what off_delay:
is doing.
1 Like
wars
(Warren)
September 15, 2022, 8:31am
20
Hey Andrew,
Thanks so much for helping me out. When I read through this thread I figured this was the way forward but wasn’t sure if it would work for me due to mine looking slightly different to anyone else’s.
So, to save a long post I didn’t list all of the sensors as they are all similar. I have a remote control with 4 buttons on, two are on’s and two are off’s (for the kids to turn some lights on and off, I was finding that if they use the same button for both on&off it was getting confusing so one is only on, the other is only off).
This code is in /config/includes/binarysensor.yaml - will it be fine for me to use the heading mqtt: in this (if it could exist in other yaml files which will probably cause a conflict, right?)
The less headachey way of doing it - is to have all your MQTT stuff in it’s own files - then stick this in your configuration.yaml:
mqtt:
sensor: !include includes/mqttsensor.yaml
binary_sensor: !include includes/mqttbinarysensor.yaml
switch: !include includes/mqttswitch.yaml
Inside includes/mqttbinarysensor.yaml - your file will look like this:
- name: 'Toilet Motion'
state_topic: 'tele/tasmota_8266F7/RESULT'
value_template: >-
{% if value_json.RfReceived.Data == 'D49B1E' %}
{{'ON'}}
{% else %}
{{states('binary_sensor.toilet_motion') | upper}}
{% endif %}
off_delay: 15
device_class: motion
unique_id: mqtt-a979e8dadc7a49f295604f6342ad50b9
- name: "R1_Button_A"
state_topic: "tele/tasmota_8266F7/RESULT"
value_template: '{{value_json.RfReceived.Data}}'
payload_on: '8CA0B1'
payload_off: '8CA0B1'
off_delay: 1
unique_id: mqtt-176ae5ad468747aaa24665c3dc530083
basically exactly as I posted, but just with the mqtt:
and binary_sensor:
lines removed.
wars
(Warren)
September 19, 2022, 7:11pm
22
joystick:
Hey Andrew,
Thanks again for your help. I’ve just gotten around to making the changes and it all seems to have worked as expected.
Have a great evening!
1 Like
If you are wondering what I use to create UUIDs by the way - I just refresh this site: https://www.uuidgenerator.net/ and removed the hyphens (I don’t know if that’s necessary, but I do it anyway)
I am confused - I have lots of entries in my sensors.yaml file that look like:
# Hall Thermometer
- platform: mqtt
state_topic: 'home/OpenMQTTGateway/BTtoMQTT/A4C138AB1367'
name: "Hall_temperature"
unit_of_measurement: '°C'
value_template: '{{ value_json.tempc | round(1) | is_defined }}'
expire_after: 21600 # 6 hours
How do I change these and which file do I put them in ?
I tried creating a new mqtt.yaml with:
sensor:
- name: "Hall_temperature"
state_topic: 'home/OpenMQTTGateway/BTtoMQTT/A4C138AB1367'
unit_of_measurement: '°C'
value_template: '{{ value_json.tempc | round(1) | is_defined }}'
expire_after: 21600 # 6 hours
and:
mqtt: !mqtt.yaml
in configuration.yaml
but then my dashboard stopped working - seeming because “Hall_Temperature” sensor.hall_temperature was no longer valid, but I couldn’t find its new equivalent
So after some trial and error - I think I am making some progress, my full entry in the old format for my Hall Thermometer was:
# Hall Thermometer
- platform: mqtt
name: "Hall_temperature"
state_topic: 'home/OpenMQTTGateway/BTtoMQTT/A4C138AB1367'
unit_of_measurement: '°C'
value_template: '{{ value_json.tempc | round(1) | is_defined }}'
expire_after: 21600 # 6 hours
- platform: mqtt
name: "Hall_humidity"
state_topic: 'home/OpenMQTTGateway/BTtoMQTT/A4C138AB1367'
unit_of_measurement: '%'
value_template: '{{ value_json.hum | is_defined }}'
expire_after: 21600 # 6 hours
icon: "mdi:air-humidifier"
- platform: mqtt
name: "Hall_battery_volts"
state_topic: 'home/OpenMQTTGateway/BTtoMQTT/A4C138AB1367'
unit_of_measurement: 'V'
value_template: '{{ value_json.volt | is_defined }}'
expire_after: 21600 # 6 hours
icon: "mdi:battery-outline"
- platform: mqtt
name: "Hall_battery_percent"
state_topic: 'home/OpenMQTTGateway/BTtoMQTT/A4C138AB1367'
unit_of_measurement: '%'
value_template: '{{ value_json.batt | is_defined }}'
expire_after: 21600 # 6 hours
icon: "mdi:battery-outline"
- platform: mqtt
name: "Hall_rssi"
state_topic: 'home/OpenMQTTGateway/BTtoMQTT/A4C138AB1367'
value_template: '{{ value_json.rssi | is_defined }}'
expire_after: 21600 # 6 hours
icon: "mdi:signal-variant"
Which I initially changed (in my new mqtt.yaml) to:
sensor:
- name: "Hall_temperature"
state_topic: 'home/OpenMQTTGateway/BTtoMQTT/A4C138AB1367'
unit_of_measurement: '°C'
value_template: '{{ value_json.tempc | round(1) | is_defined }}'
expire_after: 21600 # 6 hours
sensor:
- name: "Hall_humidity"
state_topic: 'home/OpenMQTTGateway/BTtoMQTT/A4C138AB1367'
unit_of_measurement: '%'
value_template: '{{ value_json.hum | is_defined }}'
expire_after: 21600 # 6 hours
icon: "mdi:air-humidifier"
sensor:
- name: "Hall_battery_volts"
state_topic: 'home/OpenMQTTGateway/BTtoMQTT/A4C138AB1367'
unit_of_measurement: 'V'
value_template: '{{ value_json.volt | is_defined }}'
expire_after: 21600 # 6 hours
icon: "mdi:battery-outline"
sensor:
- name: "Hall_battery_percent"
state_topic: 'home/OpenMQTTGateway/BTtoMQTT/A4C138AB1367'
unit_of_measurement: '%'
value_template: '{{ value_json.batt | is_defined }}'
expire_after: 21600 # 6 hours
icon: "mdi:battery-outline"
sensor:
- name: "Hall_rssi"
state_topic: 'home/OpenMQTTGateway/BTtoMQTT/A4C138AB1367'
value_template: '{{ value_json.rssi | is_defined }}'
expire_after: 21600 # 6 hours
icon: "mdi:signal-variant"
But it seems that is wrong and breaks something as my sensors don’t work, but the Configuration Validation does not find anything wrong.
If I use:
sensor:
# Hall Thermometer
- name: "Hall_temperature"
state_topic: 'home/OpenMQTTGateway/BTtoMQTT/A4C138AB1367'
unit_of_measurement: '°C'
value_template: '{{ value_json.tempc | round(1) | is_defined }}'
expire_after: 21600 # 6 hours
- name: "Hall_humidity"
state_topic: 'home/OpenMQTTGateway/BTtoMQTT/A4C138AB1367'
unit_of_measurement: '%'
value_template: '{{ value_json.hum | is_defined }}'
expire_after: 21600 # 6 hours
icon: "mdi:air-humidifier"
- name: "Hall_battery_volts"
state_topic: 'home/OpenMQTTGateway/BTtoMQTT/A4C138AB1367'
unit_of_measurement: 'V'
value_template: '{{ value_json.volt | is_defined }}'
expire_after: 21600 # 6 hours
icon: "mdi:battery-outline"
- name: "Hall_battery_percent"
state_topic: 'home/OpenMQTTGateway/BTtoMQTT/A4C138AB1367'
unit_of_measurement: '%'
value_template: '{{ value_json.batt | is_defined }}'
expire_after: 21600 # 6 hours
icon: "mdi:battery-outline"
- name: "Hall_rssi"
state_topic: 'home/OpenMQTTGateway/BTtoMQTT/A4C138AB1367'
value_template: '{{ value_json.rssi | is_defined }}'
expire_after: 21600 # 6 hours
icon: "mdi:signal-variant"
It all works again.
(Time for some sleep before I tackle the remaining sensors)
Hi.
And how did you added the mqtt sensors inside mqtt/sensors.yaml? Can you give me an example of a sensor?
I also had all the sensors inside a folder but now it’s messed up.
Ok so I think I have changed all the entries in my yaml files and everyting seems to be working - how do I confirm I have completed them all an not missed any ?
giqcass
September 26, 2022, 11:36pm
28
ManuelTiago:
but now it’s messed up.
In the main config file
mqtt:
binary_sensor: !include mqtt/binary_sensors.yaml
sensor: !include mqtt/sensors.yaml
switch: !include mqtt/switches.yaml
in mqtt/binary_sensors.yaml
- state_topic: "tele/rfbridge/RESULT"
name: 'Leak Detector'
value_template: '{{value_json.RfReceived.Data}}'
payload_on: 'DA3A89'
payload_off: 'DA3A89off'
device_class: moisture
qos: 1
giqcass
September 26, 2022, 11:37pm
29
You should get another warning if you missed anything.
1 Like
Can anyone see anything wrong with this?
config.yaml
mqtt: !include_dir_merge_list mqtt
I have an mqtt folder in the config folder, and inside an mqtt.yaml file with these contents.
Yet this sensor never gets created and it worked just fine before this “new” way of doing mqtt sensors.
tom_l
September 28, 2022, 3:48am
31
Yes. It’s not a list so you cant use
Use one of the merge_named options.
1 Like
doberbert
(Doberbert)
October 6, 2022, 8:33am
32
Hi thanks , sorry for the late response i was on a business trip.
but when i do this
switch:
- platform: template
switches:
wohnzimmer:
friendly_name: "Wohnzimmer"
turn_on:
service: script.wohnzimmer_an
turn_off:
service: script.wohnzimmer_aus
mqtt:
switch:
- name: "test-lader-dummy"
command_topic: "home/switch/653/power"
state_topic: "home/switch/653/state"
payload_on: "On"
payload_off: "Off"
qos: 1
retain: true
The check configuration keeps spinning.
q1t1
October 6, 2022, 8:48am
33
Are you sure it’s related to these two configurations ?
The test passes for me when I test these.
doberbert
(Doberbert)
October 18, 2022, 1:35pm
35
And when you test the
mqtt:
switch:
- name: "test-lader-dummy"
command_topic: "home/switch/653/power"
state_topic: "home/switch/653/state"
payload_on: "On"
payload_off: "Off"
qos: 1
retain: true
q1t1
October 19, 2022, 7:04am
36
When I check the configuration I have “Configuration will not prevent Home Assistant from starting!”, so it’s OK for me.
tom_l
October 19, 2022, 7:20am
37
Just because it can restart dose not mean it is correct. Did it generate any persistent notification errors?
doberbert
(Doberbert)
October 20, 2022, 12:37pm
38
Ok weird i do get an error 500 on the console , maybe something else. I will give it a go.
doberbert
(Doberbert)
October 26, 2022, 4:11pm
39
styles.ts:370 POST http://homeassistant.local:8123/api/config/core/check_config 500 (Internal Server Error)
I @ styles.ts:370
(anonymous) @ styles.ts:370
callApi @ styles.ts:370
o @ ha-card.ts:5
value @ developer-yaml-config.ts:15
handleEvent @ styles.ts:370
developer-yaml-config.ts:15 Uncaught (in promise) {error: ‘Response error: 500’, status_code: 500, body: ‘500 Internal Server Error\n\nServer got itself in trouble’}
value @ developer-yaml-config.ts:15
await in value (async)
handleEvent @ styles.ts:370