yep, It is planned here
This fix seems to have been broken in 0.86.0. I have tried making a new folder under custom_components called mqtt/binary_sensor, and placing the file in there, but have had no success.
My Logs are being flooded once again.
Are you sure thatās the right folder structure? mqtt.py is supposed to be in /custom_components/binary_sensor/
Or did something change? Iām still on 0.78.3 and havenāt been keeping up with release notes.
Yeah, MQTT has been changed with 0.86.0 from what I can tell. Everything that works under the umbrella of MQTT now goes in an MQTT folder, not the type of item, such as binary_sensor. I hope that makes sense.
I think I have just managed to fix it in Docker, 0.86.0 for anyone else interested.
My Docker container is called home-assistant-homeassistant currently, so rename yours to whatever your container name is and the path to your configs. Mine is at /home/homeassistant.
The custom_components
folder now needs to have an MQTT
folder, and then the file named binary_sensor.py
SSH into your machine and execute the following (for Docker).
sudo docker cp home-assistant-homeassistant:/usr/src/app/homeassistant/components/mqtt/binary_sensor.py /home/homeassistant/custom_components/mqtt/binary_sensor.py
Open (sudo nano) the binary_sensor.py file and comment out these lines, 144, 145, 146 & 147
else: # Payload is not for this entity
# _LOGGER.warning('No matching payload found'
# ' for entity: %s with state_topic: %s',
# self._config.get(CONF_NAME),
# self._config.get(CONF_STATE_TOPIC))
return
Reboot, and sorted! No more log spam again
Excellent. Iām sure you just saved me at least an hour of my life for when I do get around to upgrading. Thanks.
Yep, thatās about how long it took me to work it out hahaha.
Can i download the file or find it somewhere as plain text ? Iām not into Unix/Linux at all and failed trying with PuTTY to copy the file.
Rgds. Henning
By the way, I can see no more warnings after upgrading to 0.86.1
Here is my file, with the offending lines #commented out. You need to create a folder in your HA called custom_components
and then another one called mqtt
then create a file called binary_sensor.py
(make a .txt
file and rename it to .py
) Copy this text, save, and reboot.
I hope that makes sense and helps you.
"""
Support for MQTT binary sensors.
For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/binary_sensor.mqtt/
"""
import logging
import voluptuous as vol
from homeassistant.core import callback
from homeassistant.components import mqtt, binary_sensor
from homeassistant.components.binary_sensor import (
BinarySensorDevice, DEVICE_CLASSES_SCHEMA)
from homeassistant.const import (
CONF_FORCE_UPDATE, CONF_NAME, CONF_VALUE_TEMPLATE, CONF_PAYLOAD_ON,
CONF_PAYLOAD_OFF, CONF_DEVICE_CLASS, CONF_DEVICE)
from homeassistant.components.mqtt import (
ATTR_DISCOVERY_HASH, CONF_QOS, CONF_STATE_TOPIC, MqttAttributes,
MqttAvailability, MqttDiscoveryUpdate, MqttEntityDeviceInfo, subscription)
from homeassistant.components.mqtt.discovery import (
MQTT_DISCOVERY_NEW, clear_discovery_hash)
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.dispatcher import async_dispatcher_connect
import homeassistant.helpers.event as evt
from homeassistant.helpers.typing import HomeAssistantType, ConfigType
_LOGGER = logging.getLogger(__name__)
DEFAULT_NAME = 'MQTT Binary sensor'
CONF_OFF_DELAY = 'off_delay'
CONF_UNIQUE_ID = 'unique_id'
DEFAULT_PAYLOAD_OFF = 'OFF'
DEFAULT_PAYLOAD_ON = 'ON'
DEFAULT_FORCE_UPDATE = False
DEPENDENCIES = ['mqtt']
PLATFORM_SCHEMA = mqtt.MQTT_RO_PLATFORM_SCHEMA.extend({
vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
vol.Optional(CONF_PAYLOAD_OFF, default=DEFAULT_PAYLOAD_OFF): cv.string,
vol.Optional(CONF_PAYLOAD_ON, default=DEFAULT_PAYLOAD_ON): cv.string,
vol.Optional(CONF_DEVICE_CLASS): DEVICE_CLASSES_SCHEMA,
vol.Optional(CONF_FORCE_UPDATE, default=DEFAULT_FORCE_UPDATE): cv.boolean,
vol.Optional(CONF_OFF_DELAY):
vol.All(vol.Coerce(int), vol.Range(min=0)),
# Integrations should never expose unique_id through configuration.
# This is an exception because MQTT is a message transport, not a protocol
vol.Optional(CONF_UNIQUE_ID): cv.string,
vol.Optional(CONF_DEVICE): mqtt.MQTT_ENTITY_DEVICE_INFO_SCHEMA,
}).extend(mqtt.MQTT_AVAILABILITY_SCHEMA.schema).extend(
mqtt.MQTT_JSON_ATTRS_SCHEMA.schema)
async def async_setup_platform(hass: HomeAssistantType, config: ConfigType,
async_add_entities, discovery_info=None):
"""Set up MQTT binary sensor through configuration.yaml."""
await _async_setup_entity(config, async_add_entities)
async def async_setup_entry(hass, config_entry, async_add_entities):
"""Set up MQTT binary sensor dynamically through MQTT discovery."""
async def async_discover(discovery_payload):
"""Discover and add a MQTT binary sensor."""
try:
discovery_hash = discovery_payload[ATTR_DISCOVERY_HASH]
config = PLATFORM_SCHEMA(discovery_payload)
await _async_setup_entity(config, async_add_entities,
discovery_hash)
except Exception:
if discovery_hash:
clear_discovery_hash(hass, discovery_hash)
raise
async_dispatcher_connect(
hass, MQTT_DISCOVERY_NEW.format(binary_sensor.DOMAIN, 'mqtt'),
async_discover)
async def _async_setup_entity(config, async_add_entities, discovery_hash=None):
"""Set up the MQTT binary sensor."""
async_add_entities([MqttBinarySensor(config, discovery_hash)])
class MqttBinarySensor(MqttAttributes, MqttAvailability, MqttDiscoveryUpdate,
MqttEntityDeviceInfo, BinarySensorDevice):
"""Representation a binary sensor that is updated by MQTT."""
def __init__(self, config, discovery_hash):
"""Initialize the MQTT binary sensor."""
self._config = config
self._unique_id = config.get(CONF_UNIQUE_ID)
self._state = None
self._sub_state = None
self._delay_listener = None
device_config = config.get(CONF_DEVICE)
MqttAttributes.__init__(self, config)
MqttAvailability.__init__(self, config)
MqttDiscoveryUpdate.__init__(self, discovery_hash,
self.discovery_update)
MqttEntityDeviceInfo.__init__(self, device_config)
async def async_added_to_hass(self):
"""Subscribe mqtt events."""
await super().async_added_to_hass()
await self._subscribe_topics()
async def discovery_update(self, discovery_payload):
"""Handle updated discovery message."""
config = PLATFORM_SCHEMA(discovery_payload)
self._config = config
await self.attributes_discovery_update(config)
await self.availability_discovery_update(config)
await self._subscribe_topics()
self.async_schedule_update_ha_state()
async def _subscribe_topics(self):
"""(Re)Subscribe to topics."""
value_template = self._config.get(CONF_VALUE_TEMPLATE)
if value_template is not None:
value_template.hass = self.hass
@callback
def off_delay_listener(now):
"""Switch device off after a delay."""
self._delay_listener = None
self._state = False
self.async_schedule_update_ha_state()
@callback
def state_message_received(_topic, payload, _qos):
"""Handle a new received MQTT state message."""
value_template = self._config.get(CONF_VALUE_TEMPLATE)
if value_template is not None:
payload = value_template.async_render_with_possible_json_value(
payload, variables={'entity_id': self.entity_id})
if payload == self._config.get(CONF_PAYLOAD_ON):
self._state = True
elif payload == self._config.get(CONF_PAYLOAD_OFF):
self._state = False
else: # Payload is not for this entity
# _LOGGER.warning('No matching payload found'
# ' for entity: %s with state_topic: %s',
# self._config.get(CONF_NAME),
# self._config.get(CONF_STATE_TOPIC))
return
if self._delay_listener is not None:
self._delay_listener()
self._delay_listener = None
off_delay = self._config.get(CONF_OFF_DELAY)
if (self._state and off_delay is not None):
self._delay_listener = evt.async_call_later(
self.hass, off_delay, off_delay_listener)
self.async_schedule_update_ha_state()
self._sub_state = await subscription.async_subscribe_topics(
self.hass, self._sub_state,
{'state_topic': {'topic': self._config.get(CONF_STATE_TOPIC),
'msg_callback': state_message_received,
'qos': self._config.get(CONF_QOS)}})
async def async_will_remove_from_hass(self):
"""Unsubscribe when removed."""
self._sub_state = await subscription.async_unsubscribe_topics(
self.hass, self._sub_state)
await MqttAttributes.async_will_remove_from_hass(self)
await MqttAvailability.async_will_remove_from_hass(self)
@property
def should_poll(self):
"""Return the polling state."""
return False
@property
def name(self):
"""Return the name of the binary sensor."""
return self._config.get(CONF_NAME)
@property
def is_on(self):
"""Return true if the binary sensor is on."""
return self._state
@property
def device_class(self):
"""Return the class of this sensor."""
return self._config.get(CONF_DEVICE_CLASS)
@property
def force_update(self):
"""Force update."""
return self._config.get(CONF_FORCE_UPDATE)
@property
def unique_id(self):
"""Return a unique ID."""
return self._unique_id
Ok everyone slam on the brakes editing the .py files!!! I may have stumbled upon a stupid simple solution that should be much easier for anyone to implement.
The MQTT messages are logged as level āwarningā, so just configure the logger to ignore anything less than āerrorā. Like this in configuration.yaml:
logger:
default: warning
logs:
homeassistant.components.mqtt: error
And done. Everything else (the default: line) will log at āwarningā or higher, while MQTT will log at āerrorā or higher. My log now has the same messages as before I started. I have deleted my custom MQTT component.
Here are the two docs that describe this:
Iām on 0.86.2 now. No idea when the above logger configuration ability was introduced, but itās there now.
Great solution!
I just wish they would remove the problem for us though. Some bright spark decided it was a good idea to create this logging in the first place and even after being made aware of the problem, no one has fixed it.
Frustrating.
As mentioned earlier in this thread, this is the PR that caused the issue. Would be great if this could be reverted to remove this logging error. @pvizeli ?
Are you still getting these warnings?
I did nothing about it, and see no sign of them since upgrading to 0.86.1
Iām not sure, I have edited my binary_sensor.py
file, so I wonāt know until I remove that file and upgrade - iām still on 86.0
Edit: Iāve gone back through the changes for 86.0/1/2 and can not find any specific reference to this being changed for 86.1, although I must admit to skimming through the changes a little sometimes, so may have missed it.
I can confirm on 86.2 I was still getting the message, motivating me to mess with the logging severity levels to make it go away.
you are right, couldnāt see it between stupid rflink debug messages :
the login levels approach looks absolutely valid, but does not work on my Hass.io 0.86.1
tried both default: warning
and default: error
.
EDIT: actually, I can see no mqtt warnings in /config/home-assistant.log, but they are still there if I go to http://hassio.local:8123/dev-info - didnāt think itās not the sameā¦
Thanks a million, kanga_who. Works perfectly !
Saved me a lot of time searching for the original souce code to patch myself (couldnāt find it on Github ?)
Still wonder why the he#%Ā¤" this PR hasnāt been reverted months ago. All using 433MHz to Wifi bridges like me are stuck with one topic for multiple sensors. Itās annoying that i have to patch core Home Assistant components to get rid off warnings for no reason at all.
Iāll still continue to patch for now, as the change of log level will remove the warnings in log file. But they are still persistent in HAās dev-info ??
Welcome to the frustration.
Just keep in mind the logging level solution does NOT remove warnings from the log file. Only those specific to MQTT. For the rest, defined by the default value, you can make it as verbose as you want by choosing, for example, āinfoā.
I just found that when set to level āwarningā I was seeing usual warning in my log that I expected to see. Minus of course the MQTT messages.
I have put the āloggerā entry into my config yaml but still get these:
No matching payload found for entity: Kitchen Window with state_topic: tele/RF_Bridge_Kitchen/RESULT
8:34 AM components/mqtt/binary_sensor.py (WARNING)
Any ideas?
I am on 8.7.1
Iām still seeing this error despite setting the homeassistant.components.mqtt: error
@ee1 Can you share how you have your binary_sensors
setup? Are they setup using the mqtt
platform or as a template
?
I have a couple of binary_sensors
as follows, which causes errors to appear in the log:
- platform: mqtt
state_topic: "tele/sonoff-rf-bridge-living-room/RESULT"
name: 'Kitchen Window'
value_template: '{{ value_json.RfReceived.Data }}'
payload_on: 'AAAAAA'
payload_off: 'AAAAAA'
device_class: window
qos: 1
Whereas I have binary_sensors
for a doorbell that works using a combined sensor
to monitor the latest received RF code. I donāt seem to see any errors for the binary_sensor
thatās setup as follows:
- platform: template
sensors:
front_door_bell:
friendly_name: "Front Door Bell"
value_template: '{{ is_state("sensor.sonoff_rf_bridge_living_room", "AAAAAA") }}'
delay_off: '00:00:02'
I donāt know if itās possible to setup all mqtt binary_sensors
as the later?