diff --git a/homeassistant/components/mqtt/climate.py b/homeassistant/components/mqtt/climate.py index 5ac43d51316..2e19a345bc3 100644 --- a/homeassistant/components/mqtt/climate.py +++ b/homeassistant/components/mqtt/climate.py @@ -125,6 +125,8 @@ CONF_TEMP_MAX = "max_temp" CONF_TEMP_MIN = "min_temp" CONF_TEMP_STEP = "temp_step" +PAYLOAD_NONE = "None" + MQTT_CLIMATE_ATTRIBUTES_BLOCKED = frozenset( { climate.ATTR_AUX_HEAT, @@ -441,6 +443,12 @@ class MqttClimate(MqttEntity, ClimateEntity): if payload in CURRENT_HVAC_ACTIONS: self._action = payload self.async_write_ha_state() + elif not payload or payload == PAYLOAD_NONE: + _LOGGER.debug( + "Invalid %s action: %s, ignoring", + CURRENT_HVAC_ACTIONS, + payload, + ) else: _LOGGER.warning( "Invalid %s action: %s", diff --git a/tests/components/mqtt/test_climate.py b/tests/components/mqtt/test_climate.py index 0f4f9b209c6..3b2da69f94b 100644 --- a/tests/components/mqtt/test_climate.py +++ b/tests/components/mqtt/test_climate.py @@ -900,6 +900,15 @@ async def test_get_with_templates(hass, mqtt_mock, caplog): state = hass.states.get(ENTITY_CLIMATE) assert state.attributes.get("hvac_action") == "cooling" + # Test ignoring null values + async_fire_mqtt_message(hass, "action", "null") + state = hass.states.get(ENTITY_CLIMATE) + assert state.attributes.get("hvac_action") == "cooling" + assert ( + "Invalid ['off', 'heating', 'cooling', 'drying', 'idle', 'fan'] action: None, ignoring" + in caplog.text + ) + async def test_set_with_templates(hass, mqtt_mock, caplog): """Test setting various attributes with templates."""